docs: seal Tianshu research and scoped adoption baseline

This commit is contained in:
Agent Workbench Dev
2026-11-04 10:03:32 +08:00
parent 676fc55420
commit ce3afb2f0d
13 changed files with 2223 additions and 0 deletions
+149
View File
@@ -0,0 +1,149 @@
"""Read a pinned, clean public source checkout; never import or run its code."""
import argparse
import hashlib
import json
from pathlib import Path
import subprocess
PIN = "2d0b22e0b3554686e1e4131f8bdc568ef768e060"
PRODUCT_PIN = "676fc554"
URL = "https://github.com/huiliyi37/Tianshu-harness"
# Identifiers are used by the research report. Empty needles anchor at line one.
SOURCES = [
("S01", "package.json", '"version"'),
("S02", "LICENSE", ""),
("S03", "README.md", "**提交、验证、审查分离的交付**"),
("S04", "src/agent/runtime-hooks.ts", "export type RuntimeHookPhase"),
("S05", "src/agent/create-runtime-hooks.ts", "export function createDefaultRuntimeHooks"),
("S06", "src/agent/loop-factory.ts", "const hooks = createDefaultRuntimeHooks"),
("S07", "src/agent/turn-perception.ts", ""),
("S08", "src/agent/tool-execution.ts", "export class ToolExecutionController"),
("S09", "src/agent/turn-orchestrator.ts", ""),
("S10", "src/context/task-contract.ts", "export interface TaskContract"),
("S11", "src/agent/evidence-obligation.ts", "export type ObligationState"),
("S12", "src/agent/obligation-tracker.ts", "export class ObligationTracker"),
("S13", "src/agent/loop.ts", "captureAcceptance(items:"),
("S14", "src/agent/advisory-bus.ts", "export class AdvisoryBus"),
("S15", "src/agent/runtime-advice-facts.ts", ""),
("S16", "src/agent/convergence-detector.ts", "const effectiveScore ="),
("S17", "src/agent/convergence-message.ts", ""),
("S18", "src/agent/score-history.ts", ""),
("S19", "src/tools/write-tool-helpers.ts", ""),
("S20", "src/agent/exploration-stall.ts", ""),
("S21", "src/agent/__tests__/convergence-detector.test.ts", ""),
("S22", "src/agent/delivery-gate-v2.ts", ""),
("S23", "src/agent/deliver-task.ts", ""),
("S24", "src/agent/evidence.ts", ""),
("S25", "src/agent/verification-snapshot.ts", ""),
("S26", "src/agent/verification-scope-current.ts", ""),
("S27", "src/agent/tool-pipeline.ts", "export function executeToolUse("),
("S28", "src/agent/approval-input-boundary.ts", ""),
("S29", "src/prompt/engine.ts", "export class PromptEngine"),
("S30", "src/agent/request-context-controller.ts", "export class RequestContextController"),
("S31", "src/agent/context-budget-preparation.ts", "export async function prepareContextRequest"),
("S32", "src/agent/compact-boundary-coordinator.ts", ""),
("S33", "src/context/request-budget.ts", ""),
("S34", "src/tools/tool-preset.ts", "minimal 36 / 26"),
("S35", "src/tools/default-registry.ts", ""),
("S36", "src/agent/tool-surface.ts", "export function describeToolSurface"),
("S37", "src/agent/work-order.ts", "const workerBudgetSchema"),
("S38", "src/agent/worker-runtime.ts", "export function createWorkerRuntimeFactory"),
("S39", "src/agent/worker-session.ts", "async function runWorkerSessionImpl"),
("S40", "src/agent/hands-session.ts", "const gateOn ="),
("S41", "src/agent/worker-write-gate.ts", "export async function evaluateWorkerWriteGate"),
("S42", "src/agent/worker-objective-gate.ts", "export function reconcileWithObjective"),
("S43", "src/agent/coordinator.ts", "result: reconcileWithObjective(order"),
("S44", "src/model/model-binding.ts", "export function resolveModelBinding"),
("S45", "src/config/provider-keys.ts", "export function findModelOwner"),
("S46", "src/api/fallback-client.ts", "getMainPrefixProof?.() ||"),
("S47", "src/memory/formation-policy.ts", ""),
("S48", "src/memory/essence-gate.ts", "export async function runEssenceGate"),
("S49", "src/memory/unified-memory.ts", "export function recallMemoryEntries"),
("S50", "src/agent/hooks/essence-gate-hook.ts", ""),
("S51", "src/agent/skill-distill.ts", "export function renderSkillDraftMarkdown"),
("S52", "src/agent/hooks/skill-distill-hook.ts", ""),
("S53", "src/skills/skill-loader.ts", "Two tiers:"),
("S54", "src/mcp/manager.ts", "export class McpManager"),
("S55", "src/plugins/plugin-loader.ts", "export async function initializePlugins"),
("S56", "src/tools/computer-use/bridge.ts", ""),
("S57", "src/tools/computer-use/stub.ts", ""),
("S58", "docs/architecture-overview.md", ""),
("S59", "docs/reference/observability-harness.md", ""),
("S60", "docs/CVM运行时对Agent模型的实证影响.md", "版权与许可"),
("S61", "docs/reference/cvm-cognitive-runtime.md", "版权与许可"),
("S62", "src/cli/entry.ts", ""),
("S63", "src/main.ts", ""),
]
PRODUCT = [
"src/server/runtime.mjs", "src/core/context/working-set.mjs",
"src/core/context/request-plan.mjs", "src/core/context/delivery-progress.mjs",
"src/core/tasks/task-plan-manager.mjs", "src/core/tasks/worker-manager.mjs",
"src/core/git-delivery.mjs", "src/core/models/model-hub.mjs",
"src/core/models/protocols.mjs", "src/core/memory/project-memory.mjs",
"src/core/evaluation/evaluation-manager.mjs", "src/core/browser/browser-manager.mjs",
"src/shared/contracts/task-plans.mjs", "docs/PLAN-1.25.md",
]
def git(root, *args):
return subprocess.check_output(["git", "-C", str(root), *args])
def digest(root, rel):
data = (root / rel).read_bytes()
return {"path": rel, "bytes": len(data), "sha256": hashlib.sha256(data).hexdigest(),
"lines": len(data.decode("utf-8").splitlines())}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source", required=True, type=Path)
parser.add_argument("--output", required=True, type=Path)
args = parser.parse_args()
source = args.source.resolve()
product = Path(__file__).resolve().parents[1]
assert git(source, "rev-parse", "HEAD").decode().strip() == PIN, "Unexpected source revision"
assert git(source, "status", "--porcelain") == b"", "Source checkout is not clean"
tracked = git(source, "ls-files", "-z").decode("utf-8").split("\0")[:-1]
ts = [p for p in tracked if p.startswith("src/") and p.endswith((".ts", ".tsx"))]
tests = [p for p in ts if "/__tests__/" in p or ".test." in p or ".spec." in p]
code = [p for p in ts if p not in set(tests)]
hooks = [p for p in code if p.startswith("src/agent/hooks/")]
entries = []
for identifier, rel, needle in SOURCES:
entry = {"id": identifier, **digest(source, rel)}
lines = (source / rel).read_text(encoding="utf-8").splitlines()
matches = [i + 1 for i, line in enumerate(lines) if needle in line] if needle else [1]
assert matches, f"Anchor not found: {identifier} {rel} {needle}"
entry.update(anchorLine=matches[0], anchorNeedle=needle,
url=f"{URL}/blob/{PIN}/{rel}#L{matches[0]}",
gitBlob=git(source, "rev-parse", f"HEAD:{rel}").decode().strip())
entries.append(entry)
result = {
"schemaVersion": 1, "repository": URL + ".git", "commit": PIN,
"commitInfo": git(source, "show", "-s", "--format=%cI%n%s", "HEAD").decode().splitlines(),
"packageVersion": json.loads((source / "package.json").read_text(encoding="utf-8"))["version"],
"codeLicense": "Apache-2.0",
"documentExceptions": ["docs/CVM运行时对Agent模型的实证影响.md", "docs/reference/cvm-cognitive-runtime.md"],
"documentExceptionLicense": "CC-BY-NC-ND-4.0; linked and license-recorded only; not reproduced or adapted",
"publicTree": {name: any(p.startswith(name + "/") for p in tracked) for name in ["desktop", "src/pro", "vscode-extension", "src/tools/computer-use"]},
"inventory": {"trackedFiles": len(tracked), "srcTsTsxFiles": len(ts), "testFilesByPathOrName": len(tests),
"sourceFilesByExclusion": len(code), "sourceLinesSplitlines": sum(digest(source, p)["lines"] for p in code),
"hookSourceFiles": len(hooks)},
"inventoryMethod": "git ls-files; src/ .ts/.tsx; tests are /__tests__/ or .test. or .spec.; UTF-8 splitlines counts; no tests executed",
"sourceFiles": entries,
"productBaselineCommit": git(product, "rev-parse", PRODUCT_PIN).decode().strip(),
"productFiles": [digest(product, p) for p in PRODUCT],
"executionScope": {"fullApplicationStarted": False, "thirdPartyDependenciesInstalled": False, "modelRequests": 0,
"pureProbeOnly": "Five reviewed modules; separate original output and driver are sealed alongside this index"},
}
args.output.parent.mkdir(parents=True, exist_ok=True)
with args.output.open("x", encoding="utf-8", newline="\n") as stream:
json.dump(result, stream, ensure_ascii=False, indent=2)
stream.write("\n")
print(json.dumps({"commit": PIN, "inventory": result["inventory"], "indexedSources": len(entries), "productFiles": len(PRODUCT)}, ensure_ascii=False))
if __name__ == "__main__":
main()
+118
View File
@@ -0,0 +1,118 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { createHash } from 'node:crypto';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
// Research validation only: no fetch, credentials, model calls or third-party execution.
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const evidence = path.join(root, 'docs/tianshu-research-evidence');
const pin = '2d0b22e0b3554686e1e4131f8bdc568ef768e060';
const args = process.argv.slice(2);
let sourceRoot = null, useIndex = false;
for (let i = 0; i < args.length; i++) {
if (args[i] === '--index') useIndex = true;
else if (args[i] === '--source-root' && args[i + 1]) sourceRoot = path.resolve(args[++i]);
else throw new Error('Usage: node scripts/verify-tianshu-research.mjs [--source-root <checkout>] [--index]');
}
const sha = data => createHash('sha256').update(data).digest('hex');
const git = (cwd, ...gitArgs) => execFileSync('git', ['-C', cwd, ...gitArgs], { maxBuffer: 16 * 1024 * 1024, windowsHide: true });
function contained(base, relative) {
assert.equal(typeof relative, 'string');
assert.ok(relative.length && !relative.includes('\\') && !path.isAbsolute(relative));
const target = path.resolve(base, relative), rel = path.relative(base, target);
assert.ok(rel && !rel.startsWith('..') && !path.isAbsolute(rel), 'Path escapes research root');
assert.ok(fs.lstatSync(target).isFile(), 'Expected an ordinary file: ' + relative);
return target;
}
function checkBytes(bytes, row) {
assert.equal(bytes.length, row.bytes, 'Byte count: ' + row.path);
assert.equal(sha(bytes), row.sha256, 'SHA-256: ' + row.path);
}
const manifest = JSON.parse(fs.readFileSync(path.join(evidence, 'manifest.json'), 'utf8'));
assert.equal(manifest.sourceCommit, pin);
assert.equal(manifest.modelRequests, 0);
assert.equal(manifest.productCodeChanged, false);
assert.equal(manifest.files.length, new Set(manifest.files.map(row => row.path)).size);
let bytes = 0;
for (const row of manifest.files) {
checkBytes(fs.readFileSync(contained(root, row.path)), row);
if (useIndex) checkBytes(git(root, 'show', ':' + row.path), row);
bytes += row.bytes;
}
assert.equal(bytes, manifest.bytes);
const index = JSON.parse(fs.readFileSync(path.join(evidence, 'source-index.json'), 'utf8'));
assert.equal(index.commit, pin);
assert.equal(index.packageVersion, '3.37.4');
assert.equal(index.publicTree.desktop, false);
assert.equal(index.publicTree['src/pro'], false);
assert.equal(index.sourceFiles.length, 63);
assert.equal(index.sourceFiles.length, new Set(index.sourceFiles.map(row => row.id)).size);
assert.equal(index.productFiles.length, 14);
const report = fs.readFileSync(path.join(root, 'docs/TIANSHU-HARNESS-SOURCE-REVIEW.md'), 'utf8');
assert.ok(!report.includes('<!-- SOURCE_REFERENCES -->'), 'Unexpanded source links');
for (const row of index.sourceFiles) assert.ok(report.includes(`[${row.id}]: ${row.url}`), 'Missing pinned link ' + row.id);
for (const [, id] of report.matchAll(/\[(S\d+)\]/g)) assert.ok(index.sourceFiles.some(row => row.id === id), 'Unknown citation ' + id);
const probe = JSON.parse(fs.readFileSync(path.join(evidence, 'pure-probe-original.json'), 'utf8'));
assert.equal(probe.sourceCommit, pin);
assert.equal(probe.modelRequests, 0);
assert.equal(probe.fullApplicationStarted, false);
assert.equal(probe.thirdPartyDependenciesInstalled, false);
assert.equal(probe.productChanged, false);
const expectedModules = new Set(['src/agent/convergence-detector.ts', 'src/agent/convergence-message.ts',
'src/agent/score-history.ts', 'src/agent/runtime-advice-facts.ts', 'src/tools/write-tool-helpers.ts']);
assert.equal(probe.sources.length, expectedModules.size);
for (const module of probe.sources) {
assert.ok(expectedModules.delete(module.path), 'Unexpected or duplicate executable module');
const indexed = index.sourceFiles.find(row => row.path === module.path);
assert.ok(indexed);
assert.equal(indexed.sha256, module.sha256);
assert.equal(indexed.bytes, module.bytes);
}
const expected = [
['upstream-W4-high-error-fixture', 0.5164603132291642, 1, false],
['upstream-W4-repeated-read-baseline', 0.082125, 2, false],
['same-repeated-read-plus-high-error-ratio', 0.082125, 2, false],
['repeated-failing-read-actual-high-error-window', 0, 2, false],
['verification-waiting-protection', 0.082125, 1, false],
['no-tool-hard-stop-preserved', 0.048556689040178395, 3, true],
];
assert.equal(probe.cases.length, expected.length);
for (let i = 0; i < expected.length; i++) {
const [name, score, level, abort] = expected[i], row = probe.cases[i];
assert.equal(row.name, name);
assert.ok(Math.abs(row.result.score - score) < 1e-12);
assert.equal(row.result.level, level);
assert.equal(row.result.shouldAbort, abort);
}
// Research describes the frozen product baseline, not future working-tree code.
// Read Git blobs so later implementation never invalidates or rewrites old evidence.
assert.match(manifest.productBaselineCommit, /^[a-f0-9]{40}$/);
for (const row of index.productFiles) {
const blob = git(root, 'show', manifest.productBaselineCommit + ':' + row.path);
// The original index captured one CRLF Markdown checkout; Git stores LF.
// Restore only that line-ending representation, then require the original SHA.
const original = sha(blob) === row.sha256 ? blob : Buffer.from(blob.toString('utf8').replace(/\r?\n/g, '\r\n'));
checkBytes(original, row);
}
if (sourceRoot) {
assert.equal(git(sourceRoot, 'rev-parse', 'HEAD').toString('utf8').trim(), pin);
assert.equal(git(sourceRoot, 'status', '--porcelain').toString('utf8'), '');
for (const row of index.sourceFiles) {
const data = fs.readFileSync(contained(sourceRoot, row.path));
checkBytes(data, row);
const lines = data.toString('utf8').split(/\r\n|\n|\r/);
if (lines.at(-1) === '') lines.pop();
assert.equal(lines.length, row.lines, 'Source line count ' + row.id);
assert.ok(row.anchorLine >= 1 && row.anchorLine <= lines.length);
assert.ok(lines[row.anchorLine - 1].includes(row.anchorNeedle));
assert.equal(git(sourceRoot, 'rev-parse', 'HEAD:' + row.path).toString('utf8').trim(), row.gitBlob);
}
for (const [directory, present] of Object.entries(index.publicTree)) {
assert.equal(git(sourceRoot, 'ls-tree', '-d', 'HEAD', directory).length > 0, present);
}
}
console.log(JSON.stringify({ ok: true, sourceCommit: pin, files: manifest.files.length, bytes,
indexedSourceFiles: index.sourceFiles.length, productInputs: index.productFiles.length, pureCases: probe.cases.length,
sourceCheckoutChecked: !!sourceRoot, gitIndexChecked: useIndex, thirdPartyCodeExecutedByVerifier: false, modelRequests: 0 }));