@tea-agent/loop-agent 0.38.2 → 0.38.4
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/AGENTS.md +4 -1
- package/CHANGELOG.md +171 -96
- package/README.md +11 -5
- package/bin/loop-agent.js +7 -3
- package/dist/application/task-lifecycle/advance.js +4 -0
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +16 -5
- package/dist/cli/program.js +16 -2
- package/dist/cli/update/notifier.js +2 -2
- package/dist/cli.js +2 -1
- package/dist/commands/dag-rerun.js +55 -1
- package/dist/commands/init-model-catalog.js +464 -0
- package/dist/commands/init-upgrade.js +265 -97
- package/dist/commands/init.js +428 -27
- package/dist/commands/inspect-next.js +8 -0
- package/dist/commands/task-advance.js +31 -0
- package/dist/executors/dag-pi-executor.js +76 -10
- package/dist/executors/pi-event-serializer.js +42 -1
- package/dist/executors/pi-executor.js +51 -0
- package/dist/executors/pi-extension-resolver.js +233 -0
- package/dist/executors/pi-playwright-cli-tool.js +51 -12
- package/dist/executors/pi-sdk-executor.js +187 -59
- package/dist/executors/shell-executor.js +265 -15
- package/dist/executors/shell-write-guard.js +7 -0
- package/dist/shared/dag-prompt-override.js +28 -0
- package/dist/shared/operator/capabilities.js +32 -0
- package/dist/shared/playwright-cli-command-policy.js +15 -0
- package/dist/shared/update/console-notifier.js +100 -0
- package/dist/{cli → shared}/update/npm-client.js +41 -8
- package/dist/{cli → shared}/update/state.js +41 -13
- package/dist/task/contract/constants.js +1 -0
- package/dist/task/contract/diff.js +26 -0
- package/dist/task/contract/project.js +5 -0
- package/dist/task/contract/schema.js +6 -1
- package/dist/task/source-prepare/build-draft.js +15 -0
- package/dist/task/source-prepare/parse-intent.js +24 -4
- package/dist/worker/cli.js +31 -1
- package/dist/worker/console/chat/routes.js +1 -0
- package/dist/worker/console/dag-execution-receipt.js +33 -0
- package/dist/worker/console/operator-actions.js +116 -0
- package/dist/worker/console/operator-user-error.js +2 -2
- package/dist/worker/console/pi-readiness.js +4 -4
- package/dist/worker/console/routes.js +43 -2
- package/dist/worker/console/security.js +63 -9
- package/dist/worker/console/server.js +36 -5
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-C4bmo3iY.js → abnfDiagram-N423BO3Z-gauhD9kD.js} +1 -1
- package/dist/worker/console/static/assets/{arc-SAD7McOS.js → arc-pm3c2Rsl.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-DAVLUdK1.js → architectureDiagram-T3A2C74G-D_JAg3wH.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-CPPdv4vj.js → blockDiagram-VBNYF7ZC-Dk7-ex52.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-D1GRGZax.js → c4Diagram-5PPSVZJV-Uval9oRI.js} +1 -1
- package/dist/worker/console/static/assets/channel-CVrnUdZl.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-D_Bq2ZqK.js → chunk-2GRJ4B5K-BSYjHs-v.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-CPLVtamK.js → chunk-2Q5K7J3B-KGUuBXI8.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-DnaZWcL3.js → chunk-5RXB4S5H-JqAtxD9N.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BRTmFgnq.js → chunk-5VM5RSS4-D6EJOVQK.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-BRlfYZoH.js → chunk-6Q2QTUOP-B1JriSjm.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-CjNybD4u.js → chunk-GF5L2VYU-D62b96Jd.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-D3e-74fG.js → chunk-JWPE2WC7-BsNKEC_r.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-Br3ir6f2.js → chunk-KBJHAD2P-B56v6-ZP.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-1NgVuRbh.js → chunk-RYQCIY6F-D2KPnd8K.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-BTYuvuWN.js → chunk-XXDRQBXY-kzKSCaaL.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-aX91WTya.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-aX91WTya.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BC6Bgosf.js → cose-bilkent-JH36ORCC-C6N6KNJd.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-DV-HypfL.js → cynefin-VYW2F7L2-DiyymT2D.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-DhTaddO-.js → cynefinDiagram-MW4NZA55-BeKAXvf3.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BnEcOmiI.js → dagre-VZM6K2ZE-TkIdXfPF.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-xphGRVKp.js → diagram-7IWD3JNH-BFmSG3ks.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-CrdD1mRG.js → diagram-B4RE2ZJO-DqpJT2Fs.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-D4YdLsaF.js → diagram-LBJQPF4R-r5ATN43t.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-LCKyGZ5U.js → diagram-Q27KOJAE-DEcSCMuR.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-BeiTe7t0.js → diagram-UB23O5K3-VOvYRLVc.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-BO2cq8GS.js → ebnfDiagram-BXEA7PRR-D7f4Cb1u.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CmWww3Nt.js → erDiagram-JOGREHBK-ziUf3U0G.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-C2kkUYg5.js → flowDiagram-UKHOOZJN-BoRdQ-1y.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-DY_JZ2iQ.js → ganttDiagram-PKOTCBZU-B1-GncNm.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-BizhCSw9.js → gitGraphDiagram-DS77QQ5N-CTW-ph8W.js} +1 -1
- package/dist/worker/console/static/assets/index-C8rOIAJr.css +1 -0
- package/dist/worker/console/static/assets/{index-BXN89VPX.js → index-DEbyrEfW.js} +147 -68
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-Dlo2eK_d.js → infoDiagram-6WML65LV-BFA337tZ.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-3EIlIIuZ.js → ishikawaDiagram-WSZJBQD7-BtEujgRR.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DiMDe5Yh.js → journeyDiagram-NVQOT4AX-C8ZwD2Jp.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-sN553oIN.js → kanban-definition-27J2QSJJ-Ck-z8B11.js} +1 -1
- package/dist/worker/console/static/assets/{linear-D9Py31Ld.js → linear-CAyXjQjN.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-D7Occzk_.js → mermaid.core-CcWKn6tS.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-DjDRboiR.js → mindmap-definition-FAOFIHXS-C2NuDO7E.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-Cgc4qlzp.js → pegDiagram-VL7TDLO6-BFub3PDz.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-DxZj8pKd.js → pieDiagram-7S7Q4E2Y-BJx5THZ5.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-CJ50MngR.js → quadrantDiagram-CIZ2JOQS-DhalkDWV.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BY-OD8Tr.js → railroadDiagram-AXF67PYL-CVcBM36o.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-CQFButfK.js → requirementDiagram-LRYGKXZP-D_vy4n0w.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BB_QUK_b.js → sankeyDiagram-W5VNT64P-DGYdJL1D.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-CqhXZjyx.js → sequenceDiagram-SI44F4Z6-C1xJFg3k.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-2l1U4rgJ.js → sizeCapture-X5ZJPWSS-D_Fc43df.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-BX1FbrhJ.js → stateDiagram-OKZ733FA-BhGbIjbu.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DUt1lyFL.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-DOSnT7hb.js → swimlanes-SLNWSIFB-DVkNcO-V.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BM6SGr7j.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-DVJQA7AN.js → timeline-definition-Z64GVDOM-BQU9ufV0.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-74uxl9gx.js → vennDiagram-T6HMQDX7-BCQhRmYB.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-DsBxlcg_.js → wardleyDiagram-T6FBY63Y-DWerOyHO.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-snuW9Mjw.js → xychartDiagram-ELKLHX3M-DxLeebQU.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/mutation-gate.js +1 -1
- package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +328 -0
- package/dist/worker/loop-agent/loop-agent-client.js +7 -3
- package/dist/worker/observe/node-input.js +74 -3
- package/dist/worker/observe/node-process.js +377 -0
- package/dist/worker/observe/routes.js +36 -3
- package/dist/worker/observe/shell-handler-keys.js +34 -0
- package/dist/worker/observe/static/api.js +66 -0
- package/dist/worker/observe/static/constants.js +8 -1
- package/dist/worker/observe/static/dag-history-labels.js +4 -0
- package/dist/worker/observe/static/format.js +23 -0
- package/dist/worker/observe/static/markdown-render.js +20 -1
- package/dist/worker/observe/static/operator-chrome.js +4 -0
- package/dist/worker/observe/static/state.js +13 -2
- package/dist/worker/observe/static/styles.css +73 -0
- package/dist/worker/observe/static/views/dag-inspector.js +612 -8
- package/dist/worker/observe/static/views/dag.js +8 -1
- package/dist/worker/observe/static/views/failures.js +5 -2
- package/dist/worker/observe/static/views/session-timeline.js +78 -9
- package/dist/workflows/dag/backend-test-case-coverage-analysis.js +76 -6
- package/dist/workflows/dag/backend-test-scenario-partitions.js +73 -1
- package/dist/workflows/dag/contract-output-registry.js +15 -0
- package/dist/workflows/dag/failure-category.js +12 -0
- package/dist/workflows/dag/frontend-implementation-contract.js +145 -40
- package/dist/workflows/dag/frontend-prewrite-gate.js +87 -135
- package/dist/workflows/dag/frontend-repair.js +14 -0
- package/dist/workflows/dag/frontend-risk.js +15 -2
- package/dist/workflows/dag/frontend-test-case-checklist.js +26 -2
- package/dist/workflows/dag/frontend-test-case-manifest.js +5 -0
- package/dist/workflows/dag/frontend-test-case-quality.js +5 -13
- package/dist/workflows/dag/frontend-test-environment-probe.js +227 -0
- package/dist/workflows/dag/frontend-test-markdown.js +61 -0
- package/dist/workflows/dag/frontend-test-result-contract.js +160 -28
- package/dist/workflows/dag/frontend-test-standard-scenarios.js +68 -0
- package/dist/workflows/dag/frontend-verification-trace.js +29 -4
- package/dist/workflows/dag/init-hybrid.js +196 -117
- package/dist/workflows/dag/node-execution.js +139 -10
- package/dist/workflows/dag/prompt.js +15 -1
- package/dist/workflows/dag/rerun-plan.js +134 -3
- package/dist/workflows/dag/rerun-run.js +58 -6
- package/dist/workflows/dag/retry-policy.js +91 -0
- package/dist/workflows/dag/structured-output-repair.js +712 -0
- package/dist/workflows/dag/types.js +32 -1
- package/dist/workflows/dag/validate.js +41 -1
- package/docs/init-surface.manifest.json +5 -0
- package/docs/operations/README.md +1 -1
- package/docs/operations/local-development-environment.md +1 -5
- package/docs/skills/vetted-skill-registry.md +14 -0
- package/docs/templates/README.md +1 -1
- package/docs/templates/agent-dag.schema.json +44 -0
- package/docs/templates/backend-test-dag.json +2 -2
- package/docs/templates/frontend-test-dag.json +8 -10
- package/docs/templates/frontend-test-dag.retrieve-context.prompt.md +1 -1
- package/docs/templates/init-managed-agents.md +13 -3
- package/harness.json +2 -2
- package/package.json +12 -4
- package/scripts/next-info.mjs +356 -0
- package/scripts/next-publish-gate.mjs +238 -0
- package/scripts/release-source-binding.mjs +251 -0
- package/skills/analyze-product-requirements/SKILL.md +8 -5
- package/skills/analyze-product-requirements/references/acceptance-criteria.md +1 -1
- package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +10 -6
- package/skills/analyze-product-requirements/references/example.md +50 -0
- package/skills/analyze-product-requirements/references/forward-test-cases.md +11 -7
- package/skills/analyze-product-requirements/references/kb-integration.md +5 -5
- package/skills/analyze-product-requirements/references/product-analysis-schema.md +8 -4
- package/skills/analyze-product-requirements/references/product-requirement-schema.md +2 -2
- package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +1 -1
- package/skills/analyze-product-requirements/scripts/test-validators.mjs +11 -1
- package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +20 -1
- package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +9 -0
- package/skills/codebase-scout/SKILL.md +1 -1
- package/skills/fe-test-ui-scout/SKILL.md +65 -0
- package/skills/fe-test-ui-scout/references/ledger-schema.md +62 -0
- package/skills/fe-test-ui-scout/references/recon-protocol.md +54 -0
- package/skills/improve-codebase-architecture/SKILL.md +81 -0
- package/skills/improve-codebase-architecture/deepening.md +37 -0
- package/skills/improve-codebase-architecture/html-report.md +123 -0
- package/skills/improve-codebase-architecture/interface-design.md +44 -0
- package/skills/improve-codebase-architecture/language.md +53 -0
- package/skills/loop-agent/references/command-reference.md +11 -4
- package/skills/playwright-cli/SKILL.md +22 -0
- package/skills/playwright-cli-case-generator/SKILL.md +20 -1
- package/dist/worker/console/static/assets/channel-R6oQIDkw.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BPXlmPWI.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BPXlmPWI.js +0 -1
- package/dist/worker/console/static/assets/index-CuH5CNFu.css +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DJKi0Qel.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-YYe7EEm5.js +0 -8
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { collectNextInfo, formatNextInfo, } from "../../scripts/next-info.mjs";
|
|
2
|
+
export async function runInspectNext(repoRoot, args = []) {
|
|
3
|
+
const json = args.includes("--json");
|
|
4
|
+
const result = collectNextInfo({ cwd: repoRoot });
|
|
5
|
+
process.stdout.write(formatNextInfo(result, { json }));
|
|
6
|
+
if (!result.ok)
|
|
7
|
+
process.exitCode = result.exitCode || 1;
|
|
8
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { advanceTaskLifecycle, } from "../application/task-lifecycle/index.js";
|
|
2
|
+
import { backendTestConfigSchema, } from "../task/config-types.js";
|
|
2
3
|
import { buildOperatorResult, operatorFailed, processExitCodeForOutcome, writeOperatorJson, } from "../shared/operator/index.js";
|
|
3
4
|
import { createRunDagProgressObserver, validateRunDagProgressIntervalMs, } from "./run-dag-progress.js";
|
|
4
5
|
const COMMAND = "task advance";
|
|
@@ -14,6 +15,7 @@ const USAGE = `usage:
|
|
|
14
15
|
[--forbidden-path <glob>]...
|
|
15
16
|
[--verify <label:command>]...
|
|
16
17
|
[--verify-timeout <label:timeoutMs>]...
|
|
18
|
+
[--backend-test <json>]
|
|
17
19
|
[--accept-recommendations <digest>]
|
|
18
20
|
[--approve-gate <gate-id:digest>]
|
|
19
21
|
[--reject-gate <gate-id:digest> --reason <text>]
|
|
@@ -52,6 +54,30 @@ function parseVerifyTimeout(flag) {
|
|
|
52
54
|
}
|
|
53
55
|
return { label: flag.slice(0, idx), timeoutMs };
|
|
54
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse `--backend-test <json>` into a validated managed backendTest config.
|
|
59
|
+
* `{}` is legal (explicit clear back to the default layout).
|
|
60
|
+
*/
|
|
61
|
+
function parseBackendTestFlag(raw) {
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = JSON.parse(raw);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new Error(`invalid --backend-test ${raw}; expected an inline JSON object`);
|
|
68
|
+
}
|
|
69
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
70
|
+
throw new Error(`invalid --backend-test ${raw}; expected an inline JSON object`);
|
|
71
|
+
}
|
|
72
|
+
const result = backendTestConfigSchema.safeParse(parsed);
|
|
73
|
+
if (!result.success) {
|
|
74
|
+
const summary = result.error.issues
|
|
75
|
+
.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
|
|
76
|
+
.join("; ");
|
|
77
|
+
throw new Error(`invalid --backend-test: ${summary}`);
|
|
78
|
+
}
|
|
79
|
+
return result.data ?? {};
|
|
80
|
+
}
|
|
55
81
|
export function parseTaskAdvanceArgs(args) {
|
|
56
82
|
const options = {};
|
|
57
83
|
const positional = [];
|
|
@@ -113,6 +139,10 @@ export function parseTaskAdvanceArgs(args) {
|
|
|
113
139
|
options.verifyTimeout = pushList(options.verifyTimeout, next());
|
|
114
140
|
continue;
|
|
115
141
|
}
|
|
142
|
+
if (token === "--backend-test") {
|
|
143
|
+
options.backendTest = parseBackendTestFlag(next());
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
116
146
|
if (token === "--accept-recommendations") {
|
|
117
147
|
options.acceptRecommendations = next();
|
|
118
148
|
continue;
|
|
@@ -273,6 +303,7 @@ export function toUseCaseInput(repoRoot, taskId, options, observer) {
|
|
|
273
303
|
allowedPaths: options.allowedPaths,
|
|
274
304
|
forbiddenPaths: options.forbiddenPaths,
|
|
275
305
|
verifyCommands: verifyCommands.length > 0 ? verifyCommands : undefined,
|
|
306
|
+
backendTest: options.backendTest,
|
|
276
307
|
approveGateToken: options.approveGate,
|
|
277
308
|
rejectGateToken: options.rejectGate,
|
|
278
309
|
rejectReason: options.reason,
|
|
@@ -2,13 +2,14 @@ import path from "node:path";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { writeDagNodeJsonArtifact, writeTextArtifactFile, } from "../infrastructure/harness/artifact-store.js";
|
|
5
|
-
import { executePiStep, } from "./pi-executor.js";
|
|
5
|
+
import { executePiStep, resolvePiBackend, } from "./pi-executor.js";
|
|
6
|
+
import { resolveDagPiExtensions, } from "./pi-extension-resolver.js";
|
|
6
7
|
import { buildPiWriterToolPolicyContext, createPiWriterCustomTools, } from "./pi-writer-tool-policy.js";
|
|
7
8
|
import { cleanupPlaywrightCliDefaultSession, createPlaywrightCliTool, PI_COMMAND_CAPABILITY_REGISTRY, resolveCaseIdFromWriteSet, resolveEvidenceDirFromWriteSet, } from "./pi-playwright-cli-tool.js";
|
|
8
9
|
import { dagCommandPolicyAllows, resolveDagCommandPolicy, } from "../workflows/dag/types.js";
|
|
9
10
|
import { redactPromptForLog, truncateOutput, } from "../shared/output-truncation.js";
|
|
10
11
|
import { GitStatusUnavailableError, pathsChangedDuringRun, readGitStatusPorcelain, recoverRootNulArtifact, snapshotGitStatusPathFingerprints, snapshotGitStatusPorcelain, validateShellWriteGuard, } from "./shell-write-guard.js";
|
|
11
|
-
import { isWriterEmptyDiffRetryCandidate, isWriterTransportRetryCandidate, INCOMPLETE_WRITE_SET_RETRY_CATEGORY, WRITER_CLEAN_TIMEOUT_RETRY_CATEGORY, WRITER_EMPTY_DIFF_RETRY_CATEGORY, } from "../workflows/dag/retry-policy.js";
|
|
12
|
+
import { isTargetTemplateTransientRetryNode, isWriterEmptyDiffRetryCandidate, isWriterTransportRetryCandidate, INCOMPLETE_WRITE_SET_RETRY_CATEGORY, WRITER_CLEAN_TIMEOUT_RETRY_CATEGORY, WRITER_EMPTY_DIFF_RETRY_CATEGORY, } from "../workflows/dag/retry-policy.js";
|
|
12
13
|
import { assessBackendTestMdPlanCompleteness, assessBackendTestMdWriterCompleteness, assessBackendTestPytestPlanCompleteness, assessBackendTestPytestWriterCompleteness, assessBackendTestShardChildCompleteness, backendTestWriterProgressRoleForTask, classifyBackendTestWriterCompletenessFailure, isBackendTestCompletenessRetryCandidate, isBackendTestMdPlanTask, isBackendTestPytestPlanTask, isBackendTestShardChildTask, writeBackendTestWriterProgressArtifacts, } from "../workflows/dag/backend-test-writer-completeness.js";
|
|
13
14
|
import { resolveBackendTestLayout } from "../workflows/dag/backend-test-layout.js";
|
|
14
15
|
import { redactSecrets, truncateUtf8Preview } from "../shared/preview.js";
|
|
@@ -327,6 +328,36 @@ export async function writePiExecutorArtifacts(artifactsDir, input) {
|
|
|
327
328
|
await writeTextArtifactFile(summaryPath, buildPiResultSummaryMarkdown(input));
|
|
328
329
|
return { promptPath, summaryPath };
|
|
329
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Run-owned per-node Pi extension facts (plan 2026-08-21): requested ids,
|
|
333
|
+
* resolved packages (with absolute entry paths), and degraded/missing ids.
|
|
334
|
+
* Written only for nodes that declare `piExtensions`; never into the repo-level
|
|
335
|
+
* DAG template. Best-effort: artifact failures never fail the node.
|
|
336
|
+
*/
|
|
337
|
+
async function writePiExtensionsArtifact(nodeArtifactsDir, requested, resolved, missing) {
|
|
338
|
+
try {
|
|
339
|
+
const runDir = path.dirname(nodeArtifactsDir);
|
|
340
|
+
const nodeId = path.basename(nodeArtifactsDir);
|
|
341
|
+
await writeDagNodeJsonArtifact(runDir, nodeId, "pi-extensions.json", {
|
|
342
|
+
schemaVersion: 1,
|
|
343
|
+
requested: [...requested],
|
|
344
|
+
resolved: resolved.map((entry) => ({
|
|
345
|
+
id: entry.id,
|
|
346
|
+
packageName: entry.packageName,
|
|
347
|
+
version: entry.version,
|
|
348
|
+
path: entry.entryPaths.join(", "),
|
|
349
|
+
})),
|
|
350
|
+
missing: missing.map((entry) => ({
|
|
351
|
+
id: entry.id,
|
|
352
|
+
reason: entry.reason,
|
|
353
|
+
...(entry.detail ? { detail: entry.detail } : {}),
|
|
354
|
+
})),
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
// best-effort run fact; node execution continues
|
|
359
|
+
}
|
|
360
|
+
}
|
|
330
361
|
async function resolveValidatedFrontendBaseUrlFromContext(workspaceRoot, runDir) {
|
|
331
362
|
try {
|
|
332
363
|
const capability = JSON.parse(await readFile(path.join(runDir, "preflight-frontend-browser-tool-shell", "frontend-browser-capability.json"), "utf8"));
|
|
@@ -550,6 +581,29 @@ export async function executeDagPiNode(input, meta, piStepFn = executePiStep, wr
|
|
|
550
581
|
};
|
|
551
582
|
}
|
|
552
583
|
}
|
|
584
|
+
// Plan 2026-08-21 D4/D6: resolve the node's explicit Pi extension
|
|
585
|
+
// allowlist against the settings inventory. Degrade on missing packages —
|
|
586
|
+
// never fail the node — and persist requested/resolved/missing facts.
|
|
587
|
+
const piExtensionsResolution = input.task.piExtensions
|
|
588
|
+
? resolveDagPiExtensions({
|
|
589
|
+
repoRoot: input.cwd,
|
|
590
|
+
ids: input.task.piExtensions,
|
|
591
|
+
})
|
|
592
|
+
: undefined;
|
|
593
|
+
if (piExtensionsResolution) {
|
|
594
|
+
const piBackend = resolvePiBackend();
|
|
595
|
+
const cliDegraded = piBackend === "cli-only";
|
|
596
|
+
await writePiExtensionsArtifact(path.join(meta.runDir, input.task.id), input.task.piExtensions, cliDegraded ? [] : piExtensionsResolution.resolved, cliDegraded
|
|
597
|
+
? input.task.piExtensions.map((id) => ({
|
|
598
|
+
id,
|
|
599
|
+
reason: "not-installed",
|
|
600
|
+
detail: "cli backend does not load pi extensions (sdk-only v1)",
|
|
601
|
+
}))
|
|
602
|
+
: piExtensionsResolution.missing);
|
|
603
|
+
}
|
|
604
|
+
const piExtensionPaths = piExtensionsResolution && resolvePiBackend() !== "cli-only"
|
|
605
|
+
? piExtensionsResolution.resolved.flatMap((entry) => entry.entryPaths)
|
|
606
|
+
: undefined;
|
|
553
607
|
result = await piStepFn({
|
|
554
608
|
attachedFiles: [],
|
|
555
609
|
modelConfig: resolveDagPiModelConfig(input.model, input.thinking ? { thinking: input.thinking } : undefined),
|
|
@@ -564,6 +618,9 @@ export async function executeDagPiNode(input, meta, piStepFn = executePiStep, wr
|
|
|
564
618
|
stallTimeoutMs: input.stallTimeoutMs,
|
|
565
619
|
abortGraceMs: input.abortGraceMs,
|
|
566
620
|
...(writerToolPolicy ? { writerToolPolicy } : {}),
|
|
621
|
+
...(piExtensionPaths && piExtensionPaths.length > 0
|
|
622
|
+
? { piExtensionPaths }
|
|
623
|
+
: {}),
|
|
567
624
|
onActivity: bridgeActivity
|
|
568
625
|
? (activity) => {
|
|
569
626
|
if (activity.kind === "lease" ||
|
|
@@ -885,22 +942,31 @@ export async function executeDagPiNode(input, meta, piStepFn = executePiStep, wr
|
|
|
885
942
|
if (meta.writeGuardAttribution === "best-effort") {
|
|
886
943
|
stderrParts.push("write guard note: concurrent rank writers use best-effort per-node attribution; keep same-rank writeSet entries disjoint");
|
|
887
944
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
const writerCleanTimeout = !mapped.ok &&
|
|
892
|
-
mapped.failureCategory === "timeout" &&
|
|
893
|
-
writeGuardOk &&
|
|
945
|
+
const rawFailureCategory = mapped.failureCategory;
|
|
946
|
+
const writeToolCallCount = readWriterThinkingExhaustionEvidence(result).writeToolCallCount;
|
|
947
|
+
const zeroSideEffects = writeGuardOk &&
|
|
894
948
|
!completenessFailure &&
|
|
895
949
|
!writerThinkingExhausted &&
|
|
896
|
-
|
|
950
|
+
!writerOutcomeViolation &&
|
|
897
951
|
changeManifestChangedFiles !== undefined &&
|
|
898
952
|
changeManifestChangedFiles.length === 0 &&
|
|
899
|
-
|
|
953
|
+
writeToolCallCount === 0;
|
|
954
|
+
const targetCleanTransport = !mapped.ok &&
|
|
955
|
+
isTargetTemplateTransientRetryNode(input.task) &&
|
|
956
|
+
rawFailureCategory !== undefined &&
|
|
957
|
+
["timeout", "network", "rate-limit", "unavailable"].includes(rawFailureCategory) &&
|
|
958
|
+
zeroSideEffects;
|
|
959
|
+
const frontendCleanTimeout = !mapped.ok &&
|
|
960
|
+
rawFailureCategory === "timeout" &&
|
|
961
|
+
isWriterTransportRetryCandidate(input.task) &&
|
|
962
|
+
!isTargetTemplateTransientRetryNode(input.task) &&
|
|
963
|
+
zeroSideEffects;
|
|
964
|
+
const writerCleanTimeout = targetCleanTransport || frontendCleanTimeout;
|
|
900
965
|
return {
|
|
901
966
|
...mapped,
|
|
902
967
|
ok: false,
|
|
903
968
|
stderr: stderrParts.filter(Boolean).join("\n\n"),
|
|
969
|
+
...(rawFailureCategory ? { rawFailureCategory } : {}),
|
|
904
970
|
failureCategory: mapped.ok
|
|
905
971
|
? writeGuardOk
|
|
906
972
|
? completenessFailure
|
|
@@ -51,9 +51,50 @@ export function normalizePiSessionEvent(event) {
|
|
|
51
51
|
}
|
|
52
52
|
return unifyToolPayloadFields(event);
|
|
53
53
|
}
|
|
54
|
+
const TERMINAL_FINISH_REASON_TYPES = new Set([
|
|
55
|
+
'message_end',
|
|
56
|
+
'turn_end',
|
|
57
|
+
'assistant_message',
|
|
58
|
+
]);
|
|
59
|
+
function readExplicitFinishReason(source) {
|
|
60
|
+
const message = isRecord(source.message) ? source.message : undefined;
|
|
61
|
+
const candidates = [
|
|
62
|
+
source.finish_reason,
|
|
63
|
+
source.finishReason,
|
|
64
|
+
source.stop_reason,
|
|
65
|
+
source.stopReason,
|
|
66
|
+
message?.finish_reason,
|
|
67
|
+
message?.finishReason,
|
|
68
|
+
message?.stop_reason,
|
|
69
|
+
message?.stopReason,
|
|
70
|
+
];
|
|
71
|
+
for (const candidate of candidates) {
|
|
72
|
+
if (typeof candidate === 'string' && candidate.trim().length > 0) {
|
|
73
|
+
return candidate;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
function applyFinishReason(original, normalized) {
|
|
79
|
+
const originalType = typeof original.type === 'string' ? original.type : undefined;
|
|
80
|
+
if (!originalType || !TERMINAL_FINISH_REASON_TYPES.has(originalType)) {
|
|
81
|
+
return normalized;
|
|
82
|
+
}
|
|
83
|
+
const existing = readExplicitFinishReason({
|
|
84
|
+
finish_reason: normalized.finish_reason,
|
|
85
|
+
});
|
|
86
|
+
if (existing !== undefined) {
|
|
87
|
+
return normalized;
|
|
88
|
+
}
|
|
89
|
+
const promoted = readExplicitFinishReason(original);
|
|
90
|
+
if (promoted === undefined) {
|
|
91
|
+
return normalized;
|
|
92
|
+
}
|
|
93
|
+
return { ...normalized, finish_reason: promoted };
|
|
94
|
+
}
|
|
54
95
|
/** Serialize one SDK session event as a single JSONL line. */
|
|
55
96
|
export function serializeSessionEvent(event, options) {
|
|
56
|
-
const normalized = normalizePiSessionEvent(event);
|
|
97
|
+
const normalized = applyFinishReason(event, normalizePiSessionEvent(event));
|
|
57
98
|
if (typeof normalized.recordedAt !== 'string') {
|
|
58
99
|
normalized.recordedAt = options?.recordedAt ?? new Date().toISOString();
|
|
59
100
|
}
|
|
@@ -408,6 +408,50 @@ export class BoundedTextPreview {
|
|
|
408
408
|
].join("\n");
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Normalize provider-specific completion-limit labels to the DAG's canonical
|
|
413
|
+
* `length` signal. Other terminal reasons remain observable without being
|
|
414
|
+
* treated as truncation.
|
|
415
|
+
*/
|
|
416
|
+
export function normalizeProviderStopReason(value) {
|
|
417
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
418
|
+
return undefined;
|
|
419
|
+
const trimmed = value.trim();
|
|
420
|
+
const compact = trimmed.toLowerCase().replace(/[\s_-]/g, "");
|
|
421
|
+
if ([
|
|
422
|
+
"length",
|
|
423
|
+
"maxtokens",
|
|
424
|
+
"maxoutputtokens",
|
|
425
|
+
"outputlimit",
|
|
426
|
+
"tokenlimit",
|
|
427
|
+
"tokenlimitreached",
|
|
428
|
+
].includes(compact)) {
|
|
429
|
+
return "length";
|
|
430
|
+
}
|
|
431
|
+
return trimmed;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Extract a terminal stop reason from the provider event shapes used by Pi
|
|
435
|
+
* SDK/CLI bridges. Providers disagree on `stop*` versus `finish*`; keep this
|
|
436
|
+
* boundary centralized so downstream DAG recovery sees one canonical signal.
|
|
437
|
+
*/
|
|
438
|
+
export function extractPiEventStopReason(event) {
|
|
439
|
+
const nested = [event.message, event.response, event.completion].filter(isRecord);
|
|
440
|
+
const containers = [...nested, event];
|
|
441
|
+
for (const container of containers) {
|
|
442
|
+
for (const key of [
|
|
443
|
+
"stopReason",
|
|
444
|
+
"stop_reason",
|
|
445
|
+
"finishReason",
|
|
446
|
+
"finish_reason",
|
|
447
|
+
]) {
|
|
448
|
+
const normalized = normalizeProviderStopReason(container[key]);
|
|
449
|
+
if (normalized)
|
|
450
|
+
return normalized;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
411
455
|
export class PiJsonlStreamCollector {
|
|
412
456
|
lineBuffer = "";
|
|
413
457
|
discardUntilNewline = false;
|
|
@@ -415,6 +459,7 @@ export class PiJsonlStreamCollector {
|
|
|
415
459
|
parsedEvents = 0;
|
|
416
460
|
tokensUsed = 0;
|
|
417
461
|
outputTooLarge = false;
|
|
462
|
+
stopReason;
|
|
418
463
|
subagentTotalCalls = 0;
|
|
419
464
|
subagentFailedCalls = 0;
|
|
420
465
|
subagentModes = new Set();
|
|
@@ -454,6 +499,7 @@ export class PiJsonlStreamCollector {
|
|
|
454
499
|
assistantText: this.assistantText.trim(),
|
|
455
500
|
outputTooLarge: this.outputTooLarge,
|
|
456
501
|
parsedEvents: this.parsedEvents,
|
|
502
|
+
stopReason: this.stopReason,
|
|
457
503
|
subagentStats: this.formatSubagentStats(),
|
|
458
504
|
tokensUsed: this.tokensUsed,
|
|
459
505
|
};
|
|
@@ -472,6 +518,10 @@ export class PiJsonlStreamCollector {
|
|
|
472
518
|
}
|
|
473
519
|
}
|
|
474
520
|
consumeEvent(event) {
|
|
521
|
+
const stopReason = extractPiEventStopReason(event);
|
|
522
|
+
if (stopReason === "length" || !this.stopReason) {
|
|
523
|
+
this.stopReason = stopReason ?? this.stopReason;
|
|
524
|
+
}
|
|
475
525
|
const candidate = extractAssistantTextFromEvent(event);
|
|
476
526
|
if (candidate !== undefined) {
|
|
477
527
|
if (candidate.length > MAX_ASSISTANT_TEXT_CHARS) {
|
|
@@ -865,6 +915,7 @@ async function executeSingleCliAttempt(options, modelConfig, promptFilePath) {
|
|
|
865
915
|
stdoutTruncated: stdoutPreview.truncated,
|
|
866
916
|
stderrTruncated: stderrPreview.truncated,
|
|
867
917
|
outputTooLarge: collected.outputTooLarge,
|
|
918
|
+
stopReason: collected.stopReason,
|
|
868
919
|
timedOut,
|
|
869
920
|
tokensUsed: collected.tokensUsed,
|
|
870
921
|
subagentStats: collected.subagentStats,
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Pi extension allowlist for backend implementation DAGs (plan D2/D3).
|
|
6
|
+
* DAG specs carry these frozen short ids; the executor resolves them against
|
|
7
|
+
* the Pi agent settings package inventory at run time.
|
|
8
|
+
*/
|
|
9
|
+
export const DAG_PI_EXTENSION_IDS = ["pi-codegraph", "pi-lens"];
|
|
10
|
+
/**
|
|
11
|
+
* Alias table: one DAG short id may resolve to multiple published package
|
|
12
|
+
* names. The first settings spec whose de-`npm:`-prefixed package name is in
|
|
13
|
+
* the alias set wins (project settings override user settings).
|
|
14
|
+
*/
|
|
15
|
+
export const DAG_PI_EXTENSION_PACKAGE_ALIASES = {
|
|
16
|
+
"pi-codegraph": [
|
|
17
|
+
"@estebanforge/pi-codegraph-enhanced",
|
|
18
|
+
"@vndv/pi-codegraph",
|
|
19
|
+
"pi-codegraph",
|
|
20
|
+
],
|
|
21
|
+
"pi-lens": ["pi-lens"],
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Extension tools that must never be activated as extras on any node (D5):
|
|
25
|
+
* they mutate files without the writer path policy. Writer nodes keep only
|
|
26
|
+
* policy-wrapped edit/write; read nodes keep only navigation tools.
|
|
27
|
+
*/
|
|
28
|
+
export const DAG_PI_EXTENSION_WRITE_TOOL_DENY = new Set([
|
|
29
|
+
"ast_grep_replace",
|
|
30
|
+
]);
|
|
31
|
+
/** Builtin tool names extensions must never replace (D5). */
|
|
32
|
+
export const DAG_PI_EXTENSION_PROTECTED_BUILTIN_TOOLS = new Set(["read", "edit", "write", "bash", "grep", "find", "ls"]);
|
|
33
|
+
/** Deny surface extensions must never activate (D5). */
|
|
34
|
+
export const DAG_PI_EXTENSION_DENIED_TOOL_IDS = new Set([
|
|
35
|
+
"apply_patch",
|
|
36
|
+
"apply-patch",
|
|
37
|
+
"full-tools",
|
|
38
|
+
"full_tools",
|
|
39
|
+
"coding-chat",
|
|
40
|
+
"coding_chat",
|
|
41
|
+
"shell",
|
|
42
|
+
]);
|
|
43
|
+
export function isDagPiExtensionId(value) {
|
|
44
|
+
return DAG_PI_EXTENSION_IDS.includes(value);
|
|
45
|
+
}
|
|
46
|
+
function getPiAgentDir() {
|
|
47
|
+
const envDir = process.env.PI_CODING_AGENT_DIR;
|
|
48
|
+
if (envDir)
|
|
49
|
+
return envDir;
|
|
50
|
+
return path.join(os.homedir(), ".pi", "agent");
|
|
51
|
+
}
|
|
52
|
+
function readSettingsPackages(settingsPath) {
|
|
53
|
+
try {
|
|
54
|
+
if (!existsSync(settingsPath))
|
|
55
|
+
return undefined;
|
|
56
|
+
const parsed = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
57
|
+
if (!Array.isArray(parsed.packages))
|
|
58
|
+
return undefined;
|
|
59
|
+
return parsed.packages.filter((spec) => typeof spec === "string");
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Strip an `npm:` prefix from a settings package spec, e.g. `npm:pi-lens`. */
|
|
66
|
+
export function packageNameFromSpec(spec) {
|
|
67
|
+
return spec.startsWith("npm:") ? spec.slice(4) : spec;
|
|
68
|
+
}
|
|
69
|
+
function loadPackageInventories(repoRoot) {
|
|
70
|
+
const agentDir = getPiAgentDir();
|
|
71
|
+
const userSpecs = readSettingsPackages(path.join(agentDir, "settings.json"));
|
|
72
|
+
const projectSpecs = readSettingsPackages(path.join(repoRoot, ".pi", "settings.json"));
|
|
73
|
+
const inventories = [];
|
|
74
|
+
if (userSpecs) {
|
|
75
|
+
inventories.push({
|
|
76
|
+
specs: userSpecs,
|
|
77
|
+
nodeModulesRoot: path.join(agentDir, "npm", "node_modules"),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (projectSpecs) {
|
|
81
|
+
inventories.push({
|
|
82
|
+
specs: projectSpecs,
|
|
83
|
+
nodeModulesRoot: path.join(repoRoot, "node_modules"),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return inventories;
|
|
87
|
+
}
|
|
88
|
+
const EXTENSION_FILE_RE = /\.(?:ts|js|mjs|cjs)$/;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve a package's `pi.extensions` entries to absolute entry paths.
|
|
91
|
+
* - A file entry maps to itself.
|
|
92
|
+
* - A directory entry expands to every extension file directly inside it
|
|
93
|
+
* (e.g. `@estebanforge/pi-codegraph-enhanced` ships `./extensions` holding
|
|
94
|
+
* `codegraph.ts`).
|
|
95
|
+
* No `pi.extensions` declaration, or a declaration whose paths do not exist,
|
|
96
|
+
* yields no entries (caller records `no-entry`) — no heuristic scanning
|
|
97
|
+
* outside declared paths.
|
|
98
|
+
*/
|
|
99
|
+
export function resolvePackageEntryPaths(packageDir) {
|
|
100
|
+
let manifest;
|
|
101
|
+
try {
|
|
102
|
+
manifest = JSON.parse(readFileSync(path.join(packageDir, "package.json"), "utf8"));
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return { entryPaths: [], reason: "no-entry" };
|
|
106
|
+
}
|
|
107
|
+
const declared = manifest.pi?.extensions;
|
|
108
|
+
if (!Array.isArray(declared)) {
|
|
109
|
+
return { entryPaths: [], reason: "no-entry" };
|
|
110
|
+
}
|
|
111
|
+
const entryPaths = [];
|
|
112
|
+
for (const entry of declared) {
|
|
113
|
+
if (typeof entry !== "string" || entry.length === 0)
|
|
114
|
+
continue;
|
|
115
|
+
const resolved = path.resolve(packageDir, entry);
|
|
116
|
+
if (!existsSync(resolved))
|
|
117
|
+
continue;
|
|
118
|
+
let isDirectory = false;
|
|
119
|
+
try {
|
|
120
|
+
isDirectory = statSync(resolved).isDirectory();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!isDirectory) {
|
|
126
|
+
entryPaths.push(resolved);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
let names;
|
|
130
|
+
try {
|
|
131
|
+
names = readdirSync(resolved);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
for (const name of names.sort()) {
|
|
137
|
+
if (!EXTENSION_FILE_RE.test(name))
|
|
138
|
+
continue;
|
|
139
|
+
entryPaths.push(path.join(resolved, name));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (entryPaths.length === 0) {
|
|
143
|
+
return { entryPaths: [], reason: "no-entry" };
|
|
144
|
+
}
|
|
145
|
+
return { entryPaths };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Resolve frozen DAG short ids against the Pi settings package inventory
|
|
149
|
+
* (user `~/.pi/agent/settings.json`, then project `.pi/settings.json` — a
|
|
150
|
+
* later match on the same alias wins). Pure synchronous read; never throws.
|
|
151
|
+
*/
|
|
152
|
+
export function resolveDagPiExtensions(input) {
|
|
153
|
+
const inventories = loadPackageInventories(input.repoRoot);
|
|
154
|
+
const resolved = [];
|
|
155
|
+
const missing = [];
|
|
156
|
+
for (const id of input.ids) {
|
|
157
|
+
if (!isDagPiExtensionId(id)) {
|
|
158
|
+
missing.push({
|
|
159
|
+
id,
|
|
160
|
+
reason: "package-unreadable",
|
|
161
|
+
detail: `unknown pi extension id: ${id}`,
|
|
162
|
+
});
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const aliases = DAG_PI_EXTENSION_PACKAGE_ALIASES[id];
|
|
166
|
+
let matched;
|
|
167
|
+
// Later inventories (project) override earlier (user).
|
|
168
|
+
for (const inventory of inventories) {
|
|
169
|
+
for (const spec of inventory.specs) {
|
|
170
|
+
const packageName = packageNameFromSpec(spec);
|
|
171
|
+
if (!aliases.includes(packageName))
|
|
172
|
+
continue;
|
|
173
|
+
const packageDir = path.join(inventory.nodeModulesRoot, ...packageName.split("/"));
|
|
174
|
+
if (!existsSync(packageDir))
|
|
175
|
+
continue;
|
|
176
|
+
try {
|
|
177
|
+
const manifest = JSON.parse(readFileSync(path.join(packageDir, "package.json"), "utf8"));
|
|
178
|
+
if (typeof manifest.version !== "string")
|
|
179
|
+
continue;
|
|
180
|
+
matched = { packageDir, packageName, version: manifest.version };
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// unreadable manifest: skip this candidate
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!matched) {
|
|
188
|
+
missing.push({ id, reason: "not-installed" });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const entries = resolvePackageEntryPaths(matched.packageDir);
|
|
192
|
+
if (entries.entryPaths.length === 0) {
|
|
193
|
+
missing.push({
|
|
194
|
+
id,
|
|
195
|
+
reason: entries.reason === "no-entry" ? "no-entry" : "package-unreadable",
|
|
196
|
+
});
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
resolved.push({
|
|
200
|
+
id,
|
|
201
|
+
packageName: matched.packageName,
|
|
202
|
+
version: matched.version,
|
|
203
|
+
entryPaths: entries.entryPaths,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return { resolved, missing };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Compute extension tool names that may join a node's active tool allowlist
|
|
210
|
+
* after session creation (D5): new tool names registered by the loaded
|
|
211
|
+
* extensions, minus protected builtins, the deny surface, and write-capable
|
|
212
|
+
* extension tools (both buckets — writer writes stay policy-wrapped only).
|
|
213
|
+
*/
|
|
214
|
+
export function computeExtensionToolAllowlistExtras(sessionTools, baseline) {
|
|
215
|
+
const baselineLower = new Set(baseline.map((name) => name.toLowerCase()));
|
|
216
|
+
const extras = [];
|
|
217
|
+
for (const tool of sessionTools) {
|
|
218
|
+
const name = tool && typeof tool.name === "string" ? tool.name : undefined;
|
|
219
|
+
if (!name)
|
|
220
|
+
continue;
|
|
221
|
+
const lower = name.toLowerCase();
|
|
222
|
+
if (baselineLower.has(lower))
|
|
223
|
+
continue;
|
|
224
|
+
if (DAG_PI_EXTENSION_PROTECTED_BUILTIN_TOOLS.has(lower))
|
|
225
|
+
continue;
|
|
226
|
+
if (DAG_PI_EXTENSION_DENIED_TOOL_IDS.has(lower))
|
|
227
|
+
continue;
|
|
228
|
+
if (DAG_PI_EXTENSION_WRITE_TOOL_DENY.has(lower))
|
|
229
|
+
continue;
|
|
230
|
+
extras.push(name);
|
|
231
|
+
}
|
|
232
|
+
return extras;
|
|
233
|
+
}
|