@the-open-engine/zeroshot 5.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/CHANGELOG.md +539 -0
- package/LICENSE +21 -0
- package/README.md +508 -0
- package/cli/commands/inspect-render.js +135 -0
- package/cli/commands/inspect.js +294 -0
- package/cli/commands/providers.js +149 -0
- package/cli/index.js +5431 -0
- package/cli/lib/first-run.js +211 -0
- package/cli/lib/update-checker.js +281 -0
- package/cli/message-formatter-utils.js +75 -0
- package/cli/message-formatters-normal.js +275 -0
- package/cli/message-formatters-watch.js +185 -0
- package/cluster-templates/base-templates/debug-workflow.json +422 -0
- package/cluster-templates/base-templates/full-workflow.json +727 -0
- package/cluster-templates/base-templates/heavy-validation.json +272 -0
- package/cluster-templates/base-templates/quick-validation.json +285 -0
- package/cluster-templates/base-templates/single-worker.json +71 -0
- package/cluster-templates/base-templates/worker-validator.json +230 -0
- package/cluster-templates/conductor-bootstrap.json +130 -0
- package/docker/zeroshot-cluster/Dockerfile +153 -0
- package/docker/zeroshot-cluster/pre-baked-deps.json +28 -0
- package/lib/agent-cli-provider/adapters/claude-parser.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/claude-parser.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/claude-parser.js +122 -0
- package/lib/agent-cli-provider/adapters/claude-parser.js.map +1 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.d.ts +15 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.js +165 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.js.map +1 -0
- package/lib/agent-cli-provider/adapters/claude.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/claude.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/claude.js +181 -0
- package/lib/agent-cli-provider/adapters/claude.js.map +1 -0
- package/lib/agent-cli-provider/adapters/codex-parser.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/codex-parser.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/codex-parser.js +192 -0
- package/lib/agent-cli-provider/adapters/codex-parser.js.map +1 -0
- package/lib/agent-cli-provider/adapters/codex.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/codex.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/codex.js +151 -0
- package/lib/agent-cli-provider/adapters/codex.js.map +1 -0
- package/lib/agent-cli-provider/adapters/common.d.ts +28 -0
- package/lib/agent-cli-provider/adapters/common.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/common.js +71 -0
- package/lib/agent-cli-provider/adapters/common.js.map +1 -0
- package/lib/agent-cli-provider/adapters/gemini.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/gemini.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/gemini.js +176 -0
- package/lib/agent-cli-provider/adapters/gemini.js.map +1 -0
- package/lib/agent-cli-provider/adapters/index.d.ts +9 -0
- package/lib/agent-cli-provider/adapters/index.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/index.js +95 -0
- package/lib/agent-cli-provider/adapters/index.js.map +1 -0
- package/lib/agent-cli-provider/adapters/opencode.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/opencode.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/opencode.js +228 -0
- package/lib/agent-cli-provider/adapters/opencode.js.map +1 -0
- package/lib/agent-cli-provider/contract-actions.d.ts +5 -0
- package/lib/agent-cli-provider/contract-actions.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-actions.js +140 -0
- package/lib/agent-cli-provider/contract-actions.js.map +1 -0
- package/lib/agent-cli-provider/contract-env.d.ts +11 -0
- package/lib/agent-cli-provider/contract-env.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-env.js +113 -0
- package/lib/agent-cli-provider/contract-env.js.map +1 -0
- package/lib/agent-cli-provider/contract-envelope.d.ts +49 -0
- package/lib/agent-cli-provider/contract-envelope.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-envelope.js +52 -0
- package/lib/agent-cli-provider/contract-envelope.js.map +1 -0
- package/lib/agent-cli-provider/contract-errors.d.ts +22 -0
- package/lib/agent-cli-provider/contract-errors.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-errors.js +71 -0
- package/lib/agent-cli-provider/contract-errors.js.map +1 -0
- package/lib/agent-cli-provider/contract-fallback.d.ts +7 -0
- package/lib/agent-cli-provider/contract-fallback.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-fallback.js +102 -0
- package/lib/agent-cli-provider/contract-fallback.js.map +1 -0
- package/lib/agent-cli-provider/contract-invoke.d.ts +5 -0
- package/lib/agent-cli-provider/contract-invoke.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-invoke.js +89 -0
- package/lib/agent-cli-provider/contract-invoke.js.map +1 -0
- package/lib/agent-cli-provider/contract-options.d.ts +3 -0
- package/lib/agent-cli-provider/contract-options.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-options.js +140 -0
- package/lib/agent-cli-provider/contract-options.js.map +1 -0
- package/lib/agent-cli-provider/contract-parse.d.ts +15 -0
- package/lib/agent-cli-provider/contract-parse.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-parse.js +81 -0
- package/lib/agent-cli-provider/contract-parse.js.map +1 -0
- package/lib/agent-cli-provider/contract-support.d.ts +18 -0
- package/lib/agent-cli-provider/contract-support.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-support.js +154 -0
- package/lib/agent-cli-provider/contract-support.js.map +1 -0
- package/lib/agent-cli-provider/contract.d.ts +13 -0
- package/lib/agent-cli-provider/contract.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract.js +30 -0
- package/lib/agent-cli-provider/contract.js.map +1 -0
- package/lib/agent-cli-provider/env-safety.d.ts +11 -0
- package/lib/agent-cli-provider/env-safety.d.ts.map +1 -0
- package/lib/agent-cli-provider/env-safety.js +83 -0
- package/lib/agent-cli-provider/env-safety.js.map +1 -0
- package/lib/agent-cli-provider/errors.d.ts +5 -0
- package/lib/agent-cli-provider/errors.d.ts.map +1 -0
- package/lib/agent-cli-provider/errors.js +115 -0
- package/lib/agent-cli-provider/errors.js.map +1 -0
- package/lib/agent-cli-provider/executable.d.ts +3 -0
- package/lib/agent-cli-provider/executable.d.ts.map +1 -0
- package/lib/agent-cli-provider/executable.js +24 -0
- package/lib/agent-cli-provider/executable.js.map +1 -0
- package/lib/agent-cli-provider/index.d.ts +8 -0
- package/lib/agent-cli-provider/index.d.ts.map +1 -0
- package/lib/agent-cli-provider/index.js +31 -0
- package/lib/agent-cli-provider/index.js.map +1 -0
- package/lib/agent-cli-provider/invoke-evidence.d.ts +4 -0
- package/lib/agent-cli-provider/invoke-evidence.d.ts.map +1 -0
- package/lib/agent-cli-provider/invoke-evidence.js +17 -0
- package/lib/agent-cli-provider/invoke-evidence.js.map +1 -0
- package/lib/agent-cli-provider/json.d.ts +16 -0
- package/lib/agent-cli-provider/json.d.ts.map +1 -0
- package/lib/agent-cli-provider/json.js +110 -0
- package/lib/agent-cli-provider/json.js.map +1 -0
- package/lib/agent-cli-provider/log-prefix.d.ts +2 -0
- package/lib/agent-cli-provider/log-prefix.d.ts.map +1 -0
- package/lib/agent-cli-provider/log-prefix.js +22 -0
- package/lib/agent-cli-provider/log-prefix.js.map +1 -0
- package/lib/agent-cli-provider/process-runner.d.ts +17 -0
- package/lib/agent-cli-provider/process-runner.d.ts.map +1 -0
- package/lib/agent-cli-provider/process-runner.js +89 -0
- package/lib/agent-cli-provider/process-runner.js.map +1 -0
- package/lib/agent-cli-provider/redaction.d.ts +9 -0
- package/lib/agent-cli-provider/redaction.d.ts.map +1 -0
- package/lib/agent-cli-provider/redaction.js +227 -0
- package/lib/agent-cli-provider/redaction.js.map +1 -0
- package/lib/agent-cli-provider/schema.d.ts +5 -0
- package/lib/agent-cli-provider/schema.d.ts.map +1 -0
- package/lib/agent-cli-provider/schema.js +136 -0
- package/lib/agent-cli-provider/schema.js.map +1 -0
- package/lib/agent-cli-provider/single-agent-runtime.d.ts +15 -0
- package/lib/agent-cli-provider/single-agent-runtime.d.ts.map +1 -0
- package/lib/agent-cli-provider/single-agent-runtime.js +228 -0
- package/lib/agent-cli-provider/single-agent-runtime.js.map +1 -0
- package/lib/agent-cli-provider/types.d.ts +194 -0
- package/lib/agent-cli-provider/types.d.ts.map +1 -0
- package/lib/agent-cli-provider/types.js +12 -0
- package/lib/agent-cli-provider/types.js.map +1 -0
- package/lib/completion.js +174 -0
- package/lib/detached-startup.js +220 -0
- package/lib/docker-config.js +220 -0
- package/lib/git-remote-utils.js +165 -0
- package/lib/id-detector.js +55 -0
- package/lib/provider-defaults.js +62 -0
- package/lib/provider-detection.js +59 -0
- package/lib/provider-names.js +57 -0
- package/lib/repo-settings.js +69 -0
- package/lib/settings/claude-auth.js +78 -0
- package/lib/settings.js +542 -0
- package/lib/start-cluster.js +321 -0
- package/lib/stream-json-parser.js +67 -0
- package/package.json +162 -0
- package/scripts/fix-node-pty-permissions.js +75 -0
- package/scripts/record-demo.sh +279 -0
- package/scripts/setup-merge-queue.sh +170 -0
- package/scripts/test-install.sh +40 -0
- package/scripts/validate-templates.js +107 -0
- package/src/agent/agent-config.js +266 -0
- package/src/agent/agent-context-builder.js +189 -0
- package/src/agent/agent-context-sections.js +338 -0
- package/src/agent/agent-context-sources.js +147 -0
- package/src/agent/agent-hook-executor.js +721 -0
- package/src/agent/agent-input-injector.js +141 -0
- package/src/agent/agent-lifecycle.js +982 -0
- package/src/agent/agent-quality-gate-schema.js +93 -0
- package/src/agent/agent-quality-gates-context.js +51 -0
- package/src/agent/agent-stuck-detector.js +256 -0
- package/src/agent/agent-task-executor.js +2028 -0
- package/src/agent/agent-trigger-evaluator.js +67 -0
- package/src/agent/context-metrics.js +160 -0
- package/src/agent/context-pack-builder.js +367 -0
- package/src/agent/context-replay-policy.js +51 -0
- package/src/agent/guidance-queue.js +77 -0
- package/src/agent/output-extraction.js +367 -0
- package/src/agent/output-reformatter.js +175 -0
- package/src/agent/pr-verification.js +653 -0
- package/src/agent/rate-limit-backoff.js +82 -0
- package/src/agent/schema-utils.js +146 -0
- package/src/agent/validation-platform.js +35 -0
- package/src/agent-cli-provider/adapters/claude-parser.ts +133 -0
- package/src/agent-cli-provider/adapters/claude-recovery.ts +203 -0
- package/src/agent-cli-provider/adapters/claude.ts +247 -0
- package/src/agent-cli-provider/adapters/codex-parser.ts +211 -0
- package/src/agent-cli-provider/adapters/codex.ts +217 -0
- package/src/agent-cli-provider/adapters/common.ts +124 -0
- package/src/agent-cli-provider/adapters/gemini.ts +243 -0
- package/src/agent-cli-provider/adapters/index.ts +126 -0
- package/src/agent-cli-provider/adapters/opencode.ts +286 -0
- package/src/agent-cli-provider/contract-actions.ts +150 -0
- package/src/agent-cli-provider/contract-env.ts +111 -0
- package/src/agent-cli-provider/contract-envelope.ts +110 -0
- package/src/agent-cli-provider/contract-errors.ts +66 -0
- package/src/agent-cli-provider/contract-fallback.ts +121 -0
- package/src/agent-cli-provider/contract-invoke.ts +104 -0
- package/src/agent-cli-provider/contract-options.ts +173 -0
- package/src/agent-cli-provider/contract-parse.ts +94 -0
- package/src/agent-cli-provider/contract-support.ts +167 -0
- package/src/agent-cli-provider/contract.ts +56 -0
- package/src/agent-cli-provider/env-safety.ts +82 -0
- package/src/agent-cli-provider/errors.ts +122 -0
- package/src/agent-cli-provider/executable.ts +24 -0
- package/src/agent-cli-provider/index.ts +83 -0
- package/src/agent-cli-provider/invoke-evidence.ts +18 -0
- package/src/agent-cli-provider/json.ts +114 -0
- package/src/agent-cli-provider/log-prefix.ts +20 -0
- package/src/agent-cli-provider/process-runner.ts +145 -0
- package/src/agent-cli-provider/redaction.ts +282 -0
- package/src/agent-cli-provider/schema.ts +115 -0
- package/src/agent-cli-provider/single-agent-runtime.ts +311 -0
- package/src/agent-cli-provider/types.ts +237 -0
- package/src/agent-wrapper.js +615 -0
- package/src/agents/git-pusher-template.js +705 -0
- package/src/attach/attach-client.js +438 -0
- package/src/attach/attach-server.js +543 -0
- package/src/attach/index.js +37 -0
- package/src/attach/protocol.js +220 -0
- package/src/attach/ring-buffer.js +121 -0
- package/src/attach/send-input.js +88 -0
- package/src/attach/socket-discovery.js +267 -0
- package/src/claude-task-runner.js +661 -0
- package/src/config-router.js +89 -0
- package/src/config-validator.js +2202 -0
- package/src/copy-worker.js +43 -0
- package/src/guidance-topics.js +10 -0
- package/src/input-helpers.js +65 -0
- package/src/isolation-manager.js +1734 -0
- package/src/issue-providers/README.md +305 -0
- package/src/issue-providers/azure-devops-provider.js +307 -0
- package/src/issue-providers/base-provider.js +232 -0
- package/src/issue-providers/github-provider.js +210 -0
- package/src/issue-providers/gitlab-provider.js +262 -0
- package/src/issue-providers/index.js +196 -0
- package/src/issue-providers/jira-provider.js +260 -0
- package/src/ledger.js +692 -0
- package/src/lib/gc.js +232 -0
- package/src/lib/safe-exec.js +88 -0
- package/src/logic-engine.js +201 -0
- package/src/message-buffer.js +81 -0
- package/src/message-bus-bridge.js +144 -0
- package/src/message-bus.js +256 -0
- package/src/name-generator.js +232 -0
- package/src/orchestrator.js +3924 -0
- package/src/preflight.js +712 -0
- package/src/process-metrics.js +608 -0
- package/src/providers/anthropic/index.js +3 -0
- package/src/providers/base-provider.js +355 -0
- package/src/providers/capabilities.js +60 -0
- package/src/providers/google/index.js +3 -0
- package/src/providers/index.js +293 -0
- package/src/providers/openai/index.js +3 -0
- package/src/providers/opencode/index.js +3 -0
- package/src/quality-gates.js +143 -0
- package/src/schemas/sub-cluster.js +208 -0
- package/src/state-snapshot.js +398 -0
- package/src/state-snapshotter.js +142 -0
- package/src/status-footer.js +1026 -0
- package/src/sub-cluster-wrapper.js +693 -0
- package/src/task-runner.js +30 -0
- package/src/template-resolver.js +425 -0
- package/src/template-validation/index.js +338 -0
- package/src/template-validation/simulate-consensus-gates.js +324 -0
- package/src/template-validation/simulate-random-topology.js +541 -0
- package/src/template-validation/simulate-two-stage-validation.js +270 -0
- package/src/worktree-claude-config.js +135 -0
- package/src/worktree-tooling-env.js +150 -0
- package/task-lib/attachable-watcher.js +381 -0
- package/task-lib/commands/clean.js +50 -0
- package/task-lib/commands/episodes.js +105 -0
- package/task-lib/commands/get-log-path.js +23 -0
- package/task-lib/commands/kill.js +32 -0
- package/task-lib/commands/list.js +105 -0
- package/task-lib/commands/logs.js +439 -0
- package/task-lib/commands/resume.js +42 -0
- package/task-lib/commands/run.js +57 -0
- package/task-lib/commands/schedule.js +105 -0
- package/task-lib/commands/scheduler-cmd.js +96 -0
- package/task-lib/commands/schedules.js +148 -0
- package/task-lib/commands/status.js +44 -0
- package/task-lib/commands/unschedule.js +16 -0
- package/task-lib/completion.js +9 -0
- package/task-lib/config.js +11 -0
- package/task-lib/name-generator.js +230 -0
- package/task-lib/package.json +3 -0
- package/task-lib/provider-helper-runtime.js +29 -0
- package/task-lib/runner.js +190 -0
- package/task-lib/scheduler.js +252 -0
- package/task-lib/store.js +529 -0
- package/task-lib/watcher.js +305 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
const { readFileSync } = require('fs');
|
|
2
|
+
const { join, resolve } = require('path');
|
|
3
|
+
|
|
4
|
+
const { isPlatformMismatchReason } = require('./validation-platform');
|
|
5
|
+
|
|
6
|
+
const EXAMPLE_PRIMITIVE_VALUES = {
|
|
7
|
+
boolean: true,
|
|
8
|
+
number: 0,
|
|
9
|
+
integer: 0,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function generateExampleValue(propSchema, key) {
|
|
13
|
+
if (!propSchema) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (Array.isArray(propSchema.enum) && propSchema.enum.length > 0) {
|
|
18
|
+
return propSchema.enum[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (propSchema.type === 'string') {
|
|
22
|
+
return propSchema.description || `${key} value`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (propSchema.type === 'array') {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (propSchema.type === 'object') {
|
|
30
|
+
return generateExampleFromSchema(propSchema) || {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return EXAMPLE_PRIMITIVE_VALUES[propSchema.type];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function generateExampleFromSchema(schema) {
|
|
37
|
+
if (!schema || schema.type !== 'object' || !schema.properties) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const example = {};
|
|
42
|
+
|
|
43
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
44
|
+
const value = generateExampleValue(propSchema, key);
|
|
45
|
+
if (value !== undefined) {
|
|
46
|
+
example[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return example;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildAutonomousSection() {
|
|
54
|
+
return [
|
|
55
|
+
'## 🔴 CRITICAL: AUTONOMOUS EXECUTION REQUIRED',
|
|
56
|
+
'',
|
|
57
|
+
'You are running in a NON-INTERACTIVE cluster environment.',
|
|
58
|
+
'',
|
|
59
|
+
'**NEVER** use AskUserQuestion or ask for user input - there is NO user to respond.',
|
|
60
|
+
'**NEVER** ask "Would you like me to..." or "Should I..." - JUST DO IT.',
|
|
61
|
+
'**NEVER** wait for approval or confirmation - MAKE DECISIONS AUTONOMOUSLY.',
|
|
62
|
+
'',
|
|
63
|
+
'When facing choices:',
|
|
64
|
+
'- Choose the option that maintains code quality and correctness',
|
|
65
|
+
'- If unsure between "fix the code" vs "relax the rules" → ALWAYS fix the code',
|
|
66
|
+
'- If unsure between "do more" vs "do less" → ALWAYS do what\'s required, nothing more',
|
|
67
|
+
'',
|
|
68
|
+
].join('\n');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function buildOutputStyleSection() {
|
|
72
|
+
return [
|
|
73
|
+
'## 🔴 OUTPUT STYLE - NON-NEGOTIABLE',
|
|
74
|
+
'',
|
|
75
|
+
'**ALL OUTPUT: Maximum informativeness, minimum verbosity. NO EXCEPTIONS.**',
|
|
76
|
+
'',
|
|
77
|
+
'This applies to EVERYTHING you output:',
|
|
78
|
+
'- Text responses',
|
|
79
|
+
'- JSON schema values',
|
|
80
|
+
'- Reasoning fields',
|
|
81
|
+
'- Summary fields',
|
|
82
|
+
'- ALL string values in structured output',
|
|
83
|
+
'',
|
|
84
|
+
'Rules:',
|
|
85
|
+
'- Progress: "Reading auth.ts" NOT "I will now read the auth.ts file..."',
|
|
86
|
+
'- Tool calls: NO preamble. Call immediately.',
|
|
87
|
+
'- Schema strings: Dense facts. No filler. No fluff.',
|
|
88
|
+
'- Errors: DETAILED (stack traces, repro). NEVER compress errors.',
|
|
89
|
+
'- FORBIDDEN: "I\'ll help...", "Let me...", "I\'m going to...", "Sure!", "Great!", "Certainly!"',
|
|
90
|
+
'',
|
|
91
|
+
'Every token costs money. Waste nothing.',
|
|
92
|
+
'',
|
|
93
|
+
].join('\n');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildGitOperationsSection() {
|
|
97
|
+
return [
|
|
98
|
+
'## 🚫 GIT OPERATIONS - FORBIDDEN',
|
|
99
|
+
'',
|
|
100
|
+
'NEVER commit, push, or create PRs. You only modify files.',
|
|
101
|
+
'The git-pusher agent handles ALL git operations AFTER validators approve.',
|
|
102
|
+
'',
|
|
103
|
+
'- ❌ NEVER run: git add, git commit, git push, gh pr create',
|
|
104
|
+
'- ❌ NEVER suggest committing changes',
|
|
105
|
+
'- ✅ Only modify files and publish your completion message when done',
|
|
106
|
+
'',
|
|
107
|
+
].join('\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildHeaderContext({ id, role, iteration, isIsolated }) {
|
|
111
|
+
return [
|
|
112
|
+
`You are agent "${id}" with role "${role}".`,
|
|
113
|
+
'',
|
|
114
|
+
`Iteration: ${iteration}`,
|
|
115
|
+
'',
|
|
116
|
+
buildAutonomousSection(),
|
|
117
|
+
buildOutputStyleSection(),
|
|
118
|
+
isIsolated ? '' : buildGitOperationsSection(),
|
|
119
|
+
]
|
|
120
|
+
.filter(Boolean)
|
|
121
|
+
.join('\n');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function buildInstructionsSection({ config, selectedPrompt, id }) {
|
|
125
|
+
const promptText =
|
|
126
|
+
selectedPrompt || (typeof config.prompt === 'string' ? config.prompt : config.prompt?.system);
|
|
127
|
+
|
|
128
|
+
if (promptText) {
|
|
129
|
+
return `## Instructions\n\n${promptText}\n\n`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (config.prompt && typeof config.prompt !== 'string' && !config.prompt?.system) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Agent "${id}" has invalid prompt format. ` +
|
|
135
|
+
`Expected string or object with .system property, got: ${JSON.stringify(config.prompt).slice(0, 100)}...`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function hasIgnoredRepoToolingError(error) {
|
|
143
|
+
return (
|
|
144
|
+
typeof error === 'object' &&
|
|
145
|
+
error !== null &&
|
|
146
|
+
'code' in error &&
|
|
147
|
+
['ENOENT', 'ENOTDIR', 'EACCES', 'EPERM'].includes(error.code)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function resolveRepoToolingRoots({ config, worktree }) {
|
|
152
|
+
return Array.from(
|
|
153
|
+
new Set(
|
|
154
|
+
[worktree?.path, config?.cwd, process.cwd()]
|
|
155
|
+
.filter((value) => typeof value === 'string' && value.trim() !== '')
|
|
156
|
+
.map((value) => resolve(value))
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function buildRepoToolingSection({ config, worktree }) {
|
|
162
|
+
for (const root of resolveRepoToolingRoots({ config, worktree })) {
|
|
163
|
+
const skillPath = join(root, '.claude', 'skills', 'repo-tooling', 'SKILL.md');
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const content = readFileSync(skillPath, 'utf8').trim();
|
|
167
|
+
if (content !== '') {
|
|
168
|
+
return `${content}\n\n`;
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (!hasIgnoredRepoToolingError(error)) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function buildLegacyOutputSchemaSection(config) {
|
|
181
|
+
if (!config.prompt?.outputFormat) {
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const rules = (config.prompt.outputFormat.rules || []).map((rule) => `- ${rule}`).join('\n');
|
|
186
|
+
|
|
187
|
+
return [
|
|
188
|
+
'## Output Schema (REQUIRED)',
|
|
189
|
+
'',
|
|
190
|
+
'```json',
|
|
191
|
+
JSON.stringify(config.prompt.outputFormat.example, null, 2),
|
|
192
|
+
'```',
|
|
193
|
+
'',
|
|
194
|
+
'STRING VALUES IN THIS SCHEMA: Dense. Factual. No filler words. No pleasantries.',
|
|
195
|
+
rules,
|
|
196
|
+
'',
|
|
197
|
+
]
|
|
198
|
+
.filter(Boolean)
|
|
199
|
+
.join('\n');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function buildJsonSchemaSection(config) {
|
|
203
|
+
if (!config.jsonSchema || config.outputFormat !== 'json') {
|
|
204
|
+
return '';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const lines = [
|
|
208
|
+
'## 🔴 OUTPUT FORMAT - JSON ONLY',
|
|
209
|
+
'',
|
|
210
|
+
'Your response must be ONLY valid JSON. No other text before or after.',
|
|
211
|
+
'Start with { and end with }. Nothing else.',
|
|
212
|
+
'',
|
|
213
|
+
'Required schema:',
|
|
214
|
+
'```json',
|
|
215
|
+
JSON.stringify(config.jsonSchema, null, 2),
|
|
216
|
+
'```',
|
|
217
|
+
'',
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
const example = generateExampleFromSchema(config.jsonSchema);
|
|
221
|
+
if (example) {
|
|
222
|
+
lines.push('Example output:', '```json', JSON.stringify(example, null, 2), '```', '');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
lines.push(
|
|
226
|
+
'CRITICAL RULES:',
|
|
227
|
+
'- Output ONLY the JSON object - no explanation, no thinking, no preamble',
|
|
228
|
+
'- Use EXACTLY the enum values specified (case-sensitive)',
|
|
229
|
+
'- Include ALL required fields',
|
|
230
|
+
''
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
return lines.join('\n');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function shouldKeepCannotValidate(criteria, ignoreReason, seenIds) {
|
|
237
|
+
if (criteria.status !== 'CANNOT_VALIDATE' || !criteria.id) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (ignoreReason && ignoreReason(criteria.reason)) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (seenIds.has(criteria.id)) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function collectCannotValidateCriteria(prevValidations, options = {}) {
|
|
253
|
+
const cannotValidateCriteria = [];
|
|
254
|
+
const seenIds = new Set();
|
|
255
|
+
const ignoreReason = options.ignoreReason;
|
|
256
|
+
|
|
257
|
+
for (const msg of prevValidations) {
|
|
258
|
+
const criteriaResults = msg.content?.data?.criteriaResults;
|
|
259
|
+
if (!Array.isArray(criteriaResults)) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
for (const criteria of criteriaResults) {
|
|
264
|
+
if (!shouldKeepCannotValidate(criteria, ignoreReason, seenIds)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
seenIds.add(criteria.id);
|
|
269
|
+
cannotValidateCriteria.push({
|
|
270
|
+
id: criteria.id,
|
|
271
|
+
reason: criteria.reason || 'No reason provided',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return cannotValidateCriteria;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function buildCannotValidateSection(cannotValidateCriteria) {
|
|
280
|
+
if (cannotValidateCriteria.length === 0) {
|
|
281
|
+
return '';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return [
|
|
285
|
+
'',
|
|
286
|
+
'## ⚠️ Permanently Unverifiable Criteria (SKIP THESE)',
|
|
287
|
+
'',
|
|
288
|
+
'The following criteria have PERMANENT environmental limitations (missing tools, no access).',
|
|
289
|
+
'These limitations have not changed. Do NOT re-attempt verification.',
|
|
290
|
+
'Mark these as CANNOT_VALIDATE again with the same reason.',
|
|
291
|
+
'',
|
|
292
|
+
...cannotValidateCriteria.map((criteria) => `- **${criteria.id}**: ${criteria.reason}`),
|
|
293
|
+
'',
|
|
294
|
+
].join('\n');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function buildValidatorSkipSection({ role, messageBus, cluster, isolation }) {
|
|
298
|
+
if (role !== 'validator') {
|
|
299
|
+
return '';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const prevValidations = messageBus.query({
|
|
303
|
+
cluster_id: cluster.id,
|
|
304
|
+
topic: 'VALIDATION_RESULT',
|
|
305
|
+
since: cluster.createdAt,
|
|
306
|
+
limit: 50,
|
|
307
|
+
});
|
|
308
|
+
const ignoreReason = isolation?.enabled ? isPlatformMismatchReason : null;
|
|
309
|
+
const cannotValidateCriteria = collectCannotValidateCriteria(prevValidations, { ignoreReason });
|
|
310
|
+
|
|
311
|
+
return buildCannotValidateSection(cannotValidateCriteria);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function buildTriggeringMessageSection(triggeringMessage) {
|
|
315
|
+
const lines = [
|
|
316
|
+
'',
|
|
317
|
+
'## Triggering Message',
|
|
318
|
+
'',
|
|
319
|
+
`Topic: ${triggeringMessage.topic}`,
|
|
320
|
+
`Sender: ${triggeringMessage.sender}`,
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
if (triggeringMessage.content?.text) {
|
|
324
|
+
lines.push('', triggeringMessage.content.text);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return `${lines.join('\n')}\n`;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
module.exports = {
|
|
331
|
+
buildHeaderContext,
|
|
332
|
+
buildInstructionsSection,
|
|
333
|
+
buildJsonSchemaSection,
|
|
334
|
+
buildLegacyOutputSchemaSection,
|
|
335
|
+
buildRepoToolingSection,
|
|
336
|
+
buildTriggeringMessageSection,
|
|
337
|
+
buildValidatorSkipSection,
|
|
338
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const { isReplayableMessage } = require('./context-replay-policy');
|
|
2
|
+
|
|
3
|
+
function resolveSourceSince(source, cluster, lastTaskEndTime, lastAgentStartTime) {
|
|
4
|
+
const sinceValue = source.since;
|
|
5
|
+
|
|
6
|
+
if (sinceValue === 'cluster_start') {
|
|
7
|
+
return cluster.createdAt;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (sinceValue === 'last_task_end') {
|
|
11
|
+
return lastTaskEndTime || cluster.createdAt;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (sinceValue === 'last_agent_start') {
|
|
15
|
+
return lastAgentStartTime ? lastAgentStartTime + 1 : cluster.createdAt;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof sinceValue === 'string') {
|
|
19
|
+
const parsed = Date.parse(sinceValue);
|
|
20
|
+
if (Number.isNaN(parsed)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Unknown context source "since" value "${sinceValue}" for topic ${source.topic}. ` +
|
|
23
|
+
'Use cluster_start, last_task_end, last_agent_start, or an ISO timestamp.'
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return parsed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return sinceValue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function formatSourceMessagesSection(source, messages) {
|
|
33
|
+
let context = `\n## Messages from topic: ${source.topic}\n\n`;
|
|
34
|
+
|
|
35
|
+
for (const msg of messages) {
|
|
36
|
+
context += `[${new Date(msg.timestamp).toISOString()}] ${msg.sender}:\n`;
|
|
37
|
+
if (msg.content?.text) {
|
|
38
|
+
context += `${msg.content.text}\n`;
|
|
39
|
+
}
|
|
40
|
+
if (msg.content?.data) {
|
|
41
|
+
context += `Data: ${JSON.stringify(msg.content.data, null, 2)}\n`;
|
|
42
|
+
}
|
|
43
|
+
context += '\n';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return context;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function resolveSourceSelection(source, { compact = false } = {}) {
|
|
50
|
+
const baseAmount = source.amount ?? source.limit;
|
|
51
|
+
const baseStrategy = source.strategy ?? (baseAmount !== undefined ? 'latest' : 'all');
|
|
52
|
+
|
|
53
|
+
if (!compact) {
|
|
54
|
+
return { amount: baseAmount, strategy: baseStrategy };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
amount: source.compactAmount ?? 1,
|
|
59
|
+
strategy: source.compactStrategy ?? (baseStrategy === 'all' ? 'latest' : baseStrategy),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function resolveSourceMessages({
|
|
64
|
+
source,
|
|
65
|
+
messageBus,
|
|
66
|
+
cluster,
|
|
67
|
+
lastTaskEndTime,
|
|
68
|
+
lastAgentStartTime,
|
|
69
|
+
compact = false,
|
|
70
|
+
}) {
|
|
71
|
+
const sinceTimestamp = resolveSourceSince(source, cluster, lastTaskEndTime, lastAgentStartTime);
|
|
72
|
+
const { amount, strategy } = resolveSourceSelection(source, { compact });
|
|
73
|
+
const messages = messageBus.query({
|
|
74
|
+
cluster_id: cluster.id,
|
|
75
|
+
topic: source.topic,
|
|
76
|
+
sender: source.sender,
|
|
77
|
+
since: sinceTimestamp,
|
|
78
|
+
});
|
|
79
|
+
const replayableMessages = messages.filter(isReplayableMessage);
|
|
80
|
+
|
|
81
|
+
if (amount === undefined) {
|
|
82
|
+
return replayableMessages;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (strategy === 'latest') {
|
|
86
|
+
return replayableMessages.slice(-amount);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return replayableMessages.slice(0, amount);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const REQUIRED_TOPICS = new Set(['STATE_SNAPSHOT', 'ISSUE_OPENED', 'PLAN_READY']);
|
|
93
|
+
const HIGH_PRIORITY_TOPICS = new Set(['VALIDATION_RESULT', 'IMPLEMENTATION_READY']);
|
|
94
|
+
|
|
95
|
+
function resolveSourcePriority(source) {
|
|
96
|
+
if (source.priority) {
|
|
97
|
+
return source.priority;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (REQUIRED_TOPICS.has(source.topic)) {
|
|
101
|
+
return 'required';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (HIGH_PRIORITY_TOPICS.has(source.topic)) {
|
|
105
|
+
return 'high';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return 'medium';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildSourcePack({
|
|
112
|
+
source,
|
|
113
|
+
index,
|
|
114
|
+
messageBus,
|
|
115
|
+
cluster,
|
|
116
|
+
lastTaskEndTime,
|
|
117
|
+
lastAgentStartTime,
|
|
118
|
+
}) {
|
|
119
|
+
const render = (compact) => {
|
|
120
|
+
const messages = resolveSourceMessages({
|
|
121
|
+
source,
|
|
122
|
+
messageBus,
|
|
123
|
+
cluster,
|
|
124
|
+
lastTaskEndTime,
|
|
125
|
+
lastAgentStartTime,
|
|
126
|
+
compact,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (messages.length === 0) {
|
|
130
|
+
return '';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return formatSourceMessagesSection(source, messages);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
id: `source:${source.topic}:${index}`,
|
|
138
|
+
section: 'sources',
|
|
139
|
+
priority: resolveSourcePriority(source),
|
|
140
|
+
render: () => render(false),
|
|
141
|
+
compact: () => render(true),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = {
|
|
146
|
+
buildSourcePack,
|
|
147
|
+
};
|