cocheck 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +104 -2
- package/THIRD_PARTY_NOTICES.md +279 -0
- package/bin/cocheck.mjs +8 -0
- package/dist/agent-transcripts.js +541 -0
- package/dist/attribution/basis.js +31 -0
- package/dist/attribution/evidence.js +311 -0
- package/dist/attribution/hooks/cocheck-preload.cjs +254 -0
- package/dist/attribution/hooks/sitecustomize.py +245 -0
- package/dist/attribution/names.js +163 -0
- package/dist/attribution/reconstruct.js +128 -0
- package/dist/attribution/tag.js +246 -0
- package/dist/attribution/write-scope-win.js +615 -0
- package/dist/attribution/write-scope.js +1668 -0
- package/dist/build-info.json +1 -0
- package/dist/cli-main.js +8 -0
- package/dist/cli.js +193 -0
- package/dist/codex-config.js +107 -0
- package/dist/connector/after-gap.js +56 -0
- package/dist/connector/after-snapshot.js +244 -0
- package/dist/connector/before-snapshot.js +168 -0
- package/dist/connector/builtins.js +93 -0
- package/dist/connector/changes-v1.js +276 -0
- package/dist/connector/claimed-state.js +40 -0
- package/dist/connector/claimed.js +86 -0
- package/dist/connector/conformance.js +458 -0
- package/dist/connector/diff-object.js +81 -0
- package/dist/connector/diff-samples.js +64 -0
- package/dist/connector/diff.js +273 -0
- package/dist/connector/doc-level.js +20 -0
- package/dist/connector/enabled-types.js +87 -0
- package/dist/connector/export-view.js +13 -0
- package/dist/connector/file-capture.js +265 -0
- package/dist/connector/frozen.js +213 -0
- package/dist/connector/installed-manifests.js +72 -0
- package/dist/connector/installed-match.js +161 -0
- package/dist/connector/local-process.js +119 -0
- package/dist/connector/nothing-changed-rule.js +23 -0
- package/dist/connector/old-rows.js +66 -0
- package/dist/connector/png-pixels.js +4 -0
- package/dist/connector/registry.js +78 -0
- package/dist/connector/requires.js +30 -0
- package/dist/connector/row-doc.js +54 -0
- package/dist/connector/run-argv.js +25 -0
- package/dist/connector/runner.js +325 -0
- package/dist/connector/schema.js +242 -0
- package/dist/connector/subject.js +8 -0
- package/dist/connector/subjects.js +113 -0
- package/dist/connector/validate.js +200 -0
- package/dist/connector-auth.js +101 -0
- package/dist/connector-create.js +55 -0
- package/dist/connector-doctor.js +167 -0
- package/dist/connector-test-cli.js +627 -0
- package/dist/connector-types-cli.js +43 -0
- package/dist/connectors/microsoft-excel/cocheck-connector.json +13 -0
- package/dist/connectors/microsoft-excel/connector.mjs +11 -0
- package/dist/connectors/microsoft-powerpoint/cocheck-connector.json +13 -0
- package/dist/connectors/microsoft-powerpoint/connector.mjs +11 -0
- package/dist/connectors/microsoft-word/cocheck-connector.json +13 -0
- package/dist/connectors/microsoft-word/connector.mjs +11 -0
- package/dist/copies.js +151 -0
- package/dist/copilot-helpers.js +246 -0
- package/dist/coverage.js +277 -0
- package/dist/credit-guard.js +330 -0
- package/dist/display.js +78 -0
- package/dist/file-lock.js +145 -0
- package/dist/fingerprint.js +25 -0
- package/dist/formats/files/align.js +84 -0
- package/dist/formats/files/csv.js +78 -0
- package/dist/formats/files/layer.js +274 -0
- package/dist/formats/files/scan.js +86 -0
- package/dist/formats/files/textlike.js +21 -0
- package/dist/formats/layer.js +48 -0
- package/dist/helpers/pdfpages +0 -0
- package/dist/home-page.js +173 -0
- package/dist/home-perms.js +59 -0
- package/dist/hook-adapter.js +3415 -0
- package/dist/hook-cli.js +505 -0
- package/dist/hook-journal.js +147 -0
- package/dist/hook.js +25 -0
- package/dist/hosts/claude.js +250 -0
- package/dist/hosts/codex-bin-macos.js +2 -0
- package/dist/hosts/codex-bin.js +35 -0
- package/dist/hosts/codex-trust-probe.js +52 -0
- package/dist/hosts/codex-trust.js +46 -0
- package/dist/hosts/codex.js +355 -0
- package/dist/hosts/copilot.js +236 -0
- package/dist/hosts/index.js +52 -0
- package/dist/hosts/session-titles.js +327 -0
- package/dist/hosts/shared.js +31 -0
- package/dist/hosts/types.js +26 -0
- package/dist/html.js +4 -0
- package/dist/install.js +676 -0
- package/dist/items.js +105 -0
- package/dist/ledger.js +2097 -0
- package/dist/narration.js +202 -0
- package/dist/normalize.js +82 -0
- package/dist/office/connector/apps.js +34 -0
- package/dist/office/connector/docx/layer.js +247 -0
- package/dist/office/connector/docx/reader.js +284 -0
- package/dist/office/connector/excel/align.js +284 -0
- package/dist/office/connector/excel/answer.js +352 -0
- package/dist/office/connector/excel/diff.js +1310 -0
- package/dist/office/connector/excel/errors.js +44 -0
- package/dist/office/connector/excel/look.js +121 -0
- package/dist/office/connector/excel/print-boxes.js +432 -0
- package/dist/office/connector/excel/print-grid-previous.js +206 -0
- package/dist/office/connector/excel/print-setup.js +168 -0
- package/dist/office/connector/excel/workbook.js +374 -0
- package/dist/office/connector/export-driver.js +9 -0
- package/dist/office/connector/helpers/cocheck-screen +0 -0
- package/dist/office/connector/issues.js +31 -0
- package/dist/office/connector/mac-guard.js +16 -0
- package/dist/office/connector/main.js +23 -0
- package/dist/office/connector/nothing-changed.js +18 -0
- package/dist/office/connector/office-job.js +416 -0
- package/dist/office/connector/office-macos.js +473 -0
- package/dist/office/connector/office-win-export.js +107 -0
- package/dist/office/connector/office-win-lifecycle.js +194 -0
- package/dist/office/connector/office-win.js +209 -0
- package/dist/office/connector/office-win.ps1 +451 -0
- package/dist/office/connector/open-watch.js +46 -0
- package/dist/office/connector/pictures.js +156 -0
- package/dist/office/connector/pptx/diff.js +589 -0
- package/dist/office/connector/pptx/frames.js +105 -0
- package/dist/office/connector/pptx/layer.js +148 -0
- package/dist/office/connector/pptx/links.js +59 -0
- package/dist/office/connector/pptx/reader.js +744 -0
- package/dist/office/connector/pptx/spans.js +70 -0
- package/dist/office/connector/pptx/tags.js +86 -0
- package/dist/office/connector/pptx/xml.js +96 -0
- package/dist/office/connector/pptx/zip.js +223 -0
- package/dist/office/connector/pptx-boxes.js +238 -0
- package/dist/office/connector/print-copy-cap.js +19 -0
- package/dist/office/connector/print-copy.js +13 -0
- package/dist/office/connector/program.js +291 -0
- package/dist/office/connector/reach.js +27 -0
- package/dist/office/connector/refusal.js +16 -0
- package/dist/office/connector/screen-macos.js +193 -0
- package/dist/office/connector/screen-windows.js +34 -0
- package/dist/office/connector/shared/chart-diff.js +376 -0
- package/dist/office/connector/shared/docprops-noise.js +13 -0
- package/dist/office/connector/shared/lock.js +107 -0
- package/dist/office/connector/shared/ooxml-names.js +347 -0
- package/dist/office/connector/shared/owner.js +57 -0
- package/dist/office/connector/shared/package-media.js +703 -0
- package/dist/office/connector/shared/preflight.js +226 -0
- package/dist/office/connector/shared/structure-check.js +623 -0
- package/dist/office/connector/word-boxes.js +364 -0
- package/dist/office/connector/word-print-copy.js +234 -0
- package/dist/office/connector/xlsx/diff.js +1038 -0
- package/dist/office/connector/xlsx/formula.js +410 -0
- package/dist/office/connector/xlsx/layer.js +621 -0
- package/dist/office/connector/xlsx/memo.js +39 -0
- package/dist/office/connector/xlsx/numbers.js +31 -0
- package/dist/office/connector/xlsx/numfmt.js +913 -0
- package/dist/office/connector/xlsx/parts.js +66 -0
- package/dist/office/connector/xlsx/reader.js +394 -0
- package/dist/office/connector/xlsx/types.js +20 -0
- package/dist/office/connector/xlsx/written.js +446 -0
- package/dist/open-pick.js +99 -0
- package/dist/patch-secrets.js +194 -0
- package/dist/paths.js +65 -0
- package/dist/platform/darwin.js +179 -0
- package/dist/platform/index.js +61 -0
- package/dist/platform/spawn.js +115 -0
- package/dist/platform/stub.js +21 -0
- package/dist/platform/task-folder.js +41 -0
- package/dist/platform/types.js +20 -0
- package/dist/platform/win32-docrender.js +7 -0
- package/dist/platform/win32.js +265 -0
- package/dist/preferences.js +49 -0
- package/dist/reason.js +103 -0
- package/dist/region-delivery.js +148 -0
- package/dist/registry.js +68 -0
- package/dist/reveal.js +45 -0
- package/dist/review-process.js +154 -0
- package/dist/review-refresh-process.js +17 -0
- package/dist/review-refresh.js +120 -0
- package/dist/review-server.js +2079 -0
- package/dist/review-view-server.js +106 -0
- package/dist/review.js +8 -0
- package/dist/seal.js +315 -0
- package/dist/secret-files.js +34 -0
- package/dist/secret-hashes.js +27 -0
- package/dist/secret-rules.generated.js +3519 -0
- package/dist/secret-scan.js +127 -0
- package/dist/session-context.js +18 -0
- package/dist/signoff.js +419 -0
- package/dist/skill.js +110 -0
- package/dist/states.js +192 -0
- package/dist/tasks.js +1001 -0
- package/dist/timeline/attribution.js +207 -0
- package/dist/timeline/broken.js +55 -0
- package/dist/timeline/describe.js +413 -0
- package/dist/timeline/generic.js +195 -0
- package/dist/timeline/load.js +464 -0
- package/dist/timeline/loading.js +49 -0
- package/dist/timeline/notes.js +208 -0
- package/dist/timeline/page.js +178 -0
- package/dist/timeline/picture.js +303 -0
- package/dist/timeline/rail/assets/cocheck-icon.svg +1 -0
- package/dist/timeline/rail/assets/files-view.js +198 -0
- package/dist/timeline/rail/assets/loaders/icon-intro.json +1 -0
- package/dist/timeline/rail/assets/loaders/loader-orbit.json +1 -0
- package/dist/timeline/rail/assets/loaders/loader-spin.json +1 -0
- package/dist/timeline/rail/assets/review.css +992 -0
- package/dist/timeline/rail/assets/review.js +3365 -0
- package/dist/timeline/rail/assets/view-table.js +683 -0
- package/dist/timeline/rail/failure-line.js +26 -0
- package/dist/timeline/rail/files-model.js +45 -0
- package/dist/timeline/rail/live.js +49 -0
- package/dist/timeline/rail/made-pictures.js +48 -0
- package/dist/timeline/rail/mcp-card.js +307 -0
- package/dist/timeline/rail/model.js +1317 -0
- package/dist/timeline/rail/page.js +167 -0
- package/dist/timeline/rail/passes.js +106 -0
- package/dist/timeline/rail/regions.js +26 -0
- package/dist/timeline/rail/send-back.js +154 -0
- package/dist/timeline/rail/stop-status.js +164 -0
- package/dist/timeline/read-signal.js +743 -0
- package/dist/timeline/render/claimed.js +13 -0
- package/dist/timeline/render/fallback.js +36 -0
- package/dist/timeline/render/pdf-helper.js +71 -0
- package/dist/timeline/render/pdf.js +410 -0
- package/dist/timeline/render/pixel-pages.js +168 -0
- package/dist/timeline/render/png-crop.js +281 -0
- package/dist/timeline/render/registry.js +7 -0
- package/dist/timeline/render/text.js +366 -0
- package/dist/timeline/render/types.js +1 -0
- package/dist/timeline/render/view-v1.js +148 -0
- package/dist/timeline/render/whole.js +6 -0
- package/dist/timeline/rollout-failures.js +40 -0
- package/dist/timeline/runs.js +836 -0
- package/dist/timeline/stored-image.js +34 -0
- package/dist/timeline/subject-display.js +44 -0
- package/dist/timeline/timeline.js +1114 -0
- package/dist/timeline/write-signal.js +403 -0
- package/dist/tool-label.js +201 -0
- package/dist/tracking.js +87 -0
- package/dist/vendor/pdfjs/LICENSE +177 -0
- package/dist/vendor/pdfjs/pdf.min.mjs +27 -0
- package/dist/vendor/pdfjs/pdf.worker.min.mjs +27 -0
- package/package.json +66 -4
- package/public-kit/GUIDE.md +189 -0
- package/public-kit/README.md +10 -0
- package/public-kit/conformance/README.md +13 -0
- package/public-kit/conformance/cases/C1.json +12 -0
- package/public-kit/conformance/cases/C10.json +15 -0
- package/public-kit/conformance/cases/C11.json +16 -0
- package/public-kit/conformance/cases/C12.json +18 -0
- package/public-kit/conformance/cases/C13.json +23 -0
- package/public-kit/conformance/cases/C14.json +16 -0
- package/public-kit/conformance/cases/C16.json +15 -0
- package/public-kit/conformance/cases/C17.json +25 -0
- package/public-kit/conformance/cases/C2.json +13 -0
- package/public-kit/conformance/cases/C3.json +44 -0
- package/public-kit/conformance/cases/C4.json +13 -0
- package/public-kit/conformance/cases/C5.json +16 -0
- package/public-kit/conformance/cases/C6.json +58 -0
- package/public-kit/conformance/generate-large.mjs +15 -0
- package/public-kit/examples/toy-export/cocheck-connector.json +10 -0
- package/public-kit/examples/toy-export/connector.mjs +28 -0
- package/public-kit/examples/toy-helpers/cocheck-connector.json +10 -0
- package/public-kit/examples/toy-helpers/connector.mjs +69 -0
- package/public-kit/examples/toy-level-1/cocheck-connector.json +10 -0
- package/public-kit/examples/toy-level-1/connector.mjs +61 -0
- package/public-kit/examples/toy-level-3/cocheck-connector.json +10 -0
- package/public-kit/examples/toy-level-3/connector.mjs +82 -0
- package/public-kit/examples/toy-tracker/cocheck-connector.json +14 -0
- package/public-kit/examples/toy-tracker/connector.mjs +46 -0
- package/public-kit/examples/toy-tracker/samples/history.json +10 -0
- package/public-kit/examples/toy-tracker/samples/samples.json +7 -0
- package/public-kit/examples/toy-vendor/cocheck-connector.json +15 -0
- package/public-kit/examples/toy-vendor/connector.mjs +62 -0
- package/public-kit/helpers/pdf-text-layout.d.mts +35 -0
- package/public-kit/helpers/pdf-text-layout.mjs +602 -0
- package/public-kit/helpers/pdf-text.d.mts +56 -0
- package/public-kit/helpers/pdf-text.mjs +375 -0
- package/public-kit/helpers/pdf.d.mts +61 -0
- package/public-kit/helpers/pdf.mjs +251 -0
- package/public-kit/helpers/png.d.mts +15 -0
- package/public-kit/helpers/png.mjs +88 -0
- package/public-kit/helpers/spec.d.mts +4 -0
- package/public-kit/helpers/spec.mjs +2 -0
- package/public-kit/scaffold/README.md +23 -0
- package/public-kit/scaffold/template/README.md +13 -0
- package/public-kit/scaffold/template/cocheck-connector.json +10 -0
- package/public-kit/scaffold/template/connector.mjs +50 -0
- package/public-kit/spec/README.md +408 -0
- package/public-kit/spec/v1.md +598 -0
- package/public-kit/toy-product/README.md +7 -0
- package/public-kit/toy-product/notes-store.mjs +30 -0
- package/public-kit/toy-product/states/create.after.json +16 -0
- package/public-kit/toy-product/states/create.before.json +12 -0
- package/public-kit/toy-product/states/delete.after.json +8 -0
- package/public-kit/toy-product/states/delete.before.json +12 -0
- package/public-kit/toy-product/states/edit.after.json +12 -0
- package/public-kit/toy-product/states/edit.before.json +12 -0
- package/public-kit/toy-product/states/malformed.after.json +1 -0
- package/public-kit/toy-product/states/malformed.before.json +12 -0
- package/public-kit/toy-product/states/no-change.after.json +12 -0
- package/public-kit/toy-product/states/no-change.before.json +12 -0
- package/scripts/hook-launch.mjs +58 -0
- package/scripts/hook-launch.sh +52 -0
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
// Subagent files Claude Code keeps beside a session transcript: `<transcript dir>/<session_id>/subagents/agent-<agent_id>.meta.json`
|
|
2
|
+
// (the launching call's `toolUseId`) and `agent-<agent_id>.jsonl` (the agent's own transcript). Only ids are read from them, never words.
|
|
3
|
+
import { closeSync, constants, lstatSync, openSync, readdirSync, readFileSync, readSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { defaultProfile } from "./hosts/index.js";
|
|
6
|
+
import { classifyToolResult, neverRan, resultRunsOn } from "./credit-guard.js";
|
|
7
|
+
/**
|
|
8
|
+
* A host-sent identifier kept only when it is a short plain string that starts with a letter, digit, underscore, colon or hyphen (so it
|
|
9
|
+
* is never `.`, `..` or a dotfile when it is used in a path); anything else is no identifier (the call stays on the main line).
|
|
10
|
+
*/
|
|
11
|
+
export function cleanId(v, spaces = false) {
|
|
12
|
+
return typeof v === "string" && (spaces ? /^[\w:@-][\w.:@ -]{0,127}$/ : /^[\w:-][\w.:-]{0,127}$/).test(v) ? v : undefined;
|
|
13
|
+
}
|
|
14
|
+
/** Largest `.meta.json` read for a launcher; the real file is a few hundred bytes. */
|
|
15
|
+
const AGENT_META_MAX_BYTES = 16 * 1024;
|
|
16
|
+
/** Largest agent transcript read for tool_use ids. Real ones run to a few MB; a bigger file is no match (and its calls stay on the main line). */
|
|
17
|
+
export const AGENT_TRANSCRIPT_MAX_BYTES = 64 * 1024 * 1024;
|
|
18
|
+
/** Longest single transcript line parsed; a longer one is skipped (its ids are not read). */
|
|
19
|
+
const LINE_MAX_BYTES = 8 * 1024 * 1024;
|
|
20
|
+
/** Most agent transcripts read for one session, and the most bytes read across them in one load. */
|
|
21
|
+
const MAX_AGENT_FILES = 200;
|
|
22
|
+
const MAX_SESSION_BYTES = 256 * 1024 * 1024;
|
|
23
|
+
/** Most project folders looked through when the task's own folder has no directory for a session. */
|
|
24
|
+
const MAX_PROJECT_DIRS = 2000;
|
|
25
|
+
const CHUNK = 1024 * 1024;
|
|
26
|
+
/** What an agent's meta file says: the launching call's tool_use id and whether the host started it in the background (`requestShape`). */
|
|
27
|
+
function readMeta(subagentsDir, agentId) {
|
|
28
|
+
const none = { launcher: undefined, background: false };
|
|
29
|
+
try {
|
|
30
|
+
const file = path.join(subagentsDir, defaultProfile().helpers.metaFile(agentId));
|
|
31
|
+
const st = lstatSync(file);
|
|
32
|
+
if (!st.isFile() || st.size > AGENT_META_MAX_BYTES)
|
|
33
|
+
return none;
|
|
34
|
+
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
35
|
+
try {
|
|
36
|
+
const meta = JSON.parse(readFileSync(fd, "utf8"));
|
|
37
|
+
return { launcher: cleanId(meta?.toolUseId), background: meta?.requestShape === "background" };
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
closeSync(fd);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return none;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The tool_use id of the call that launched an agent, from its meta file; undefined on any problem (missing, a link, too large, bad JSON or id). */
|
|
48
|
+
export function readLauncher(subagentsDir, agentId) {
|
|
49
|
+
return readMeta(subagentsDir, agentId).launcher;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Where Claude Code keeps its project folders: `$CLAUDE_CONFIG_DIR/projects`, else `~/.claude/projects`. Under the node test runner
|
|
53
|
+
* (`NODE_TEST_CONTEXT` is set in every test process) the `~/.claude` default is refused, so a test cannot read the real transcripts.
|
|
54
|
+
*/
|
|
55
|
+
export function defaultTranscriptsRoot() {
|
|
56
|
+
return defaultProfile().helpers.projectsRoot();
|
|
57
|
+
}
|
|
58
|
+
const isRealDir = (p) => {
|
|
59
|
+
try {
|
|
60
|
+
const st = lstatSync(p);
|
|
61
|
+
return st.isDirectory() && !st.isSymbolicLink();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/** The path under `root` through `parts`, only when every component (project dir, session dir, subagents dir) is a real directory, never a link. */
|
|
68
|
+
function realDirUnder(root, ...parts) {
|
|
69
|
+
let cur = root;
|
|
70
|
+
for (const part of parts) {
|
|
71
|
+
cur = path.join(cur, part);
|
|
72
|
+
if (!isRealDir(cur))
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return cur;
|
|
76
|
+
}
|
|
77
|
+
/** The `subagents` folder of one session under the transcripts root: the task folder's project dir first, then any project dir that holds the session. */
|
|
78
|
+
function subagentsDirOf(root, folder, session) {
|
|
79
|
+
if (folder !== null) {
|
|
80
|
+
const direct = realDirUnder(root, folder.replace(/[^A-Za-z0-9]/g, "-"), session, defaultProfile().helpers.folderName);
|
|
81
|
+
if (direct !== null)
|
|
82
|
+
return direct;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
for (const name of readdirSync(root).slice(0, MAX_PROJECT_DIRS)) {
|
|
86
|
+
const candidate = realDirUnder(root, name, session, defaultProfile().helpers.folderName);
|
|
87
|
+
if (candidate !== null)
|
|
88
|
+
return candidate;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// no such root
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reads a file from byte `from` to its end in chunks, line by line, handing each line (without its newline) to `take`; a line longer than
|
|
98
|
+
* LINE_MAX_BYTES is skipped. The file is opened without following a link. False when the file could not be read.
|
|
99
|
+
*/
|
|
100
|
+
function readLines(file, from, take, limit = Infinity) {
|
|
101
|
+
return readLinesTo(file, from, take, limit) !== null;
|
|
102
|
+
}
|
|
103
|
+
/** As `readLines`, reading at most `limit` bytes; the byte offset just past the last whole line read (where to go on), or null on failure. */
|
|
104
|
+
function readLinesTo(file, from, take, limit = Infinity) {
|
|
105
|
+
let fd;
|
|
106
|
+
let done = from;
|
|
107
|
+
try {
|
|
108
|
+
fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
109
|
+
const buf = Buffer.allocUnsafe(CHUNK);
|
|
110
|
+
let carry = [];
|
|
111
|
+
let carried = 0;
|
|
112
|
+
let skipping = false;
|
|
113
|
+
let pos = from;
|
|
114
|
+
for (;;) {
|
|
115
|
+
const want = Math.min(CHUNK, from + limit - pos);
|
|
116
|
+
if (want <= 0)
|
|
117
|
+
return done > from ? done : pos; // a single line longer than the limit is passed over
|
|
118
|
+
const n = readSync(fd, buf, 0, want, pos);
|
|
119
|
+
if (n === 0)
|
|
120
|
+
break;
|
|
121
|
+
const base = pos;
|
|
122
|
+
pos += n;
|
|
123
|
+
let start = 0;
|
|
124
|
+
for (let nl = buf.indexOf(10, start); nl !== -1 && nl < n; nl = buf.indexOf(10, start)) {
|
|
125
|
+
if (!skipping) {
|
|
126
|
+
carry.push(Buffer.from(buf.subarray(start, nl)));
|
|
127
|
+
take(carry.length === 1 ? carry[0] : Buffer.concat(carry));
|
|
128
|
+
}
|
|
129
|
+
carry = [];
|
|
130
|
+
carried = 0;
|
|
131
|
+
skipping = false;
|
|
132
|
+
start = nl + 1;
|
|
133
|
+
done = base + start;
|
|
134
|
+
}
|
|
135
|
+
if (start < n && !skipping) {
|
|
136
|
+
carry.push(Buffer.from(buf.subarray(start, n)));
|
|
137
|
+
carried += n - start;
|
|
138
|
+
if (carried > LINE_MAX_BYTES) {
|
|
139
|
+
skipping = true;
|
|
140
|
+
carry = [];
|
|
141
|
+
carried = 0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!skipping && carried > 0 && limit === Infinity)
|
|
146
|
+
take(Buffer.concat(carry));
|
|
147
|
+
return limit === Infinity ? pos : done;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (fd !== undefined)
|
|
154
|
+
closeSync(fd);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Ids per transcript file, kept by what the file was when read; a transcript only grows, so an unchanged size and mtime is the same ids.
|
|
158
|
+
const idCache = new Map();
|
|
159
|
+
const ID_CACHE_MAX = 256;
|
|
160
|
+
/**
|
|
161
|
+
* The tool_use ids an agent transcript holds: the `id` of each `tool_use` block in an assistant message, kept only as a plain id. Read in
|
|
162
|
+
* chunks, line by line; a line is parsed only when it mentions tool_use, and nothing but the ids survives the parse. A line that does not
|
|
163
|
+
* parse, or claims another session, gives no ids. null when the file is not a plain regular file within the size cap.
|
|
164
|
+
*/
|
|
165
|
+
function toolUseIds(file, session, budget) {
|
|
166
|
+
let st;
|
|
167
|
+
try {
|
|
168
|
+
st = lstatSync(file);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
if (!st.isFile() || st.size > AGENT_TRANSCRIPT_MAX_BYTES)
|
|
174
|
+
return null;
|
|
175
|
+
const key = `${file}\u0000${session}\u0000${st.size}\u0000${st.mtimeMs}`;
|
|
176
|
+
if (idCache.has(key))
|
|
177
|
+
return idCache.get(key);
|
|
178
|
+
if (st.size > budget.left)
|
|
179
|
+
return null;
|
|
180
|
+
budget.left -= st.size;
|
|
181
|
+
const ids = new Set();
|
|
182
|
+
const take = (line) => {
|
|
183
|
+
if (line.length > LINE_MAX_BYTES || !line.includes('"tool_use"'))
|
|
184
|
+
return;
|
|
185
|
+
try {
|
|
186
|
+
const o = JSON.parse(line.toString("utf8"));
|
|
187
|
+
if (typeof o.sessionId === "string" && o.sessionId !== session)
|
|
188
|
+
return;
|
|
189
|
+
if (o.type !== "assistant" && o.message?.role !== "assistant")
|
|
190
|
+
return;
|
|
191
|
+
if (!Array.isArray(o.message?.content))
|
|
192
|
+
return;
|
|
193
|
+
for (const block of o.message.content) {
|
|
194
|
+
const id = block?.type === "tool_use" ? cleanId(block.id) : undefined;
|
|
195
|
+
if (id !== undefined)
|
|
196
|
+
ids.add(id);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// a line that does not parse gives no ids
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const ok = readLines(file, 0, take);
|
|
204
|
+
const out = ok ? ids : null;
|
|
205
|
+
if (idCache.size >= ID_CACHE_MAX)
|
|
206
|
+
idCache.delete(idCache.keys().next().value);
|
|
207
|
+
idCache.set(key, out);
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Ops without an agent id get their subagent lanes from the transcripts. A call op with no `agent_id` is matched, by its `tool_use_id`, against the tool_use
|
|
212
|
+
* ids in its own session's subagent transcripts. A match stamps the op in the returned copy with that agent's id and its launcher (the
|
|
213
|
+
* `toolUseId` of the agent's meta file), so the subagent placement works as for a stamped op. Stored ops are never rewritten: this is a new
|
|
214
|
+
* array, and an op it does not change is the same object.
|
|
215
|
+
*
|
|
216
|
+
* Refusals: an op that already has an `agent_id` (any non-null value) is left alone; an id two agents' transcripts both hold matches
|
|
217
|
+
* neither; only the op's own session's folder is read; a missing or unreadable folder, a link, an oversized file or a parse failure is no
|
|
218
|
+
* match; nothing from a transcript but tool_use ids and the meta file's `toolUseId` is read.
|
|
219
|
+
*/
|
|
220
|
+
export function backfillAgentLanes(ops, source) {
|
|
221
|
+
return markBackgroundLaunchers(backfillAgentIds(ops, source), source);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* A launch the host ran in the background without saying so in the Agent input is told by its agent's meta file
|
|
225
|
+
* (`requestShape: "background"`, beside the `toolUseId` of the launching call). Each Agent or Task op of the session whose call id is
|
|
226
|
+
* such a `toolUseId` is returned with `background: true`, in a new array (stored ops are never rewritten; an unchanged op is the same
|
|
227
|
+
* object). Nothing but `toolUseId` and `requestShape` is read, from the session's own folder only; a missing folder, a link, an
|
|
228
|
+
* oversized or unparsable file, or any other shape (a foreground agent has no `requestShape`) changes nothing.
|
|
229
|
+
*/
|
|
230
|
+
function markBackgroundLaunchers(ops, source) {
|
|
231
|
+
const wanted = new Map();
|
|
232
|
+
ops.forEach((op, at) => {
|
|
233
|
+
if (typeof op.args_json !== "string" || !op.args_json.includes("tool_use_id"))
|
|
234
|
+
return;
|
|
235
|
+
try {
|
|
236
|
+
const a = JSON.parse(op.args_json);
|
|
237
|
+
const session = cleanId(a?.session_id);
|
|
238
|
+
const tool = typeof a?.tool_name === "string" ? a.tool_name : op.tool;
|
|
239
|
+
if (a === null || typeof a !== "object" || session === undefined || typeof a.tool_use_id !== "string" || a.background === true)
|
|
240
|
+
return;
|
|
241
|
+
if (tool !== "Agent" && tool !== "Task")
|
|
242
|
+
return;
|
|
243
|
+
wanted.set(session, [...(wanted.get(session) ?? []), { at, id: a.tool_use_id, a }]);
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// not a call op
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
if (wanted.size === 0)
|
|
250
|
+
return ops;
|
|
251
|
+
const out = [...ops];
|
|
252
|
+
for (const [session, list] of wanted) {
|
|
253
|
+
const dir = subagentsDirOf(source.root, source.folder, session);
|
|
254
|
+
if (dir === null)
|
|
255
|
+
continue;
|
|
256
|
+
let names;
|
|
257
|
+
try {
|
|
258
|
+
names = readdirSync(dir).filter((n) => defaultProfile().helpers.metaName.test(n)).sort().slice(0, MAX_AGENT_FILES);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const background = new Set();
|
|
264
|
+
for (const name of names) {
|
|
265
|
+
const agentId = cleanId(defaultProfile().helpers.idOfMeta(name));
|
|
266
|
+
if (agentId === undefined)
|
|
267
|
+
continue;
|
|
268
|
+
const m = readMeta(dir, agentId);
|
|
269
|
+
if (m.background && m.launcher !== undefined)
|
|
270
|
+
background.add(m.launcher);
|
|
271
|
+
}
|
|
272
|
+
for (const { at, id, a } of list)
|
|
273
|
+
if (background.has(id))
|
|
274
|
+
out[at] = { ...ops[at], args_json: JSON.stringify({ ...a, background: true }) };
|
|
275
|
+
}
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
function backfillAgentIds(ops, source) {
|
|
279
|
+
const wanted = new Map();
|
|
280
|
+
const parsed = new Map();
|
|
281
|
+
ops.forEach((op, at) => {
|
|
282
|
+
if (typeof op.args_json !== "string" || !op.args_json.includes("tool_use_id"))
|
|
283
|
+
return;
|
|
284
|
+
try {
|
|
285
|
+
const a = JSON.parse(op.args_json);
|
|
286
|
+
const session = cleanId(a?.session_id);
|
|
287
|
+
if (a === null || typeof a !== "object" || session === undefined || typeof a.tool_use_id !== "string")
|
|
288
|
+
return;
|
|
289
|
+
if (a.agent_id !== undefined && a.agent_id !== null)
|
|
290
|
+
return;
|
|
291
|
+
parsed.set(at, a);
|
|
292
|
+
wanted.set(session, [...(wanted.get(session) ?? []), { at, id: a.tool_use_id }]);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// not a call op
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
if (wanted.size === 0)
|
|
299
|
+
return ops;
|
|
300
|
+
const out = [...ops];
|
|
301
|
+
for (const [session, list] of wanted) {
|
|
302
|
+
const dir = subagentsDirOf(source.root, source.folder, session);
|
|
303
|
+
if (dir === null)
|
|
304
|
+
continue;
|
|
305
|
+
let names;
|
|
306
|
+
try {
|
|
307
|
+
names = readdirSync(dir).filter((n) => defaultProfile().helpers.transcriptName.test(n)).sort().slice(0, MAX_AGENT_FILES);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const owner = new Map();
|
|
313
|
+
const budget = { left: MAX_SESSION_BYTES };
|
|
314
|
+
for (const name of names) {
|
|
315
|
+
const agentId = cleanId(defaultProfile().helpers.idOfTranscript(name));
|
|
316
|
+
if (agentId === undefined)
|
|
317
|
+
continue;
|
|
318
|
+
for (const id of toolUseIds(path.join(dir, name), session, budget) ?? [])
|
|
319
|
+
owner.set(id, owner.has(id) && owner.get(id) !== agentId ? null : agentId);
|
|
320
|
+
}
|
|
321
|
+
const launchers = new Map();
|
|
322
|
+
for (const { at, id } of list) {
|
|
323
|
+
const agentId = owner.get(id);
|
|
324
|
+
if (agentId === undefined || agentId === null)
|
|
325
|
+
continue;
|
|
326
|
+
if (!launchers.has(agentId))
|
|
327
|
+
launchers.set(agentId, readLauncher(dir, agentId));
|
|
328
|
+
const launcher = launchers.get(agentId);
|
|
329
|
+
out[at] = { ...ops[at], args_json: JSON.stringify({ ...parsed.get(at), agent_id: agentId, ...(launcher === undefined ? {} : { launch_tool_use_id: launcher }) }) };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
// ---- A call's end, from the host's transcripts ----
|
|
335
|
+
/**
|
|
336
|
+
* Collects end evidence (`CallEvidence`, credit-guard.ts) from transcript lines. Per tool_use id: its tool_result (time and kind), else the
|
|
337
|
+
* first later turn of the same agent (an assistant message with another message id, in the same lane of the file). A background Bash keeps
|
|
338
|
+
* only evidence that it never ran: its result comes back while its process still runs. Nothing but ids, times, the error flag and the
|
|
339
|
+
* first characters of an error result is read.
|
|
340
|
+
*/
|
|
341
|
+
export class EvidenceCollector {
|
|
342
|
+
#uses = new Map();
|
|
343
|
+
#results = new Map();
|
|
344
|
+
#turns = new Map();
|
|
345
|
+
#runsOn = new Set();
|
|
346
|
+
take(line) {
|
|
347
|
+
const text = typeof line === "string" ? line : line.toString("utf8");
|
|
348
|
+
if (!text.includes('"tool_result"') && !text.includes('"assistant"'))
|
|
349
|
+
return;
|
|
350
|
+
let o;
|
|
351
|
+
try {
|
|
352
|
+
o = JSON.parse(text);
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const at = typeof o.timestamp === "string" ? Date.parse(o.timestamp) : NaN;
|
|
358
|
+
if (!Number.isFinite(at))
|
|
359
|
+
return;
|
|
360
|
+
const lane = `${o.isSidechain === true ? 1 : 0}:${typeof o.agentId === "string" ? o.agentId : ""}`;
|
|
361
|
+
const content = Array.isArray(o.message?.content) ? o.message.content : [];
|
|
362
|
+
if (o.type === "assistant" || o.message?.role === "assistant") {
|
|
363
|
+
const msg = typeof o.message?.id === "string" ? o.message.id : null;
|
|
364
|
+
const turns = this.#turns.get(lane) ?? [];
|
|
365
|
+
turns.push({ msg, at });
|
|
366
|
+
this.#turns.set(lane, turns);
|
|
367
|
+
for (const b of content) {
|
|
368
|
+
const id = b?.type === "tool_use" ? cleanId(b.id) : undefined;
|
|
369
|
+
if (id === undefined || this.#uses.has(id))
|
|
370
|
+
continue;
|
|
371
|
+
const input = (b.input ?? {});
|
|
372
|
+
this.#uses.set(id, { msg, at, lane, background: b.name === "Bash" && input?.run_in_background === true });
|
|
373
|
+
}
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
for (const b of content) {
|
|
377
|
+
const id = b?.type === "tool_result" ? cleanId(b.tool_use_id) : undefined;
|
|
378
|
+
if (id === undefined || this.#results.has(id))
|
|
379
|
+
continue;
|
|
380
|
+
const c = b.content;
|
|
381
|
+
const head = typeof c === "string" ? c.slice(0, 400) : Array.isArray(c) ? c.map((x) => (typeof x?.text === "string" ? x.text : "")).join(" ").slice(0, 400) : "";
|
|
382
|
+
// a call the host moved to the background goes on past this result: it gives no end
|
|
383
|
+
if (resultRunsOn(head)) {
|
|
384
|
+
this.#runsOn.add(id);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
this.#results.set(id, { at, kind: classifyToolResult(head, b.is_error === true) });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/** The evidence per tool_use id, for the ids in `only` when given. */
|
|
391
|
+
evidence(only) {
|
|
392
|
+
const out = new Map();
|
|
393
|
+
const ids = new Set([...this.#uses.keys(), ...this.#results.keys()]);
|
|
394
|
+
for (const id of ids) {
|
|
395
|
+
if (only && !only.has(id))
|
|
396
|
+
continue;
|
|
397
|
+
if (this.#runsOn.has(id))
|
|
398
|
+
continue;
|
|
399
|
+
const use = this.#uses.get(id);
|
|
400
|
+
const result = this.#results.get(id);
|
|
401
|
+
if (use?.background) {
|
|
402
|
+
if (neverRan(result))
|
|
403
|
+
out.set(id, result);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (result) {
|
|
407
|
+
out.set(id, result);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (!use)
|
|
411
|
+
continue;
|
|
412
|
+
const next = (this.#turns.get(use.lane) ?? []).find((t) => t.at > use.at && t.msg !== null && t.msg !== use.msg);
|
|
413
|
+
if (next)
|
|
414
|
+
out.set(id, { at: next.at, kind: "turn" });
|
|
415
|
+
}
|
|
416
|
+
return out;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/** Most bytes of one transcript read live for end evidence at one event; the next event goes on from where this one stopped. */
|
|
420
|
+
const EVIDENCE_READ_MAX_BYTES = 8 * 1024 * 1024;
|
|
421
|
+
/**
|
|
422
|
+
* Live: the end evidence for `ids` in one transcript, read from byte `from` to its end, at most EVIDENCE_READ_MAX_BYTES at a time; `next` is
|
|
423
|
+
* where the next read goes on (just past the last whole line read), so a long session is read once, in steps, never skipped. A link, a
|
|
424
|
+
* missing file, or a file that shrank gives nothing and leaves `next` at `from` (the calls stay open: the safe direction).
|
|
425
|
+
*/
|
|
426
|
+
export function evidenceSince(file, from, ids) {
|
|
427
|
+
try {
|
|
428
|
+
const st = lstatSync(file);
|
|
429
|
+
if (!st.isFile() || st.size < from)
|
|
430
|
+
return { found: new Map(), next: from };
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return { found: new Map(), next: from };
|
|
434
|
+
}
|
|
435
|
+
const c = new EvidenceCollector();
|
|
436
|
+
const next = readLinesTo(file, from, (line) => c.take(line), EVIDENCE_READ_MAX_BYTES);
|
|
437
|
+
return next === null ? { found: new Map(), next: from } : { found: c.evidence(ids), next };
|
|
438
|
+
}
|
|
439
|
+
/** The main transcript of one session under the transcripts root: the task folder's project dir first, then any project dir that holds it. */
|
|
440
|
+
function sessionFileOf(root, folder, session) {
|
|
441
|
+
const isFile = (p) => {
|
|
442
|
+
try {
|
|
443
|
+
return lstatSync(p).isFile();
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
if (folder !== null) {
|
|
450
|
+
const dir = realDirUnder(root, folder.replace(/[^A-Za-z0-9]/g, "-"));
|
|
451
|
+
if (dir !== null && isFile(path.join(dir, `${session}.jsonl`)))
|
|
452
|
+
return path.join(dir, `${session}.jsonl`);
|
|
453
|
+
}
|
|
454
|
+
try {
|
|
455
|
+
for (const name of readdirSync(root).slice(0, MAX_PROJECT_DIRS)) {
|
|
456
|
+
const dir = realDirUnder(root, name);
|
|
457
|
+
if (dir !== null && isFile(path.join(dir, `${session}.jsonl`)))
|
|
458
|
+
return path.join(dir, `${session}.jsonl`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
// no such root
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* End evidence for the calls of recorded ops, from their sessions' transcripts (the main file and every subagent file), so a timeline
|
|
468
|
+
* of a ledger written before the adapter recorded it re-renders with calls that never ran, or had ended, closed. In memory only. A session
|
|
469
|
+
* whose files are missing, links or over the size caps gives nothing for its calls.
|
|
470
|
+
*/
|
|
471
|
+
// Evidence per transcript file, kept by what the file was when read (a transcript only grows).
|
|
472
|
+
const evidenceCache = new Map();
|
|
473
|
+
const EVIDENCE_CACHE_MAX = 256;
|
|
474
|
+
export function callEvidenceOf(ops, source) {
|
|
475
|
+
const bySession = new Map();
|
|
476
|
+
for (const op of ops) {
|
|
477
|
+
if (typeof op.args_json !== "string" || !op.args_json.includes("tool_use_id"))
|
|
478
|
+
continue;
|
|
479
|
+
try {
|
|
480
|
+
const a = JSON.parse(op.args_json);
|
|
481
|
+
const session = cleanId(a?.session_id);
|
|
482
|
+
const id = cleanId(a?.tool_use_id);
|
|
483
|
+
if (session === undefined || id === undefined)
|
|
484
|
+
continue;
|
|
485
|
+
bySession.set(session, (bySession.get(session) ?? new Set()).add(id));
|
|
486
|
+
}
|
|
487
|
+
catch {
|
|
488
|
+
// not a call op
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const out = new Map();
|
|
492
|
+
const budget = { left: MAX_SESSION_BYTES };
|
|
493
|
+
const read = (file, ids) => {
|
|
494
|
+
let key;
|
|
495
|
+
try {
|
|
496
|
+
const st = lstatSync(file);
|
|
497
|
+
if (!st.isFile() || st.size > AGENT_TRANSCRIPT_MAX_BYTES)
|
|
498
|
+
return;
|
|
499
|
+
key = `${file}\u0000${st.size}\u0000${st.mtimeMs}`;
|
|
500
|
+
if (!evidenceCache.has(key)) {
|
|
501
|
+
if (st.size > budget.left)
|
|
502
|
+
return;
|
|
503
|
+
budget.left -= st.size;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
let all = evidenceCache.get(key);
|
|
510
|
+
if (all === undefined) {
|
|
511
|
+
const c = new EvidenceCollector();
|
|
512
|
+
if (!readLines(file, 0, (line) => c.take(line)))
|
|
513
|
+
return;
|
|
514
|
+
all = c.evidence();
|
|
515
|
+
if (evidenceCache.size >= EVIDENCE_CACHE_MAX)
|
|
516
|
+
evidenceCache.delete(evidenceCache.keys().next().value);
|
|
517
|
+
evidenceCache.set(key, all);
|
|
518
|
+
}
|
|
519
|
+
for (const [id, ev] of all)
|
|
520
|
+
if (ids.has(id) && !out.has(id))
|
|
521
|
+
out.set(id, ev);
|
|
522
|
+
};
|
|
523
|
+
for (const [session, ids] of bySession) {
|
|
524
|
+
const main = sessionFileOf(source.root, source.folder, session);
|
|
525
|
+
if (main !== null)
|
|
526
|
+
read(main, ids);
|
|
527
|
+
const dir = subagentsDirOf(source.root, source.folder, session);
|
|
528
|
+
if (dir === null)
|
|
529
|
+
continue;
|
|
530
|
+
let names;
|
|
531
|
+
try {
|
|
532
|
+
names = readdirSync(dir).filter((n) => defaultProfile().helpers.transcriptName.test(n)).sort().slice(0, MAX_AGENT_FILES);
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
for (const name of names)
|
|
538
|
+
read(path.join(dir, name), ids);
|
|
539
|
+
}
|
|
540
|
+
return out;
|
|
541
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// What a credit stands on. A change is credited to calls; this says why those calls and not others. Stored beside the credit
|
|
2
|
+
// (`file_states.credit_basis`), read later to tell proof from inference. Pure: no host name, no I/O.
|
|
3
|
+
/** How a credit was reached, strongest first. `declared` and `joint` are named for hosts and rules that come later; nothing writes them yet. `host-reported-edit` is written by `hostReportedEdit`. */
|
|
4
|
+
export const PROOF_METHODS = ["argv-tag", "host-reported-edit", "declared", "named", "window", "joint", "unattributed"];
|
|
5
|
+
/** The methods that are proof. Any other basis, and a missing one (a row from before the basis was stored), is inference. */
|
|
6
|
+
const PROVEN_METHODS = ["argv-tag", "host-reported-edit"];
|
|
7
|
+
export const isInferredBasis = (basis) => !PROVEN_METHODS.includes(basis ?? "");
|
|
8
|
+
/**
|
|
9
|
+
* A change stands on a host-reported edit when every credited call is a host file-edit call that names this file by an absolute path of
|
|
10
|
+
* its own (`same` compares through the path kit), the tag evidence names no other writer, the call did not fail (`failed`), and the bytes recorded for the file are what the call reported writing (`content`: a process that rewrote the file after it leaves other bytes). An open call the credit was narrowed away from no longer blocks it (the exact replay is the proof; a concurrent writer of other bytes fails it; one of the same bytes is undetectable, a declared bound). Any doubt is false: the change stays inferred.
|
|
11
|
+
*/
|
|
12
|
+
export function hostReportedEdit(f) {
|
|
13
|
+
if (f.credited.length === 0)
|
|
14
|
+
return false;
|
|
15
|
+
if (!f.taggedWriters.every((id) => f.credited.includes(id)))
|
|
16
|
+
return false;
|
|
17
|
+
return f.credited.every((id) => !f.failed(id) && (f.call(id)?.edits ?? []).some((e) => f.same(e, f.file)) && f.content(id));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The basis of one change's credit. `argv-tag` only when the change is credited to someone and every credited call is a call the tag
|
|
21
|
+
* evidence names for this file: with no tag evidence, or a credited call the tag does not name, it is never `argv-tag`.
|
|
22
|
+
*/
|
|
23
|
+
export function creditBasisOf(f) {
|
|
24
|
+
if (f.credited.length === 0)
|
|
25
|
+
return "unattributed";
|
|
26
|
+
if (f.credited.every((id) => f.taggedWriters.includes(id)))
|
|
27
|
+
return "argv-tag";
|
|
28
|
+
if (f.hostEdit === true)
|
|
29
|
+
return "host-reported-edit";
|
|
30
|
+
return f.named ? "named" : "window";
|
|
31
|
+
}
|