@tea-agent/loop-agent 0.1.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/AGENTS.md +121 -0
- package/CHANGELOG.md +37 -0
- package/README.md +144 -0
- package/bin/loop-agent.js +21 -0
- package/dist/adapters/aimax.js +91 -0
- package/dist/adapters/context.js +32 -0
- package/dist/adapters/index.js +28 -0
- package/dist/adapters/loop-agent.js +98 -0
- package/dist/adapters/types.js +1 -0
- package/dist/cli/catalog.js +259 -0
- package/dist/cli/help.js +55 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/program.js +505 -0
- package/dist/cli.js +12 -0
- package/dist/commands/closeout.js +13 -0
- package/dist/commands/coverage-audit.js +14 -0
- package/dist/commands/cursor-prompt.js +222 -0
- package/dist/commands/cursor-worker.js +43 -0
- package/dist/commands/dag-approve.js +102 -0
- package/dist/commands/dag-final-verification.js +76 -0
- package/dist/commands/dag-init-hybrid.js +56 -0
- package/dist/commands/dag-reconcile-tasks.js +51 -0
- package/dist/commands/dag-reject.js +91 -0
- package/dist/commands/dag-report.js +177 -0
- package/dist/commands/dag-resume.js +34 -0
- package/dist/commands/dag-run-task.js +470 -0
- package/dist/commands/dag-validate.js +186 -0
- package/dist/commands/dag-workflow-compile.js +91 -0
- package/dist/commands/dag-workflow-plan.js +130 -0
- package/dist/commands/dag-workflow-validate.js +66 -0
- package/dist/commands/delegate.js +132 -0
- package/dist/commands/docs-archive.js +5 -0
- package/dist/commands/docs-audit.js +5 -0
- package/dist/commands/doctor.js +50 -0
- package/dist/commands/goal.js +92 -0
- package/dist/commands/handoff-check.js +5 -0
- package/dist/commands/harvest.js +44 -0
- package/dist/commands/inspect.js +11 -0
- package/dist/commands/instructions.js +195 -0
- package/dist/commands/knowledge.js +64 -0
- package/dist/commands/loop-benchmark.js +72 -0
- package/dist/commands/loop.js +241 -0
- package/dist/commands/new-task.js +5 -0
- package/dist/commands/pi-prompt.js +181 -0
- package/dist/commands/pi-reuse-benchmark.js +153 -0
- package/dist/commands/plan-list.js +5 -0
- package/dist/commands/promote-run.js +29 -0
- package/dist/commands/reference-index.js +16 -0
- package/dist/commands/run-dag.js +184 -0
- package/dist/commands/spine.js +38 -0
- package/dist/commands/stats.js +84 -0
- package/dist/commands/status.js +56 -0
- package/dist/commands/study-init.js +192 -0
- package/dist/commands/workflow.js +259 -0
- package/dist/commands/worktree-create.js +31 -0
- package/dist/commands/worktree-list.js +5 -0
- package/dist/commands/worktree-remove.js +26 -0
- package/dist/cursor-worker-entry.js +8 -0
- package/dist/executors/config-core.js +55 -0
- package/dist/executors/config.js +2 -0
- package/dist/executors/cursor-artifacts.js +33 -0
- package/dist/executors/cursor-execution-log.js +81 -0
- package/dist/executors/cursor-executor-artifacts.js +135 -0
- package/dist/executors/cursor-executor.js +468 -0
- package/dist/executors/cursor-run.js +115 -0
- package/dist/executors/cursor-tool.js +94 -0
- package/dist/executors/cursor-worker-client.js +213 -0
- package/dist/executors/cursor-worker-protocol.js +18 -0
- package/dist/executors/cursor-worker-server.js +54 -0
- package/dist/executors/cursor-worker.js +3 -0
- package/dist/executors/cursor.js +6 -0
- package/dist/executors/dag-cursor-executor.js +88 -0
- package/dist/executors/dag-pi-executor.js +322 -0
- package/dist/executors/dag-static-executor.js +45 -0
- package/dist/executors/dag.js +4 -0
- package/dist/executors/index.js +8 -0
- package/dist/executors/model-routing.js +60 -0
- package/dist/executors/pi-event-serializer.js +43 -0
- package/dist/executors/pi-executor.js +606 -0
- package/dist/executors/pi-reuse-benchmark.js +316 -0
- package/dist/executors/pi-runtime-reuse.js +29 -0
- package/dist/executors/pi-sdk-executor.js +255 -0
- package/dist/executors/pi-sdk.js +1 -0
- package/dist/executors/pi.js +3 -0
- package/dist/executors/shell-executor.js +300 -0
- package/dist/executors/shell-presets.js +47 -0
- package/dist/executors/shell-verification.js +251 -0
- package/dist/executors/shell-write-guard.js +126 -0
- package/dist/executors/shell.js +3 -0
- package/dist/executors/static.js +1 -0
- package/dist/governance/checks.js +434 -0
- package/dist/governance/harness.js +9 -0
- package/dist/governance/index.js +3 -0
- package/dist/governance/manifest-types.js +128 -0
- package/dist/governance/manifest.js +2 -0
- package/dist/governance/path-guard.js +69 -0
- package/dist/governance/path-guards.js +2 -0
- package/dist/governance/profiles.js +3 -0
- package/dist/governance/requirement-coverage.js +425 -0
- package/dist/governance/skill-safety.js +135 -0
- package/dist/governance/spine-audit.js +152 -0
- package/dist/records/closeout.js +2 -0
- package/dist/records/harvest.js +236 -0
- package/dist/records/index.js +3 -0
- package/dist/records/one-shot-runs.js +421 -0
- package/dist/records/promotion.js +199 -0
- package/dist/shared/artifacts-core.js +88 -0
- package/dist/shared/artifacts.js +2 -0
- package/dist/shared/context-files.js +32 -0
- package/dist/shared/context.js +2 -0
- package/dist/shared/copy-dir.js +17 -0
- package/dist/shared/git-progress.js +165 -0
- package/dist/shared/index.js +5 -0
- package/dist/shared/logger.js +23 -0
- package/dist/shared/one-shot-prompt-args.js +98 -0
- package/dist/shared/path-refs.js +31 -0
- package/dist/shared/prompts.js +26 -0
- package/dist/shared/reference-context.js +238 -0
- package/dist/shared/timeout-policy.js +19 -0
- package/dist/shared/timeout.js +1 -0
- package/dist/shared/types.js +5 -0
- package/dist/task/config-types.js +97 -0
- package/dist/task/config.js +2 -0
- package/dist/task/delegate.js +220 -0
- package/dist/task/goal-audit.js +51 -0
- package/dist/task/goal-policy.js +8 -0
- package/dist/task/goal.js +3 -0
- package/dist/task/ids.js +1 -0
- package/dist/task/index.js +9 -0
- package/dist/task/lifecycle.js +1 -0
- package/dist/task/paths.js +1 -0
- package/dist/task/read-model.js +149 -0
- package/dist/task/runtime.js +699 -0
- package/dist/task/source-state.js +1 -0
- package/dist/task/state.js +55 -0
- package/dist/task/subagent-guidance.js +1 -0
- package/dist/task/workflow-state-types.js +92 -0
- package/dist/task/worktree-cleanup.js +140 -0
- package/dist/task/worktree.js +171 -0
- package/dist/workflows/dag/authoring.js +8 -0
- package/dist/workflows/dag/authority-surface.js +138 -0
- package/dist/workflows/dag/canvas-observer.js +474 -0
- package/dist/workflows/dag/decision-envelope.js +502 -0
- package/dist/workflows/dag/decision-evidence.js +153 -0
- package/dist/workflows/dag/decision-gates.js +1 -0
- package/dist/workflows/dag/executor-registry.js +25 -0
- package/dist/workflows/dag/facts.js +4 -0
- package/dist/workflows/dag/failure-category.js +111 -0
- package/dist/workflows/dag/final-verification.js +180 -0
- package/dist/workflows/dag/governance-constants.js +5 -0
- package/dist/workflows/dag/governance-profile.js +405 -0
- package/dist/workflows/dag/index.js +6 -0
- package/dist/workflows/dag/init-hybrid.js +855 -0
- package/dist/workflows/dag/knowledge-curator.js +162 -0
- package/dist/workflows/dag/lifecycle.js +484 -0
- package/dist/workflows/dag/prompt-source.js +88 -0
- package/dist/workflows/dag/prompt.js +130 -0
- package/dist/workflows/dag/reconcile-tasks.js +404 -0
- package/dist/workflows/dag/recovery-recommendation.js +226 -0
- package/dist/workflows/dag/repair-artifact.js +136 -0
- package/dist/workflows/dag/report.js +1019 -0
- package/dist/workflows/dag/runner.js +1677 -0
- package/dist/workflows/dag/runtime.js +5 -0
- package/dist/workflows/dag/skill-instructions.js +471 -0
- package/dist/workflows/dag/skills.js +41 -0
- package/dist/workflows/dag/spec.js +3 -0
- package/dist/workflows/dag/topo.js +30 -0
- package/dist/workflows/dag/types.js +275 -0
- package/dist/workflows/dag/upstream-artifacts.js +95 -0
- package/dist/workflows/dag/validate.js +527 -0
- package/dist/workflows/dynamic/artifacts.js +65 -0
- package/dist/workflows/dynamic/compile.js +360 -0
- package/dist/workflows/dynamic/compileTypes.js +1 -0
- package/dist/workflows/dynamic/errors.js +5 -0
- package/dist/workflows/dynamic/index.js +7 -0
- package/dist/workflows/dynamic/profiles.js +156 -0
- package/dist/workflows/dynamic/spec.js +114 -0
- package/dist/workflows/dynamic/validate.js +275 -0
- package/dist/workflows/loop/actions.js +1334 -0
- package/dist/workflows/loop/benchmark.js +510 -0
- package/dist/workflows/loop/closeout.js +134 -0
- package/dist/workflows/loop/context.js +48 -0
- package/dist/workflows/loop/events.js +25 -0
- package/dist/workflows/loop/hash.js +32 -0
- package/dist/workflows/loop/index.js +8 -0
- package/dist/workflows/loop/paths.js +17 -0
- package/dist/workflows/loop/rounds.js +81 -0
- package/dist/workflows/loop/signals.js +55 -0
- package/dist/workflows/loop/state.js +116 -0
- package/dist/workflows/loop/templates.js +54 -0
- package/dist/workflows/loop/types.js +28 -0
- package/docs/README.md +62 -0
- package/docs/agent-dag-recovery-playbook.md +158 -0
- package/docs/agent-dag-runner.md +40 -0
- package/docs/cursor-executor-usage.md +25 -0
- package/docs/decisions/README.md +3 -0
- package/docs/design/README.md +36 -0
- package/docs/development-principles.md +71 -0
- package/docs/dynamic-workflow-dag-engine-roadmap.md +1749 -0
- package/docs/exec-plans/README.md +6 -0
- package/docs/exec-plans/active/README.md +5 -0
- package/docs/exec-plans/completed/README.md +5 -0
- package/docs/feature-workflow.md +184 -0
- package/docs/harness-methodology-debugging.md +153 -0
- package/docs/harness-methodology-tdd.md +130 -0
- package/docs/harness-methodology-verification.md +27 -0
- package/docs/loop-agent-harness.md +42 -0
- package/docs/progress/README.md +3 -0
- package/docs/reports/README.md +3 -0
- package/docs/templates/adr.md +60 -0
- package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -0
- package/docs/templates/agent-dag-decision-envelope.schema.json +213 -0
- package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -0
- package/docs/templates/agent-dag-decision-gate.prompt.md +246 -0
- package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -0
- package/docs/templates/agent-dag-report.schema.json +423 -0
- package/docs/templates/agent-dag-review-verdict.prompt.md +68 -0
- package/docs/templates/agent-dag.base.json +195 -0
- package/docs/templates/agent-dag.final-verification.json +190 -0
- package/docs/templates/agent-dag.schema.json +316 -0
- package/docs/templates/agent-dag.supervised-implementation.json +500 -0
- package/docs/templates/exec-plan.md +64 -0
- package/docs/templates/feature-spec.md +53 -0
- package/docs/templates/hybrid-dag.json +193 -0
- package/docs/templates/progress-log.md +17 -0
- package/docs/templates/project-start-checklist.md +9 -0
- package/docs/templates/qa-report.md +42 -0
- package/docs/templates/sprint-contract.md +29 -0
- package/docs/verification-matrix.md +30 -0
- package/examples/decision-gate-agent-dag.json +123 -0
- package/examples/example-dag.json +51 -0
- package/examples/hybrid-loop-agent-dag.json +194 -0
- package/harness.json +92 -0
- package/package.json +61 -0
- package/skills/ai-engineering-context/SKILL.md +48 -0
- package/skills/loop-agent/SKILL.md +260 -0
- package/skills/loop-agent/references/README.md +63 -0
- package/skills/loop-agent/references/command-reference.md +315 -0
- package/skills/loop-agent/references/harness-policy.md +258 -0
- package/skills/loop-agent/references/hybrid-dag.md +216 -0
- package/skills/loop-agent/references/learned/README.md +21 -0
- package/skills/loop-agent/references/model-routing.md +36 -0
- package/skills/loop-agent/references/multi-worktree.md +54 -0
- package/skills/loop-agent/references/one-shot-runs.md +85 -0
- package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -0
- package/skills/loop-agent/references/pi-prompt.md +23 -0
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +83 -0
- package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -0
- package/skills/loop-agent/references/task-workflow.md +84 -0
- package/skills/loop-agent/references/verification-and-failure-handling.md +74 -0
- package/skills/requesting-code-review/SKILL.md +101 -0
- package/skills/requesting-code-review/code-reviewer.md +168 -0
- package/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/skills/systematic-debugging/SKILL.md +296 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +63 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/test-academic.md +14 -0
- package/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/skills/verification-before-completion/SKILL.md +154 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { assertDagPromptSourceRule } from "./prompt-source.js";
|
|
3
|
+
export const dagComplexitySchema = z.enum(["HIGH", "MED", "LOW"]);
|
|
4
|
+
export const dagNodeExecutorSchema = z.enum([
|
|
5
|
+
"cursor",
|
|
6
|
+
"pi",
|
|
7
|
+
"shell",
|
|
8
|
+
"static",
|
|
9
|
+
]);
|
|
10
|
+
export const dagToolProfileSchema = z.enum(["read-only", "write"]);
|
|
11
|
+
export const dagShellPresetSchema = z.enum(["loop-agent-standard-verify"]);
|
|
12
|
+
export const dagVerifyQuotaSchema = z.enum(["1", "3", "full"]);
|
|
13
|
+
export const dagVerifyStrategySchema = z
|
|
14
|
+
.object({
|
|
15
|
+
intermediateQuota: dagVerifyQuotaSchema.optional(),
|
|
16
|
+
finalQuota: z.literal("full").optional().default("full"),
|
|
17
|
+
focusedCommandSource: z
|
|
18
|
+
.literal("adapter")
|
|
19
|
+
.optional()
|
|
20
|
+
.default("adapter"),
|
|
21
|
+
})
|
|
22
|
+
.optional();
|
|
23
|
+
export const dagShellVerifyEvidenceSchema = z.object({
|
|
24
|
+
phase: z.enum(["intermediate", "final"]),
|
|
25
|
+
quota: dagVerifyQuotaSchema,
|
|
26
|
+
commandSource: z.enum(["adapter", "inline"]),
|
|
27
|
+
commandCount: z.number().int().nonnegative(),
|
|
28
|
+
commandLabels: z.array(z.string()).default([]),
|
|
29
|
+
finalFullRequired: z.boolean().optional(),
|
|
30
|
+
});
|
|
31
|
+
export const dagRepairArtifactGateSchema = z.object({
|
|
32
|
+
fromNodeId: z
|
|
33
|
+
.string()
|
|
34
|
+
.regex(/^[a-z][a-z0-9-]*$/, "fromNodeId must be kebab-case"),
|
|
35
|
+
});
|
|
36
|
+
export const dagVerdictGateSchema = z.object({
|
|
37
|
+
fromNodeId: z
|
|
38
|
+
.string()
|
|
39
|
+
.regex(/^[a-z][a-z0-9-]*$/, "fromNodeId must be kebab-case"),
|
|
40
|
+
accept: z.array(z.string().min(1)).min(1),
|
|
41
|
+
lineMode: z.enum(["first-non-empty", "first-verdict-line"]).optional(),
|
|
42
|
+
label: z.string().min(1).optional(),
|
|
43
|
+
});
|
|
44
|
+
export const ENV_VAR_NAME_PATTERN = /^[A-Z_][A-Z0-9_]*$/;
|
|
45
|
+
export const dagVersionSchema = z
|
|
46
|
+
.union([z.literal(1), z.literal(2)])
|
|
47
|
+
.default(1);
|
|
48
|
+
export const dagRoleSchema = z.enum([
|
|
49
|
+
"planner",
|
|
50
|
+
"scout",
|
|
51
|
+
"implementer",
|
|
52
|
+
"reviewer",
|
|
53
|
+
"supervisor",
|
|
54
|
+
"verifier",
|
|
55
|
+
"closeout",
|
|
56
|
+
]);
|
|
57
|
+
export const dagWritePolicySchema = z.enum([
|
|
58
|
+
"read-only",
|
|
59
|
+
"docs-only",
|
|
60
|
+
"exclusive",
|
|
61
|
+
"none",
|
|
62
|
+
]);
|
|
63
|
+
export const dagDefaultsSchema = z
|
|
64
|
+
.object({
|
|
65
|
+
executor: dagNodeExecutorSchema.optional(),
|
|
66
|
+
model: z.string().optional(),
|
|
67
|
+
piBackend: z.enum(["sdk-first", "cli-only"]).optional(),
|
|
68
|
+
contextProfile: z.string().optional(),
|
|
69
|
+
skills: z.array(z.string()).optional(),
|
|
70
|
+
writePolicy: dagWritePolicySchema.optional(),
|
|
71
|
+
})
|
|
72
|
+
.optional();
|
|
73
|
+
export const dagNodeStatusSchema = z.enum([
|
|
74
|
+
"PENDING",
|
|
75
|
+
"RUNNING",
|
|
76
|
+
"FINISHED",
|
|
77
|
+
"ERROR",
|
|
78
|
+
"SKIPPED",
|
|
79
|
+
]);
|
|
80
|
+
export const dagShellConfigSchema = z.object({
|
|
81
|
+
commands: z.array(z.string()).default([]),
|
|
82
|
+
preset: dagShellPresetSchema.optional(),
|
|
83
|
+
verdictGate: dagVerdictGateSchema.optional(),
|
|
84
|
+
verifyEvidence: dagShellVerifyEvidenceSchema.optional(),
|
|
85
|
+
repairArtifactGate: dagRepairArtifactGateSchema.optional(),
|
|
86
|
+
envAllowlist: z.array(z.string()).optional(),
|
|
87
|
+
timeoutMs: z.number().optional(),
|
|
88
|
+
cwd: z.string().optional(),
|
|
89
|
+
});
|
|
90
|
+
export const dagStaticConfigSchema = z.object({
|
|
91
|
+
resultMarkdown: z.string().min(1),
|
|
92
|
+
status: z.enum(["success", "error"]).optional(),
|
|
93
|
+
});
|
|
94
|
+
export const dagDynamicExpansionChildTaskSchema = z.object({
|
|
95
|
+
executor: dagNodeExecutorSchema.default("pi"),
|
|
96
|
+
role: dagRoleSchema.optional(),
|
|
97
|
+
complexity: dagComplexitySchema.default("LOW"),
|
|
98
|
+
subtaskPromptTemplate: z.string().min(1),
|
|
99
|
+
outputContract: z.string().optional(),
|
|
100
|
+
staticResultTemplate: z.string().optional(),
|
|
101
|
+
toolProfile: dagToolProfileSchema.optional(),
|
|
102
|
+
writePolicy: dagWritePolicySchema.optional(),
|
|
103
|
+
allowedPaths: z.array(z.string()).optional().default([]),
|
|
104
|
+
forbiddenPaths: z.array(z.string()).optional().default([]),
|
|
105
|
+
writeSet: z.array(z.string()).optional(),
|
|
106
|
+
});
|
|
107
|
+
export const dagDynamicExpansionSchema = z.object({
|
|
108
|
+
type: z.enum(["map_agent", "verify_agent"]),
|
|
109
|
+
workflowNodeId: z
|
|
110
|
+
.string()
|
|
111
|
+
.regex(/^[a-z][a-z0-9-]*$/, "workflowNodeId must be kebab-case"),
|
|
112
|
+
itemsFrom: z.string().min(1),
|
|
113
|
+
itemName: z.string().min(1).default("item"),
|
|
114
|
+
maxItems: z.number().int().positive(),
|
|
115
|
+
maxExpandedNodes: z.number().int().positive(),
|
|
116
|
+
workspaceTemplate: z.string().min(1).optional(),
|
|
117
|
+
childIdPrefix: z
|
|
118
|
+
.string()
|
|
119
|
+
.regex(/^[a-z][a-z0-9-]*$/, "childIdPrefix must be kebab-case"),
|
|
120
|
+
childTask: dagDynamicExpansionChildTaskSchema,
|
|
121
|
+
});
|
|
122
|
+
export const dagDynamicReductionSchema = z.object({
|
|
123
|
+
type: z.literal("verified_findings_report"),
|
|
124
|
+
workflowNodeId: z
|
|
125
|
+
.string()
|
|
126
|
+
.regex(/^[a-z][a-z0-9-]*$/, "workflowNodeId must be kebab-case"),
|
|
127
|
+
findingsFrom: z.string().min(1),
|
|
128
|
+
verificationsFrom: z.string().min(1),
|
|
129
|
+
refutedFindingsArtifactName: z
|
|
130
|
+
.string()
|
|
131
|
+
.min(1)
|
|
132
|
+
.default("refuted-findings.json"),
|
|
133
|
+
});
|
|
134
|
+
export const dagDynamicConditionSchema = z.object({
|
|
135
|
+
workflowNodeId: z
|
|
136
|
+
.string()
|
|
137
|
+
.regex(/^[a-z][a-z0-9-]*$/, "workflowNodeId must be kebab-case"),
|
|
138
|
+
cases: z.array(z.object({
|
|
139
|
+
when: z.string().min(1),
|
|
140
|
+
then: z
|
|
141
|
+
.string()
|
|
142
|
+
.regex(/^[a-z][a-z0-9-]*$/, "then must be a kebab-case task id"),
|
|
143
|
+
})),
|
|
144
|
+
default: z
|
|
145
|
+
.string()
|
|
146
|
+
.regex(/^[a-z][a-z0-9-]*$/, "default must be a kebab-case task id")
|
|
147
|
+
.optional(),
|
|
148
|
+
});
|
|
149
|
+
export const dagDynamicLoopBodyTaskSchema = z.object({
|
|
150
|
+
id: z
|
|
151
|
+
.string()
|
|
152
|
+
.regex(/^[a-z][a-z0-9-]*$/, "body task id must be kebab-case"),
|
|
153
|
+
dependsOn: z.array(z.string()).default([]),
|
|
154
|
+
executor: dagNodeExecutorSchema.default("pi"),
|
|
155
|
+
role: dagRoleSchema.optional(),
|
|
156
|
+
complexity: dagComplexitySchema.default("LOW"),
|
|
157
|
+
subtaskPromptTemplate: z.string().min(1),
|
|
158
|
+
outputContract: z.string().optional(),
|
|
159
|
+
staticResultTemplate: z.string().optional(),
|
|
160
|
+
toolProfile: dagToolProfileSchema.optional(),
|
|
161
|
+
writePolicy: dagWritePolicySchema.optional(),
|
|
162
|
+
allowedPaths: z.array(z.string()).optional().default([]),
|
|
163
|
+
forbiddenPaths: z.array(z.string()).optional().default([]),
|
|
164
|
+
writeSet: z.array(z.string()).optional(),
|
|
165
|
+
});
|
|
166
|
+
export const dagDynamicLoopUntilSchema = z.object({
|
|
167
|
+
workflowNodeId: z
|
|
168
|
+
.string()
|
|
169
|
+
.regex(/^[a-z][a-z0-9-]*$/, "workflowNodeId must be kebab-case"),
|
|
170
|
+
maxIterations: z.number().int().positive(),
|
|
171
|
+
stopWhenAny: z.array(z.string().min(1)).default([]),
|
|
172
|
+
bodyTasks: z.array(dagDynamicLoopBodyTaskSchema).min(1),
|
|
173
|
+
});
|
|
174
|
+
export const dagDecisionGateModeSchema = z.enum([
|
|
175
|
+
"record-only",
|
|
176
|
+
"pause-on-human",
|
|
177
|
+
]);
|
|
178
|
+
export const dagDecisionGateSchema = z.object({
|
|
179
|
+
enabled: z.boolean(),
|
|
180
|
+
schemaVersion: z.literal(1).optional(),
|
|
181
|
+
mode: dagDecisionGateModeSchema.optional().default("record-only"),
|
|
182
|
+
});
|
|
183
|
+
export const dagConvergenceSpecSchema = z
|
|
184
|
+
.object({
|
|
185
|
+
enabled: z.boolean().optional().default(false),
|
|
186
|
+
maxPasses: z.number().int().positive().optional().default(3),
|
|
187
|
+
stopOnVerdictPass: z.boolean().optional().default(true),
|
|
188
|
+
stopOnHardVerifyPass: z.boolean().optional().default(true),
|
|
189
|
+
pauseOnRegression: z.boolean().optional().default(true),
|
|
190
|
+
})
|
|
191
|
+
.optional();
|
|
192
|
+
export const dagTaskSchema = z.object({
|
|
193
|
+
id: z.string().regex(/^[a-z][a-z0-9-]*$/, "task id must be kebab-case"),
|
|
194
|
+
depends_on: z.array(z.string()).default([]),
|
|
195
|
+
complexity: dagComplexitySchema,
|
|
196
|
+
subtask_prompt: z.string().min(1),
|
|
197
|
+
subtask_prompt_source: z
|
|
198
|
+
.object({
|
|
199
|
+
type: z.literal("markdown"),
|
|
200
|
+
path: z.string().min(1),
|
|
201
|
+
sha256: z.string().min(1),
|
|
202
|
+
})
|
|
203
|
+
.optional(),
|
|
204
|
+
executor: dagNodeExecutorSchema.optional().default("pi"),
|
|
205
|
+
role: dagRoleSchema.optional(),
|
|
206
|
+
skills: z.array(z.string()).optional(),
|
|
207
|
+
toolProfile: dagToolProfileSchema.optional(),
|
|
208
|
+
writePolicy: dagWritePolicySchema.optional(),
|
|
209
|
+
writeSet: z.array(z.string()).optional(),
|
|
210
|
+
piStep: z.string().optional(),
|
|
211
|
+
shell: dagShellConfigSchema.optional(),
|
|
212
|
+
static: dagStaticConfigSchema.optional(),
|
|
213
|
+
outputContract: z.string().optional(),
|
|
214
|
+
allowedPaths: z.array(z.string()).optional().default([]),
|
|
215
|
+
forbiddenPaths: z.array(z.string()).optional().default([]),
|
|
216
|
+
decisionGate: dagDecisionGateSchema.optional(),
|
|
217
|
+
dynamicExpansion: dagDynamicExpansionSchema.optional(),
|
|
218
|
+
dynamicReduction: dagDynamicReductionSchema.optional(),
|
|
219
|
+
dynamicCondition: dagDynamicConditionSchema.optional(),
|
|
220
|
+
dynamicLoopUntil: dagDynamicLoopUntilSchema.optional(),
|
|
221
|
+
});
|
|
222
|
+
export const dagModelsSchema = z
|
|
223
|
+
.object({
|
|
224
|
+
HIGH: z.string().optional(),
|
|
225
|
+
MED: z.string().optional(),
|
|
226
|
+
LOW: z.string().optional(),
|
|
227
|
+
})
|
|
228
|
+
.partial();
|
|
229
|
+
export const dagExecutorModelsSchema = z
|
|
230
|
+
.object({
|
|
231
|
+
cursor: dagModelsSchema.optional(),
|
|
232
|
+
pi: dagModelsSchema.optional(),
|
|
233
|
+
})
|
|
234
|
+
.partial();
|
|
235
|
+
export const dagSpecSchema = z.object({
|
|
236
|
+
version: dagVersionSchema,
|
|
237
|
+
title: z.string().min(1),
|
|
238
|
+
objective: z.string().optional(),
|
|
239
|
+
successCriteria: z.array(z.string()).optional(),
|
|
240
|
+
globalConstraints: z.array(z.string()).optional(),
|
|
241
|
+
convergence: dagConvergenceSpecSchema,
|
|
242
|
+
verifyStrategy: dagVerifyStrategySchema,
|
|
243
|
+
defaults: dagDefaultsSchema,
|
|
244
|
+
skillsByRole: z.record(z.string(), z.array(z.string())).optional(),
|
|
245
|
+
executorModels: dagExecutorModelsSchema.optional(),
|
|
246
|
+
tasks: z.array(dagTaskSchema).min(1),
|
|
247
|
+
});
|
|
248
|
+
export const DEFAULT_DAG_EXECUTOR_MODELS = {
|
|
249
|
+
cursor: {
|
|
250
|
+
LOW: "composer-2.5",
|
|
251
|
+
MED: "composer-2.5",
|
|
252
|
+
HIGH: "composer-2.5",
|
|
253
|
+
},
|
|
254
|
+
pi: {
|
|
255
|
+
LOW: "gpt-5.3-codex-spark",
|
|
256
|
+
MED: "glm-5.2",
|
|
257
|
+
HIGH: "gpt-5.5",
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
export const DEFAULT_DAG_PI_MODELS = DEFAULT_DAG_EXECUTOR_MODELS.pi;
|
|
261
|
+
export const LEGACY_TOP_LEVEL_MODELS_ERROR = 'top-level "models" is no longer supported; use "executorModels"';
|
|
262
|
+
export function parseDagSpec(raw) {
|
|
263
|
+
assertDagPromptSourceRule(raw, { allowMarkdown: false });
|
|
264
|
+
if (typeof raw === "object" && raw !== null && "models" in raw) {
|
|
265
|
+
throw new Error(LEGACY_TOP_LEVEL_MODELS_ERROR);
|
|
266
|
+
}
|
|
267
|
+
return dagSpecSchema.parse(raw);
|
|
268
|
+
}
|
|
269
|
+
export function resolveModelForTask(task, executorModels) {
|
|
270
|
+
if (task.executor === "shell" || task.executor === "static") {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
return (executorModels?.[task.executor]?.[task.complexity] ??
|
|
274
|
+
DEFAULT_DAG_EXECUTOR_MODELS[task.executor][task.complexity]);
|
|
275
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { MAX_UPSTREAM_CHARS } from "./prompt.js";
|
|
5
|
+
import { rewritePathPrefix } from "../../shared/path-refs.js";
|
|
6
|
+
function sha256Text(text) {
|
|
7
|
+
return createHash("sha256").update(text).digest("hex");
|
|
8
|
+
}
|
|
9
|
+
export async function persistLongNodeOutputArtifacts(input) {
|
|
10
|
+
const previewChars = input.previewChars ?? MAX_UPSTREAM_CHARS;
|
|
11
|
+
const nodeRecordPath = path.join(input.runDir, `${input.nodeId}.json`);
|
|
12
|
+
const meta = { nodeRecordPath };
|
|
13
|
+
if (input.stdout && input.stdout.length > previewChars) {
|
|
14
|
+
const nodeDir = path.join(input.runDir, input.nodeId);
|
|
15
|
+
await mkdir(nodeDir, { recursive: true });
|
|
16
|
+
const stdoutPath = path.join(nodeDir, "stdout.md");
|
|
17
|
+
await writeFile(stdoutPath, input.stdout, "utf-8");
|
|
18
|
+
meta.stdoutArtifactPath = stdoutPath;
|
|
19
|
+
meta.stdoutChars = input.stdout.length;
|
|
20
|
+
meta.stdoutSha256 = sha256Text(input.stdout);
|
|
21
|
+
}
|
|
22
|
+
const assistant = input.assistantText;
|
|
23
|
+
if (assistant &&
|
|
24
|
+
assistant !== input.stdout &&
|
|
25
|
+
assistant.length > previewChars) {
|
|
26
|
+
const nodeDir = path.join(input.runDir, input.nodeId);
|
|
27
|
+
await mkdir(nodeDir, { recursive: true });
|
|
28
|
+
const assistantPath = path.join(nodeDir, "assistant.md");
|
|
29
|
+
await writeFile(assistantPath, assistant, "utf-8");
|
|
30
|
+
meta.assistantArtifactPath = assistantPath;
|
|
31
|
+
meta.assistantChars = assistant.length;
|
|
32
|
+
meta.assistantSha256 = sha256Text(assistant);
|
|
33
|
+
}
|
|
34
|
+
return meta;
|
|
35
|
+
}
|
|
36
|
+
export function relocateNodeArtifactPaths(node, oldRunDir, newRunDir) {
|
|
37
|
+
if (oldRunDir === newRunDir)
|
|
38
|
+
return;
|
|
39
|
+
const rewrite = (value) => {
|
|
40
|
+
if (!value)
|
|
41
|
+
return value;
|
|
42
|
+
const rewritten = rewritePathPrefix(value, oldRunDir, newRunDir);
|
|
43
|
+
if (rewritten !== value)
|
|
44
|
+
return rewritten;
|
|
45
|
+
if (value === oldRunDir || value.startsWith(`${oldRunDir}${path.sep}`)) {
|
|
46
|
+
return path.join(newRunDir, path.relative(oldRunDir, value));
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
node.stdoutArtifactPath = rewrite(node.stdoutArtifactPath);
|
|
51
|
+
node.assistantArtifactPath = rewrite(node.assistantArtifactPath);
|
|
52
|
+
node.nodeRecordPath = rewrite(node.nodeRecordPath);
|
|
53
|
+
}
|
|
54
|
+
export async function relocateRunArtifactPaths(input) {
|
|
55
|
+
const { runDir, oldRunDir, nodes } = input;
|
|
56
|
+
if (oldRunDir === runDir)
|
|
57
|
+
return;
|
|
58
|
+
for (const [nodeId, node] of Object.entries(nodes)) {
|
|
59
|
+
relocateNodeArtifactPaths(node, oldRunDir, runDir);
|
|
60
|
+
await writeFile(path.join(runDir, `${nodeId}.json`), `${JSON.stringify(node, null, 2)}\n`, "utf-8");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function formatStdoutPreview(stdout, maxChars) {
|
|
64
|
+
if (stdout.length <= maxChars) {
|
|
65
|
+
return { preview: stdout, truncated: false };
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
preview: `${stdout.slice(0, maxChars)}\n...[truncated]`,
|
|
69
|
+
truncated: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function formatUpstreamArtifactPointerMap(record, artifactKind = "stdout") {
|
|
73
|
+
const artifactPath = artifactKind === "assistant"
|
|
74
|
+
? record.assistantArtifactPath
|
|
75
|
+
: record.stdoutArtifactPath;
|
|
76
|
+
const chars = artifactKind === "assistant" ? record.assistantChars : record.stdoutChars;
|
|
77
|
+
const sha256 = artifactKind === "assistant" ? record.assistantSha256 : record.stdoutSha256;
|
|
78
|
+
const lines = [
|
|
79
|
+
"",
|
|
80
|
+
"Full output artifact (read-only runner evidence — use read tool to fetch; do not edit):",
|
|
81
|
+
];
|
|
82
|
+
if (artifactPath) {
|
|
83
|
+
lines.push(`- ${artifactKind}: ${artifactPath}`);
|
|
84
|
+
}
|
|
85
|
+
if (record.nodeRecordPath) {
|
|
86
|
+
lines.push(`- node record: ${record.nodeRecordPath}`);
|
|
87
|
+
}
|
|
88
|
+
if (chars !== undefined) {
|
|
89
|
+
lines.push(`- chars: ${chars}`);
|
|
90
|
+
}
|
|
91
|
+
if (sha256) {
|
|
92
|
+
lines.push(`- sha256: ${sha256}`);
|
|
93
|
+
}
|
|
94
|
+
return lines.join("\n");
|
|
95
|
+
}
|