harness-everything 0.57.3 → 0.58.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.releaserc.json +2 -0
- package/CHANGELOG.md +15 -0
- package/benchmarks/results/live-host/agy-2026-11-22/README.md +49 -0
- package/benchmarks/results/live-host/agy-2026-11-23/README.md +48 -0
- package/ci/action-gate.test.js +162 -0
- package/ci/doc-capability-consistency.test.js +11 -1
- package/ci/mechanism-2aa-codex-action-gate-policy.test.js +37 -0
- package/ci/mechanism-2ao-plugin-sync.test.js +235 -2
- package/ci/mechanism-2w-platform-compatibility.test.js +13 -2
- package/ci/mechanism-2x-release-automation.test.js +3 -1
- package/ci/mechanism-agy-hooks.test.js +1096 -0
- package/ci/mechanism-agy-plugin-package.test.js +76 -0
- package/docs/codex-action-gate.md +2 -0
- package/docs/platform-capabilities.md +3 -1
- package/docs/platform-compatibility.json +34 -1
- package/hooks/scripts/action-gate.js +71 -5
- package/hooks/scripts/agy-post-tool.js +124 -0
- package/hooks/scripts/agy-pre-invocation.js +185 -0
- package/hooks/scripts/agy-pre-tool.js +158 -0
- package/hooks/scripts/agy-session-start.js +54 -0
- package/hooks/scripts/agy-stop.js +152 -0
- package/hooks/scripts/lib/agy-adapter-core.js +168 -0
- package/hooks/scripts/state-persist.js +50 -10
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +18 -0
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/action-gate.js +71 -5
- package/plugins/harness-everything/hooks/scripts/agy-post-tool.js +124 -0
- package/plugins/harness-everything/hooks/scripts/agy-pre-invocation.js +185 -0
- package/plugins/harness-everything/hooks/scripts/agy-pre-tool.js +158 -0
- package/plugins/harness-everything/hooks/scripts/agy-session-start.js +54 -0
- package/plugins/harness-everything/hooks/scripts/agy-stop.js +152 -0
- package/plugins/harness-everything/hooks/scripts/lib/agy-adapter-core.js +168 -0
- package/plugins/harness-everything/hooks/scripts/state-persist.js +50 -10
- package/plugins/harness-everything/hooks.json +44 -0
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/rules/AGENTS.md +111 -0
- package/sbom.cdx.json +7 -7
- package/scripts/plugin-sync.js +105 -14
- package/scripts/sync-openai-plugin.js +16 -1
- package/scripts/sync-release-version.js +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Antigravity (AGY) PreToolUse Hook Adapter
|
|
6
|
+
*
|
|
7
|
+
* Intercepts tool execution to enforce:
|
|
8
|
+
* - Worktree and filesystem boundary containment for file writes
|
|
9
|
+
* (allows writes inside any workspacePaths entry, cwd, or artifactDirectoryPath).
|
|
10
|
+
* - Canonical Action Gate policies (destructive operations, forced pushes, publish, reset).
|
|
11
|
+
*
|
|
12
|
+
* Returns protojson: {"decision": "allow" | "deny" | "ask", "reason": "..."}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
readJsonStdin,
|
|
17
|
+
getAgySessionId,
|
|
18
|
+
getAgyWorkspacePaths,
|
|
19
|
+
getAgyEffectiveCwd,
|
|
20
|
+
isOutOfBoundsPath
|
|
21
|
+
} = require('./lib/agy-adapter-core');
|
|
22
|
+
const { evaluatePreToolUse } = require('./action-gate');
|
|
23
|
+
|
|
24
|
+
const FILE_MUTATION_TOOLS = new Set([
|
|
25
|
+
'write_file',
|
|
26
|
+
'edit_file',
|
|
27
|
+
'write_to_file',
|
|
28
|
+
'replace_file_content',
|
|
29
|
+
'multi_replace_file_content'
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
function extractToolCall(payload) {
|
|
33
|
+
if (!payload || typeof payload !== 'object') {
|
|
34
|
+
return { id: undefined, name: '', args: {} };
|
|
35
|
+
}
|
|
36
|
+
const raw = payload.toolCall && typeof payload.toolCall === 'object' ? payload.toolCall : null;
|
|
37
|
+
const name = (raw && raw.name) || payload.tool_name || payload.toolName || payload.tool || '';
|
|
38
|
+
const args = (raw && raw.args && typeof raw.args === 'object')
|
|
39
|
+
? raw.args
|
|
40
|
+
: ((payload.tool_input && typeof payload.tool_input === 'object') ? payload.tool_input : {});
|
|
41
|
+
const id = (raw && raw.id) || payload.tool_use_id || payload.toolUseId || undefined;
|
|
42
|
+
return { id, name, args };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function collectAllowedWriteRoots(cwd, context = {}) {
|
|
46
|
+
const payload = (context && context.payload) || {};
|
|
47
|
+
const roots = [];
|
|
48
|
+
if (Array.isArray(context.workspacePaths)) {
|
|
49
|
+
for (const entry of context.workspacePaths) {
|
|
50
|
+
if (typeof entry === 'string' && entry.trim()) roots.push(entry.trim());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const entry of getAgyWorkspacePaths(payload)) {
|
|
54
|
+
roots.push(entry);
|
|
55
|
+
}
|
|
56
|
+
if (typeof cwd === 'string' && cwd.trim()) {
|
|
57
|
+
roots.push(cwd.trim());
|
|
58
|
+
}
|
|
59
|
+
const artifactDir = context.artifactDirectoryPath || payload.artifactDirectoryPath;
|
|
60
|
+
if (typeof artifactDir === 'string' && artifactDir.trim()) {
|
|
61
|
+
roots.push(artifactDir.trim());
|
|
62
|
+
}
|
|
63
|
+
return [...new Set(roots)];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function evaluateToolCall(toolCall, cwd, context = {}) {
|
|
67
|
+
if (!toolCall || !toolCall.name) {
|
|
68
|
+
return { decision: 'allow' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const name = toolCall.name;
|
|
72
|
+
const args = (toolCall.args && typeof toolCall.args === 'object') ? toolCall.args : {};
|
|
73
|
+
|
|
74
|
+
// 1. Filesystem boundary containment for file mutations
|
|
75
|
+
if (FILE_MUTATION_TOOLS.has(name)) {
|
|
76
|
+
const rawPath = args.TargetFile ?? args.Path ?? args.path ?? args.targetFile ?? args.filePath ?? args.file_path;
|
|
77
|
+
const filePath = typeof rawPath === 'string' ? rawPath.trim() : '';
|
|
78
|
+
if (!filePath) {
|
|
79
|
+
return {
|
|
80
|
+
decision: 'deny',
|
|
81
|
+
reason: `Harness boundary guard: missing target file path for ${name}.`
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const allowedRoots = collectAllowedWriteRoots(cwd, context);
|
|
86
|
+
if (isOutOfBoundsPath(filePath, allowedRoots, cwd)) {
|
|
87
|
+
return {
|
|
88
|
+
decision: 'deny',
|
|
89
|
+
reason: `Harness boundary guard: modification outside workspace root is forbidden (${filePath}).`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return { decision: 'allow' };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 2. Command safety via canonical Action Gate
|
|
96
|
+
if (name === 'run_command') {
|
|
97
|
+
const command = String(args.CommandLine || args.command || '').trim();
|
|
98
|
+
if (!command) {
|
|
99
|
+
return { decision: 'allow' };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const payload = context.payload || {};
|
|
103
|
+
const sessionId = context.sessionId || getAgySessionId(payload) || undefined;
|
|
104
|
+
const commandCwd = (typeof args.Cwd === 'string' && args.Cwd.trim())
|
|
105
|
+
|| (typeof args.cwd === 'string' && args.cwd.trim())
|
|
106
|
+
|| cwd;
|
|
107
|
+
const toolUseId = toolCall.id || payload.tool_use_id || payload.toolUseId || undefined;
|
|
108
|
+
|
|
109
|
+
const actionPayload = {
|
|
110
|
+
hook_event_name: 'PreToolUse',
|
|
111
|
+
tool_name: 'Bash',
|
|
112
|
+
tool_input: { command },
|
|
113
|
+
...(toolUseId ? { tool_use_id: toolUseId } : {}),
|
|
114
|
+
cwd: commandCwd,
|
|
115
|
+
...(cwd ? { workspace_root: cwd } : {}),
|
|
116
|
+
...(sessionId ? { session_id: sessionId, sessionId } : {})
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const gateResult = evaluatePreToolUse(actionPayload, { host: 'agy' });
|
|
120
|
+
|
|
121
|
+
if (gateResult.kind === 'block') {
|
|
122
|
+
const reason = gateResult.rule
|
|
123
|
+
? `[Harness actionGate:${gateResult.rule.id}] ${gateResult.rule.reason}`
|
|
124
|
+
: (gateResult.stderr || 'Harness action gate: command rejected.');
|
|
125
|
+
return { decision: 'deny', reason };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (gateResult.kind === 'ask') {
|
|
129
|
+
const reason = gateResult.rule
|
|
130
|
+
? `[Harness actionGate:${gateResult.rule.id}] ${gateResult.rule.reason}`
|
|
131
|
+
: 'Harness action gate: confirmation required.';
|
|
132
|
+
return { decision: 'ask', reason };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { decision: 'allow' };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { decision: 'allow' };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function main() {
|
|
142
|
+
const payload = await readJsonStdin();
|
|
143
|
+
const cwd = getAgyEffectiveCwd(payload);
|
|
144
|
+
const toolCall = extractToolCall(payload);
|
|
145
|
+
const sessionId = getAgySessionId(payload) || undefined;
|
|
146
|
+
|
|
147
|
+
const result = evaluateToolCall(toolCall, cwd, { sessionId, payload });
|
|
148
|
+
process.stdout.write(JSON.stringify(result) + '\n');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (require.main === module) {
|
|
152
|
+
main().catch(err => {
|
|
153
|
+
// Fail closed on evaluation failure if error occurs
|
|
154
|
+
process.stdout.write(JSON.stringify({ decision: 'deny', reason: `Internal hook error: ${err.message}` }) + '\n');
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = { main, evaluateToolCall, extractToolCall };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Antigravity (AGY) SessionStart Hook Adapter
|
|
6
|
+
*
|
|
7
|
+
* Runs once when a new conversation session begins.
|
|
8
|
+
* Binds session workspace identity (when provided) and injects Harness bootstrap message.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
readJsonStdin,
|
|
13
|
+
getAgySessionId,
|
|
14
|
+
normalizeAgyStatePayload
|
|
15
|
+
} = require('./lib/agy-adapter-core');
|
|
16
|
+
const { getWorkspaceRoot } = require('./lib/harness-state');
|
|
17
|
+
|
|
18
|
+
async function main() {
|
|
19
|
+
const payload = await readJsonStdin();
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const sessionId = getAgySessionId(payload);
|
|
23
|
+
const hasWorkspaceHint = Boolean(
|
|
24
|
+
(typeof payload.cwd === 'string' && payload.cwd.trim()) ||
|
|
25
|
+
(Array.isArray(payload.workspacePaths) && payload.workspacePaths.some(entry => typeof entry === 'string' && entry.trim()))
|
|
26
|
+
);
|
|
27
|
+
if (sessionId && hasWorkspaceHint) {
|
|
28
|
+
const normalized = normalizeAgyStatePayload(payload);
|
|
29
|
+
getWorkspaceRoot(normalized);
|
|
30
|
+
}
|
|
31
|
+
} catch (_) {
|
|
32
|
+
// Session workspace binding is best-effort and must never fail startup.
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const response = {
|
|
36
|
+
injectSteps: [
|
|
37
|
+
{
|
|
38
|
+
systemMessage: {
|
|
39
|
+
systemMessage: 'Harness Skills OS active. Operating under AGENTS.md invariant-first routing.'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
process.stdout.write(JSON.stringify(response) + '\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (require.main === module) {
|
|
49
|
+
main().catch(() => {
|
|
50
|
+
process.stdout.write('{}\n');
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = { main };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Antigravity (AGY) Stop Hook Adapter
|
|
6
|
+
*
|
|
7
|
+
* Implements the Verify-Before-Claim gate:
|
|
8
|
+
* - Inspects real session verification state (handoff-state.json in sessionDir).
|
|
9
|
+
* - If unverified edits exist or an unresolved tool failure exists, returns
|
|
10
|
+
* {"decision": "continue", "reason": "..."} to keep the agent in the loop.
|
|
11
|
+
* - If verified (or no unverified edits), returns {"decision": "allow"}.
|
|
12
|
+
* - Tracks the last continued state fingerprint in agy-stop-state.json so each
|
|
13
|
+
* unverified edit or failure triggers at most one forced continuation (preventing
|
|
14
|
+
* infinite loops on hosts that omit exitCode or continuationActive).
|
|
15
|
+
* - Respects compatibility recursion guards (continuationActive / stop_hook_active)
|
|
16
|
+
* to prevent infinite continuation loops, and allows stop on explicit abnormal
|
|
17
|
+
* terminationReason values (USER_CANCELED, ERROR, limits, etc.) while evaluating
|
|
18
|
+
* NO_TOOL_CALL, model_stop, and empty/normal reasons.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const {
|
|
24
|
+
readJsonStdin,
|
|
25
|
+
getAgySessionId,
|
|
26
|
+
normalizeAgyStatePayload
|
|
27
|
+
} = require('./lib/agy-adapter-core');
|
|
28
|
+
const { getWorkspaceRoot, getSessionDir } = require('./lib/harness-state');
|
|
29
|
+
|
|
30
|
+
const STOP_STATE_FILE = 'agy-stop-state.json';
|
|
31
|
+
|
|
32
|
+
function readStopState(filePath) {
|
|
33
|
+
try {
|
|
34
|
+
if (!fs.existsSync(filePath)) return null;
|
|
35
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
36
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
37
|
+
} catch (_) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeStopState(filePath, state) {
|
|
43
|
+
try {
|
|
44
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
45
|
+
const temp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
46
|
+
fs.writeFileSync(temp, JSON.stringify(state, null, 2) + '\n', 'utf8');
|
|
47
|
+
fs.renameSync(temp, filePath);
|
|
48
|
+
} catch (_) {
|
|
49
|
+
// Best-effort marker write; never fail stop evaluation on state IO.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const ABNORMAL_TERMINATION_REASONS = new Set([
|
|
54
|
+
'USER_CANCELED',
|
|
55
|
+
'CANCELED',
|
|
56
|
+
'CANCELLED',
|
|
57
|
+
'ERROR',
|
|
58
|
+
'MAX_INVOCATIONS',
|
|
59
|
+
'MAX_STEPS_EXCEEDED',
|
|
60
|
+
'MAX_TOKEN_BUDGET_EXCEEDED',
|
|
61
|
+
'TERMINAL_CUSTOM_HOOK',
|
|
62
|
+
'INTERRUPTED',
|
|
63
|
+
'ABORTED'
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
function evaluateStop(payload) {
|
|
67
|
+
if (!payload || typeof payload !== 'object') return { decision: 'allow' };
|
|
68
|
+
|
|
69
|
+
// 1. Compatibility recursion guards (not official documented Stop input fields):
|
|
70
|
+
// if a previous Stop hook already continued work during this turn, allow stop to prevent loops.
|
|
71
|
+
if (payload.continuationActive || payload.stop_hook_active) {
|
|
72
|
+
return { decision: 'allow' };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 2. Allow stop only on explicit abnormal termination reasons; normal reasons
|
|
76
|
+
// (NO_TOOL_CALL, model_stop, empty/unknown) must still evaluate handoff-state.json.
|
|
77
|
+
const terminationReason = typeof payload.terminationReason === 'string'
|
|
78
|
+
? payload.terminationReason.trim().toUpperCase()
|
|
79
|
+
: '';
|
|
80
|
+
if (terminationReason && ABNORMAL_TERMINATION_REASONS.has(terminationReason)) {
|
|
81
|
+
return { decision: 'allow' };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 3. Locate session state using normalized AGY workspace/session context
|
|
85
|
+
const normalized = normalizeAgyStatePayload(payload);
|
|
86
|
+
const sessionId = getAgySessionId(payload);
|
|
87
|
+
const root = getWorkspaceRoot(normalized) || normalized.cwd;
|
|
88
|
+
const sessionDir = getSessionDir(root, sessionId);
|
|
89
|
+
const handoffFile = path.join(sessionDir, 'handoff-state.json');
|
|
90
|
+
|
|
91
|
+
let handoff = null;
|
|
92
|
+
if (fs.existsSync(handoffFile)) {
|
|
93
|
+
try {
|
|
94
|
+
handoff = JSON.parse(fs.readFileSync(handoffFile, 'utf8'));
|
|
95
|
+
} catch (_) {}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const lastEditAt = (handoff && handoff.lastEditAt) || 0;
|
|
99
|
+
const lastVerifyAt = (handoff && handoff.lastVerifyAt) || 0;
|
|
100
|
+
const isFailed = handoff && handoff.status === 'failed';
|
|
101
|
+
|
|
102
|
+
// 4. Check for unverified edits or unresolved failure (bounded to 1 continuation per pending state)
|
|
103
|
+
let pending = null;
|
|
104
|
+
if (isFailed) {
|
|
105
|
+
pending = {
|
|
106
|
+
fingerprint: `failed:${handoff.timestamp || ''}:${handoff.tool || ''}:${handoff.exitCode ?? ''}`,
|
|
107
|
+
reason: 'Harness Verify-Before-Claim: pending tool failure must be resolved before claiming completion.'
|
|
108
|
+
};
|
|
109
|
+
} else if (lastEditAt > 0 && lastVerifyAt < lastEditAt) {
|
|
110
|
+
pending = {
|
|
111
|
+
fingerprint: `edit:${lastEditAt}`,
|
|
112
|
+
reason: 'Harness Verify-Before-Claim: unverified edits exist in session. Run relevant test/build/lint verification before claiming completion.'
|
|
113
|
+
};
|
|
114
|
+
} else if (process.env.HARNESS_REQUIRE_VERIFICATION === '1' && (!lastVerifyAt || lastVerifyAt < lastEditAt)) {
|
|
115
|
+
pending = {
|
|
116
|
+
fingerprint: `strict:${lastVerifyAt}`,
|
|
117
|
+
reason: 'Harness Verify-Before-Claim: objective test verification is required before claiming completion.'
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (pending) {
|
|
122
|
+
const stopStateFile = path.join(sessionDir, STOP_STATE_FILE);
|
|
123
|
+
const saved = readStopState(stopStateFile);
|
|
124
|
+
if (saved && saved.lastContinuedFingerprint === pending.fingerprint) {
|
|
125
|
+
return { decision: 'allow' };
|
|
126
|
+
}
|
|
127
|
+
writeStopState(stopStateFile, {
|
|
128
|
+
lastContinuedFingerprint: pending.fingerprint,
|
|
129
|
+
updatedAt: new Date().toISOString()
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
decision: 'continue',
|
|
133
|
+
reason: pending.reason
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return { decision: 'allow' };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function main() {
|
|
141
|
+
const payload = await readJsonStdin();
|
|
142
|
+
const result = evaluateStop(payload);
|
|
143
|
+
process.stdout.write(JSON.stringify(result) + '\n');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (require.main === module) {
|
|
147
|
+
main().catch(() => {
|
|
148
|
+
process.stdout.write('{"decision":"allow"}\n');
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = { main, evaluateStop };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
function readJsonStdin(timeoutMs = 1500) {
|
|
7
|
+
return new Promise(resolve => {
|
|
8
|
+
let raw = '';
|
|
9
|
+
let settled = false;
|
|
10
|
+
|
|
11
|
+
const timer = setTimeout(() => {
|
|
12
|
+
if (settled) return;
|
|
13
|
+
settled = true;
|
|
14
|
+
try {
|
|
15
|
+
resolve(raw.trim() ? JSON.parse(raw) : {});
|
|
16
|
+
} catch (_) {
|
|
17
|
+
resolve({});
|
|
18
|
+
}
|
|
19
|
+
}, timeoutMs);
|
|
20
|
+
|
|
21
|
+
process.stdin.setEncoding('utf8');
|
|
22
|
+
process.stdin.on('data', chunk => { raw += chunk; });
|
|
23
|
+
process.stdin.on('end', () => {
|
|
24
|
+
if (settled) return;
|
|
25
|
+
settled = true;
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
try {
|
|
28
|
+
resolve(raw.trim() ? JSON.parse(raw) : {});
|
|
29
|
+
} catch (_) {
|
|
30
|
+
resolve({});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
process.stdin.on('error', () => {
|
|
34
|
+
if (settled) return;
|
|
35
|
+
settled = true;
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
resolve({});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resolveKernelRouter() {
|
|
43
|
+
const candidates = [
|
|
44
|
+
path.join(__dirname, '..', '..', '..', 'skills', 'harness-everything', 'scripts', 'kernel-router.js'),
|
|
45
|
+
path.join(__dirname, '..', '..', '..', 'harness-everything', 'scripts', 'kernel-router.js'),
|
|
46
|
+
path.join(__dirname, '..', '..', 'harness-everything', 'scripts', 'kernel-router.js')
|
|
47
|
+
];
|
|
48
|
+
return candidates.find(candidate => fs.existsSync(candidate)) || null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getAgySessionId(payload) {
|
|
52
|
+
if (!payload || typeof payload !== 'object') return '';
|
|
53
|
+
const candidate = payload.conversationId || payload.session_id || payload.sessionId || '';
|
|
54
|
+
return typeof candidate === 'string' ? candidate.trim() : String(candidate || '').trim();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getAgyWorkspacePaths(payload) {
|
|
58
|
+
if (!payload || typeof payload !== 'object') return [];
|
|
59
|
+
const roots = [];
|
|
60
|
+
if (Array.isArray(payload.workspacePaths)) {
|
|
61
|
+
for (const entry of payload.workspacePaths) {
|
|
62
|
+
if (typeof entry === 'string' && entry.trim()) roots.push(entry.trim());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (typeof payload.cwd === 'string' && payload.cwd.trim()) {
|
|
66
|
+
roots.push(payload.cwd.trim());
|
|
67
|
+
}
|
|
68
|
+
return [...new Set(roots)];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getAgyEffectiveCwd(payload) {
|
|
72
|
+
if (payload && typeof payload === 'object') {
|
|
73
|
+
if (typeof payload.cwd === 'string' && payload.cwd.trim()) {
|
|
74
|
+
return payload.cwd.trim();
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(payload.workspacePaths)) {
|
|
77
|
+
const first = payload.workspacePaths.find(entry => typeof entry === 'string' && entry.trim());
|
|
78
|
+
if (first) return first.trim();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return process.cwd();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeAgyStatePayload(payload, overrideCwd) {
|
|
85
|
+
const base = payload && typeof payload === 'object' ? payload : {};
|
|
86
|
+
const sessionId = getAgySessionId(base);
|
|
87
|
+
const effectiveCwd = (typeof overrideCwd === 'string' && overrideCwd.trim())
|
|
88
|
+
? overrideCwd.trim()
|
|
89
|
+
: getAgyEffectiveCwd(base);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
...base,
|
|
93
|
+
...(sessionId ? { session_id: sessionId, sessionId, conversationId: sessionId } : {}),
|
|
94
|
+
cwd: effectiveCwd
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const MAX_SYMLINK_HOPS = 40;
|
|
99
|
+
const realpath = fs.realpathSync.native || fs.realpathSync;
|
|
100
|
+
|
|
101
|
+
function canonicalizePath(targetPath, baseDir, depth = 0) {
|
|
102
|
+
if (depth > MAX_SYMLINK_HOPS) return null;
|
|
103
|
+
if (typeof targetPath !== 'string' || !targetPath.trim()) return null;
|
|
104
|
+
const resolved = (typeof baseDir === 'string' && baseDir.trim())
|
|
105
|
+
? path.resolve(baseDir, targetPath)
|
|
106
|
+
: path.resolve(targetPath);
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
return realpath(resolved);
|
|
110
|
+
} catch (_) {
|
|
111
|
+
const suffix = [];
|
|
112
|
+
let current = resolved;
|
|
113
|
+
while (true) {
|
|
114
|
+
try {
|
|
115
|
+
const stat = fs.lstatSync(current);
|
|
116
|
+
if (stat.isSymbolicLink()) {
|
|
117
|
+
const linkTarget = fs.readlinkSync(current);
|
|
118
|
+
const resolvedLink = path.resolve(path.dirname(current), linkTarget);
|
|
119
|
+
const nextPath = suffix.length > 0 ? path.join(resolvedLink, ...suffix) : resolvedLink;
|
|
120
|
+
return canonicalizePath(nextPath, null, depth + 1);
|
|
121
|
+
}
|
|
122
|
+
} catch (_) {
|
|
123
|
+
// Entry does not exist yet; continue ascending to nearest existing ancestor.
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const parent = path.dirname(current);
|
|
127
|
+
if (parent === current) return resolved;
|
|
128
|
+
suffix.unshift(path.basename(current));
|
|
129
|
+
current = parent;
|
|
130
|
+
try {
|
|
131
|
+
const realAncestor = realpath(current);
|
|
132
|
+
return path.join(realAncestor, ...suffix);
|
|
133
|
+
} catch (_) {}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function isOutOfBoundsPath(filePath, allowedRoots, baseDir) {
|
|
139
|
+
if (typeof filePath !== 'string' || !filePath.trim()) return true;
|
|
140
|
+
const roots = (Array.isArray(allowedRoots) ? allowedRoots : [allowedRoots])
|
|
141
|
+
.filter(root => typeof root === 'string' && root.trim());
|
|
142
|
+
if (roots.length === 0) return false;
|
|
143
|
+
|
|
144
|
+
const resolveBase = (typeof baseDir === 'string' && baseDir.trim()) ? baseDir : roots[0];
|
|
145
|
+
const canonicalTarget = canonicalizePath(filePath, resolveBase);
|
|
146
|
+
if (!canonicalTarget) return true;
|
|
147
|
+
|
|
148
|
+
const normTarget = process.platform === 'win32' ? canonicalTarget.toLowerCase() : canonicalTarget;
|
|
149
|
+
return !roots.some(root => {
|
|
150
|
+
const canonicalRoot = canonicalizePath(root);
|
|
151
|
+
if (!canonicalRoot) return false;
|
|
152
|
+
const normRoot = process.platform === 'win32' ? canonicalRoot.toLowerCase() : canonicalRoot;
|
|
153
|
+
if (normTarget === normRoot) return true;
|
|
154
|
+
const prefix = normRoot.endsWith(path.sep) ? normRoot : normRoot + path.sep;
|
|
155
|
+
return normTarget.startsWith(prefix);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = {
|
|
160
|
+
readJsonStdin,
|
|
161
|
+
resolveKernelRouter,
|
|
162
|
+
getAgySessionId,
|
|
163
|
+
getAgyWorkspacePaths,
|
|
164
|
+
getAgyEffectiveCwd,
|
|
165
|
+
normalizeAgyStatePayload,
|
|
166
|
+
canonicalizePath,
|
|
167
|
+
isOutOfBoundsPath
|
|
168
|
+
};
|
|
@@ -2,10 +2,40 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const { getWorkspaceRoot, getSessionDir } = require('./lib/harness-state');
|
|
5
|
-
const { cwdOf, classifyShell, isVerificationShell, directMutationInWorkspace } = require('./lib/workflow-isolation');
|
|
5
|
+
const { cwdOf, classifyShell, isVerificationShell, directMutationInWorkspace, mutationPaths } = require('./lib/workflow-isolation');
|
|
6
|
+
const { getAgyWorkspacePaths, isOutOfBoundsPath } = require('./lib/agy-adapter-core');
|
|
6
7
|
const { observeTool } = require('./lib/telemetry');
|
|
7
8
|
const { readCodexToolOutcome } = require('./lib/codex-tool-outcome');
|
|
8
9
|
const codex = process.argv.includes('--codex');
|
|
10
|
+
const agy = process.argv.includes('--agy');
|
|
11
|
+
|
|
12
|
+
function agyMutationTargets(payload, toolName) {
|
|
13
|
+
if (toolName === 'apply_patch') {
|
|
14
|
+
return mutationPaths(payload).map(v => String(v || '').trim()).filter(Boolean);
|
|
15
|
+
}
|
|
16
|
+
const input = (payload && (payload.tool_input ?? payload.toolInput ?? payload.input)) || {};
|
|
17
|
+
const candidates = [
|
|
18
|
+
input.file_path,
|
|
19
|
+
input.filePath,
|
|
20
|
+
input.path,
|
|
21
|
+
input.TargetFile,
|
|
22
|
+
input.Path,
|
|
23
|
+
input.targetFile
|
|
24
|
+
];
|
|
25
|
+
const target = candidates.find(value => typeof value === 'string' && value.trim());
|
|
26
|
+
return target ? [target.trim()] : [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function agyDirectMutationInWorkspace(payload, mutationCwd, root, toolName) {
|
|
30
|
+
const targets = agyMutationTargets(payload, toolName);
|
|
31
|
+
if (targets.length === 0) return false;
|
|
32
|
+
const agyRoots = getAgyWorkspacePaths(payload);
|
|
33
|
+
if (typeof root === 'string' && root.trim() && !agyRoots.includes(root.trim())) {
|
|
34
|
+
agyRoots.push(root.trim());
|
|
35
|
+
}
|
|
36
|
+
if (agyRoots.length === 0) return false;
|
|
37
|
+
return targets.some(target => !isOutOfBoundsPath(target, agyRoots, mutationCwd));
|
|
38
|
+
}
|
|
9
39
|
|
|
10
40
|
function isSuccessfulMetadataStep(command, cwd) {
|
|
11
41
|
// A line break starts a second shell command, so it can never be metadata-only.
|
|
@@ -83,14 +113,19 @@ function processState(payload) {
|
|
|
83
113
|
const stdout = codexResult?.stdout ?? toolResponse.stdout ?? payload.stdout ?? '';
|
|
84
114
|
const stderr = codexResult?.stderr ?? toolResponse.stderr ?? payload.stderr ?? payload.error ?? '';
|
|
85
115
|
const rawExitCode = toolResponse.exitCode ?? toolResponse.exit_code ?? payload.exitCode;
|
|
86
|
-
const exitCode = codex ? codexResult.exitCode
|
|
116
|
+
const exitCode = codex ? codexResult.exitCode
|
|
117
|
+
: agy ? (Number.isInteger(rawExitCode) ? rawExitCode : undefined)
|
|
118
|
+
: typeof rawExitCode === 'number' ? rawExitCode : undefined;
|
|
87
119
|
const stderrSignal = typeof stderr === 'string' && stderr.trim().length > 0;
|
|
88
120
|
const hookEvent = captureEventName;
|
|
89
121
|
const isSuccessEvent = hookEvent === 'PostToolUse';
|
|
122
|
+
const agyErrorSignal = agy && typeof payload.error === 'string' && payload.error.trim().length > 0;
|
|
90
123
|
const isFailed = codex ? codexResult.outcome === 'failure' :
|
|
91
|
-
hookEvent === 'PostToolUseFailure' || (exitCode !== undefined && exitCode !== 0) ||
|
|
124
|
+
hookEvent === 'PostToolUseFailure' || agyErrorSignal || (exitCode !== undefined && exitCode !== 0) ||
|
|
92
125
|
(!isSuccessEvent && exitCode === undefined && stderrSignal);
|
|
93
|
-
const verifiedSuccess = codex ? codexResult.outcome === 'success'
|
|
126
|
+
const verifiedSuccess = codex ? codexResult.outcome === 'success'
|
|
127
|
+
: agy ? (!isFailed && exitCode === 0)
|
|
128
|
+
: !isFailed && (isSuccessEvent || exitCode === 0);
|
|
94
129
|
const toolName = payload.tool_name || payload.tool || 'command';
|
|
95
130
|
let editAfterCapture = false;
|
|
96
131
|
let stateOnlyCandidate = false;
|
|
@@ -98,11 +133,13 @@ function processState(payload) {
|
|
|
98
133
|
let output = (stderrSignal ? stderr : stdout) || (typeof payload.output === 'string' ? payload.output : '');
|
|
99
134
|
if (output.length > 500) output = '...' + output.slice(-500);
|
|
100
135
|
state.status = 'failed'; state.timestamp = new Date().toISOString(); state.tool = toolName; state.exitCode = exitCode; state.errorSummary = output.trim();
|
|
101
|
-
} else if ((!codex || verifiedSuccess) && state.status === 'failed') {
|
|
136
|
+
} else if (((!codex && !agy) || verifiedSuccess) && state.status === 'failed') {
|
|
102
137
|
state.lastResolved = { tool: state.tool, timestamp: state.timestamp }; state.status = 'idle'; state.timestamp = new Date().toISOString(); delete state.exitCode; delete state.errorSummary;
|
|
103
138
|
}
|
|
104
139
|
const isDirectTool = toolName === 'Edit' || toolName === 'Write' || toolName === 'apply_patch';
|
|
105
|
-
if (isDirectTool &&
|
|
140
|
+
if (isDirectTool && (agy
|
|
141
|
+
? agyDirectMutationInWorkspace(payload, cwdOf(payload, root), root, toolName)
|
|
142
|
+
: directMutationInWorkspace(payload, cwdOf(payload, root), root))) state.lastEditAt = Date.now();
|
|
106
143
|
const isShell = toolName === 'Bash' || toolName === 'PowerShell' || toolName === 'exec_command';
|
|
107
144
|
const command = (payload.tool_input && payload.tool_input.command) || '';
|
|
108
145
|
if (isShell) {
|
|
@@ -114,10 +151,6 @@ function processState(payload) {
|
|
|
114
151
|
{ toolName, sessionId, agentId: payload.agent_id }));
|
|
115
152
|
const metadataStep = !stateOnlyCandidate && verifiedSuccess
|
|
116
153
|
&& isSuccessfulMetadataStep(command, cwdOf(payload, root));
|
|
117
|
-
if (!metadataStep && commandClass !== 'read-only' && commandClass !== 'worktree-setup') {
|
|
118
|
-
if (stateOnlyCandidate) editAfterCapture = true;
|
|
119
|
-
else state.lastEditAt = Date.now();
|
|
120
|
-
}
|
|
121
154
|
// The host-specific outcome must confirm success before verification advances.
|
|
122
155
|
// Pilot ON only: a registered, argv-validated doc-check that resolves to this install's own runtime is the document
|
|
123
156
|
// verification evidence, and only at the shipped pin (R3-02). Any other path earns no verification evidence. OFF stays legacy.
|
|
@@ -129,6 +162,13 @@ function processState(payload) {
|
|
|
129
162
|
const verifies = stateOnlyCandidate ? false : docCheckCandidate
|
|
130
163
|
? Boolean(pinCheckable) && docCheck.fileDigest(installedCheck.installed) === docCheck.SHIPPED_DOC_CHECK_DIGEST
|
|
131
164
|
: !(pilotEnabled && docCheck.trustRisk(command)) && isVerificationShell(command, { cwd: cwdOf(payload, root), root });
|
|
165
|
+
// On AGY hosts that omit shell error/exitCode, an unconfirmed verification-only command must not advance lastEditAt
|
|
166
|
+
// and defeat agy-stop.js's bounded continuation fingerprint.
|
|
167
|
+
const agyUnknownOutcomeVerify = agy && !verifiedSuccess && !isFailed && verifies;
|
|
168
|
+
if (!metadataStep && !agyUnknownOutcomeVerify && commandClass !== 'read-only' && commandClass !== 'worktree-setup') {
|
|
169
|
+
if (stateOnlyCandidate) editAfterCapture = true;
|
|
170
|
+
else state.lastEditAt = Date.now();
|
|
171
|
+
}
|
|
132
172
|
if (verifiedSuccess && verifies) {
|
|
133
173
|
const verifiedAt = Date.now();
|
|
134
174
|
const verifiedExitCode = exitCode ?? null;
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "harness-everything",
|
|
3
|
+
"version": "0.58.0",
|
|
4
|
+
"description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Miya Daniel",
|
|
7
|
+
"url": "https://github.com/dyphn1"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/dyphn1/Harness-everything",
|
|
10
|
+
"repository": "https://github.com/dyphn1/Harness-everything",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"agent-harness",
|
|
14
|
+
"orchestration",
|
|
15
|
+
"tdd",
|
|
16
|
+
"verification"
|
|
17
|
+
]
|
|
18
|
+
}
|