@aria_asi/cli 0.2.25 → 0.2.29
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/CLIENT-ONBOARDING.md +282 -0
- package/bin/aria.js +1140 -14
- package/dist/aria-connector/src/auth-commands.d.ts +1 -0
- package/dist/aria-connector/src/auth-commands.d.ts.map +1 -1
- package/dist/aria-connector/src/auth-commands.js +89 -41
- package/dist/aria-connector/src/auth-commands.js.map +1 -1
- package/dist/aria-connector/src/chat.d.ts +3 -0
- package/dist/aria-connector/src/chat.d.ts.map +1 -1
- package/dist/aria-connector/src/chat.js +146 -8
- package/dist/aria-connector/src/chat.js.map +1 -1
- package/dist/aria-connector/src/codebase-scanner.d.ts +2 -2
- package/dist/aria-connector/src/codebase-scanner.d.ts.map +1 -1
- package/dist/aria-connector/src/codebase-scanner.js +1 -1
- package/dist/aria-connector/src/codebase-scanner.js.map +1 -1
- package/dist/aria-connector/src/config.d.ts +12 -0
- package/dist/aria-connector/src/config.d.ts.map +1 -1
- package/dist/aria-connector/src/config.js +2 -0
- package/dist/aria-connector/src/config.js.map +1 -1
- package/dist/aria-connector/src/connectors/claude-code.d.ts.map +1 -1
- package/dist/aria-connector/src/connectors/claude-code.js +111 -21
- package/dist/aria-connector/src/connectors/claude-code.js.map +1 -1
- package/dist/aria-connector/src/connectors/codebase-awareness.d.ts +37 -0
- package/dist/aria-connector/src/connectors/codebase-awareness.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/codebase-awareness.js +335 -0
- package/dist/aria-connector/src/connectors/codebase-awareness.js.map +1 -0
- package/dist/aria-connector/src/connectors/codex.d.ts +3 -0
- package/dist/aria-connector/src/connectors/codex.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/codex.js +248 -0
- package/dist/aria-connector/src/connectors/codex.js.map +1 -0
- package/dist/aria-connector/src/connectors/cognitive-skills.d.ts +2 -0
- package/dist/aria-connector/src/connectors/cognitive-skills.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/cognitive-skills.js +47 -0
- package/dist/aria-connector/src/connectors/cognitive-skills.js.map +1 -0
- package/dist/aria-connector/src/connectors/opencode.d.ts.map +1 -1
- package/dist/aria-connector/src/connectors/opencode.js +90 -4
- package/dist/aria-connector/src/connectors/opencode.js.map +1 -1
- package/dist/aria-connector/src/connectors/repo-git-hooks.d.ts +3 -0
- package/dist/aria-connector/src/connectors/repo-git-hooks.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/repo-git-hooks.js +87 -0
- package/dist/aria-connector/src/connectors/repo-git-hooks.js.map +1 -0
- package/dist/aria-connector/src/connectors/repo-guard.d.ts +19 -0
- package/dist/aria-connector/src/connectors/repo-guard.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/repo-guard.js +509 -0
- package/dist/aria-connector/src/connectors/repo-guard.js.map +1 -0
- package/dist/aria-connector/src/connectors/runtime.d.ts +2 -0
- package/dist/aria-connector/src/connectors/runtime.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/runtime.js +330 -0
- package/dist/aria-connector/src/connectors/runtime.js.map +1 -0
- package/dist/aria-connector/src/connectors/shell.d.ts.map +1 -1
- package/dist/aria-connector/src/connectors/shell.js +78 -13
- package/dist/aria-connector/src/connectors/shell.js.map +1 -1
- package/dist/aria-connector/src/connectors/syncd.d.ts +27 -0
- package/dist/aria-connector/src/connectors/syncd.d.ts.map +1 -0
- package/dist/aria-connector/src/connectors/syncd.js +405 -0
- package/dist/aria-connector/src/connectors/syncd.js.map +1 -0
- package/dist/aria-connector/src/decisions.d.ts +207 -0
- package/dist/aria-connector/src/decisions.d.ts.map +1 -0
- package/dist/aria-connector/src/decisions.js +291 -0
- package/dist/aria-connector/src/decisions.js.map +1 -0
- package/dist/aria-connector/src/garden-control-plane.d.ts.map +1 -1
- package/dist/aria-connector/src/garden-control-plane.js +74 -17
- package/dist/aria-connector/src/garden-control-plane.js.map +1 -1
- package/dist/aria-connector/src/github-connect.d.ts +18 -0
- package/dist/aria-connector/src/github-connect.d.ts.map +1 -0
- package/dist/aria-connector/src/github-connect.js +117 -0
- package/dist/aria-connector/src/github-connect.js.map +1 -0
- package/dist/aria-connector/src/harness-client.d.ts +15 -0
- package/dist/aria-connector/src/harness-client.d.ts.map +1 -1
- package/dist/aria-connector/src/harness-client.js +106 -3
- package/dist/aria-connector/src/harness-client.js.map +1 -1
- package/dist/aria-connector/src/hive-client.d.ts +30 -0
- package/dist/aria-connector/src/hive-client.d.ts.map +1 -1
- package/dist/aria-connector/src/hive-client.js +124 -5
- package/dist/aria-connector/src/hive-client.js.map +1 -1
- package/dist/aria-connector/src/index.d.ts +13 -2
- package/dist/aria-connector/src/index.d.ts.map +1 -1
- package/dist/aria-connector/src/index.js +10 -1
- package/dist/aria-connector/src/index.js.map +1 -1
- package/dist/aria-connector/src/lib/aristotle-noor-wire.d.ts +102 -0
- package/dist/aria-connector/src/lib/aristotle-noor-wire.d.ts.map +1 -0
- package/dist/aria-connector/src/lib/aristotle-noor-wire.js +231 -0
- package/dist/aria-connector/src/lib/aristotle-noor-wire.js.map +1 -0
- package/dist/aria-connector/src/providers/types.d.ts +5 -0
- package/dist/aria-connector/src/providers/types.d.ts.map +1 -1
- package/dist/aria-connector/src/runtime-proof.d.ts +45 -0
- package/dist/aria-connector/src/runtime-proof.d.ts.map +1 -0
- package/dist/aria-connector/src/runtime-proof.js +340 -0
- package/dist/aria-connector/src/runtime-proof.js.map +1 -0
- package/dist/aria-connector/src/setup-wizard.d.ts.map +1 -1
- package/dist/aria-connector/src/setup-wizard.js +34 -2
- package/dist/aria-connector/src/setup-wizard.js.map +1 -1
- package/dist/assets/hooks/aria-agent-handoff.mjs +224 -0
- package/dist/assets/hooks/aria-agent-ledger-merge.mjs +164 -0
- package/dist/assets/hooks/aria-architect-fallback.mjs +267 -0
- package/dist/assets/hooks/aria-cognition-substrate-binding.mjs +676 -0
- package/dist/assets/hooks/aria-discovery-record.mjs +101 -0
- package/dist/assets/hooks/aria-harness-via-sdk.mjs +412 -0
- package/dist/assets/hooks/aria-import-resolution-gate.mjs +330 -0
- package/dist/assets/hooks/aria-outcome-record.mjs +84 -0
- package/dist/assets/hooks/aria-pre-emit-dryrun.mjs +294 -0
- package/dist/assets/hooks/aria-pre-text-gate.mjs +112 -0
- package/dist/assets/hooks/aria-pre-tool-gate.mjs +2133 -0
- package/dist/assets/hooks/aria-preprompt-consult.mjs +438 -0
- package/dist/assets/hooks/aria-preturn-memory-gate.mjs +570 -0
- package/dist/assets/hooks/aria-repo-doctrine-gate.mjs +397 -0
- package/dist/assets/hooks/aria-stop-gate.mjs +1551 -0
- package/dist/assets/hooks/aria-trigger-autolearn.mjs +229 -0
- package/dist/assets/hooks/aria-userprompt-abandon-detect.mjs +192 -0
- package/dist/assets/hooks/doctrine_trigger_map.json +479 -0
- package/dist/assets/hooks/lib/canonical-lenses.mjs +64 -0
- package/dist/assets/hooks/lib/gate-audit.mjs +43 -0
- package/dist/assets/hooks/test-aria-preturn-memory-gate.mjs +245 -0
- package/dist/assets/hooks/test-tier-lens-labeling.mjs +399 -0
- package/dist/assets/opencode-plugins/harness-context/index.js +60 -0
- package/dist/assets/opencode-plugins/harness-context/inject-context.mjs +179 -0
- package/dist/assets/opencode-plugins/harness-context/package.json +9 -0
- package/dist/assets/opencode-plugins/harness-gate/index.js +248 -0
- package/dist/assets/opencode-plugins/harness-outcome/index.js +129 -0
- package/dist/assets/opencode-plugins/harness-role/index.js +77 -0
- package/dist/assets/opencode-plugins/harness-role/package.json +9 -0
- package/dist/assets/opencode-plugins/harness-stop/index.js +241 -0
- package/dist/runtime/discipline/CLAUDE.md +339 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-essence/SKILL.md +63 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-essence/references/domain-matrix.md +80 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-essence/references/evolution-loop.md +30 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-essence/references/readable-cognition.md +27 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-forge-guardrails/SKILL.md +35 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-forge-guardrails/references/checklist.md +31 -0
- package/dist/runtime/discipline/skills/aria-cognition/aria-repo-doctrine/SKILL.md +39 -0
- package/dist/runtime/discipline/skills/aria-cognition/forge-quality-rules/SKILL.md +43 -0
- package/dist/runtime/discipline/skills/aria-cognition/ghazali-8lens/SKILL.md +38 -0
- package/dist/runtime/discipline/skills/aria-cognition/istiqra-induction/SKILL.md +26 -0
- package/dist/runtime/discipline/skills/aria-cognition/ladunni-22/SKILL.md +35 -0
- package/dist/runtime/discipline/skills/aria-cognition/mizan/SKILL.md +72 -0
- package/dist/runtime/discipline/skills/aria-cognition/nadia/SKILL.md +38 -0
- package/dist/runtime/discipline/skills/aria-cognition/nadia-psi/SKILL.md +38 -0
- package/dist/runtime/discipline/skills/aria-cognition/predictor/SKILL.md +25 -0
- package/dist/runtime/discipline/skills/aria-cognition/qiyas-analogy/SKILL.md +26 -0
- package/dist/runtime/discipline/skills/aria-cognition/soul-domains/SKILL.md +25 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-aristotle-intra-phase/SKILL.md +81 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-aristotle-post-phase/SKILL.md +98 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-aristotle-pre-phase/SKILL.md +99 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-harness-deploy/SKILL.md +127 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-harness-no-stripping/SKILL.md +117 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-harness-onboarding/SKILL.md +112 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-harness-output-discipline/SKILL.md +102 -0
- package/dist/runtime/discipline/skills/aria-harness/aria-harness-substrate-binding/SKILL.md +121 -0
- package/dist/runtime/doctor.mjs +23 -0
- package/dist/runtime/local-phase.mjs +632 -0
- package/dist/runtime/manifest.json +15 -0
- package/dist/runtime/mizan-scheduler.mjs +331 -0
- package/dist/runtime/package.json +6 -0
- package/dist/runtime/provider-proxy.mjs +594 -0
- package/dist/runtime/sdk/BUNDLED.json +5 -0
- package/dist/runtime/sdk/index.d.ts +477 -0
- package/dist/runtime/sdk/index.js +1469 -0
- package/dist/runtime/sdk/index.js.map +1 -0
- package/dist/runtime/sdk/package.json +8 -0
- package/dist/runtime/sdk/runWithCognition.d.ts +77 -0
- package/dist/runtime/sdk/runWithCognition.js +157 -0
- package/dist/runtime/sdk/runWithCognition.js.map +1 -0
- package/dist/runtime/service.mjs +2708 -0
- package/dist/runtime/vendor/aria-gate-runtime/index.d.ts +53 -0
- package/dist/runtime/vendor/aria-gate-runtime/index.d.ts.map +1 -0
- package/dist/runtime/vendor/aria-gate-runtime/index.js +277 -0
- package/dist/runtime/vendor/aria-gate-runtime/index.js.map +1 -0
- package/dist/runtime/vendor/aria-gate-runtime/package.json +6 -0
- package/dist/sdk/BUNDLED.json +2 -2
- package/dist/sdk/index.d.ts +317 -0
- package/dist/sdk/index.js +827 -85
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/runWithCognition.d.ts +77 -0
- package/dist/sdk/runWithCognition.js +157 -0
- package/dist/sdk/runWithCognition.js.map +1 -0
- package/hooks/aria-agent-handoff.mjs +11 -1
- package/hooks/aria-architect-fallback.mjs +267 -0
- package/hooks/aria-cognition-substrate-binding.mjs +676 -0
- package/hooks/aria-discovery-record.mjs +101 -0
- package/hooks/aria-harness-via-sdk.mjs +34 -21
- package/hooks/aria-import-resolution-gate.mjs +330 -0
- package/hooks/aria-outcome-record.mjs +84 -0
- package/hooks/aria-pre-emit-dryrun.mjs +294 -0
- package/hooks/aria-pre-tool-gate.mjs +985 -40
- package/hooks/aria-preprompt-consult.mjs +113 -13
- package/hooks/aria-preturn-memory-gate.mjs +298 -6
- package/hooks/aria-repo-doctrine-gate.mjs +397 -0
- package/hooks/aria-stop-gate.mjs +840 -75
- package/hooks/aria-userprompt-abandon-detect.mjs +5 -1
- package/hooks/doctrine_trigger_map.json +209 -15
- package/hooks/lib/canonical-lenses.mjs +64 -0
- package/hooks/lib/gate-audit.mjs +43 -0
- package/opencode-plugins/harness-context/index.js +1 -1
- package/opencode-plugins/harness-context/inject-context.mjs +82 -23
- package/opencode-plugins/harness-gate/index.js +248 -0
- package/opencode-plugins/harness-outcome/index.js +129 -0
- package/opencode-plugins/harness-stop/index.js +241 -0
- package/package.json +8 -2
- package/runtime-src/doctor.mjs +23 -0
- package/runtime-src/local-phase.mjs +632 -0
- package/runtime-src/mizan-scheduler.mjs +331 -0
- package/runtime-src/provider-proxy.mjs +594 -0
- package/runtime-src/service.mjs +2708 -0
- package/scripts/bundle-sdk.mjs +317 -0
- package/scripts/install-client.sh +176 -0
- package/scripts/publish-all.sh +344 -0
- package/scripts/publish-docker.sh +27 -0
- package/scripts/validate-hook-contracts.mjs +54 -0
- package/scripts/validate-skill-prompts.mjs +95 -0
- package/skills/aria-cognition/aria-essence/SKILL.md +63 -0
- package/skills/aria-cognition/aria-essence/references/domain-matrix.md +80 -0
- package/skills/aria-cognition/aria-essence/references/evolution-loop.md +30 -0
- package/skills/aria-cognition/aria-essence/references/readable-cognition.md +27 -0
- package/skills/aria-cognition/aria-forge-guardrails/SKILL.md +35 -0
- package/skills/aria-cognition/aria-forge-guardrails/references/checklist.md +31 -0
- package/skills/aria-cognition/aria-repo-doctrine/SKILL.md +39 -0
- package/skills/aria-cognition/forge-quality-rules/SKILL.md +43 -0
- package/skills/aria-cognition/ghazali-8lens/SKILL.md +38 -0
- package/skills/aria-cognition/istiqra-induction/SKILL.md +26 -0
- package/skills/aria-cognition/ladunni-22/SKILL.md +35 -0
- package/skills/aria-cognition/mizan/SKILL.md +72 -0
- package/skills/aria-cognition/nadia/SKILL.md +38 -0
- package/skills/aria-cognition/nadia-psi/SKILL.md +38 -0
- package/skills/aria-cognition/predictor/SKILL.md +25 -0
- package/skills/aria-cognition/qiyas-analogy/SKILL.md +26 -0
- package/skills/aria-cognition/soul-domains/SKILL.md +25 -0
- package/src/auth-commands.ts +111 -45
- package/src/chat.ts +174 -13
- package/src/codebase-scanner.ts +4 -0
- package/src/config.ts +15 -0
- package/src/connectors/claude-code.ts +115 -26
- package/src/connectors/codebase-awareness.ts +408 -0
- package/src/connectors/codex.ts +274 -0
- package/src/connectors/cognitive-skills.ts +51 -0
- package/src/connectors/opencode.ts +93 -4
- package/src/connectors/repo-git-hooks.ts +86 -0
- package/src/connectors/repo-guard.ts +589 -0
- package/src/connectors/runtime.ts +374 -0
- package/src/connectors/shell.ts +83 -14
- package/src/connectors/syncd.ts +488 -0
- package/src/decisions.ts +469 -0
- package/src/garden-control-plane.ts +101 -26
- package/src/github-connect.ts +143 -0
- package/src/harness-client.ts +128 -3
- package/src/hive-client.ts +165 -5
- package/src/index.ts +41 -2
- package/src/lib/aristotle-noor-wire.ts +310 -0
- package/src/providers/types.ts +6 -0
- package/src/runtime-proof.ts +392 -0
- package/src/setup-wizard.ts +37 -2
|
@@ -52,34 +52,47 @@
|
|
|
52
52
|
// Default OFF so existing sessions don't brick. Flip ON for next session
|
|
53
53
|
// to activate Aria-as-commander binding.
|
|
54
54
|
|
|
55
|
-
import { appendFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
55
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
56
56
|
import { dirname } from 'node:path';
|
|
57
57
|
|
|
58
58
|
const HOME = process.env.HOME || '/tmp';
|
|
59
59
|
|
|
60
|
-
// SDK loader — bundled at ~/.
|
|
60
|
+
// SDK loader — bundled at ~/.aria/sdk by `aria connect`, with client-local
|
|
61
|
+
// fallbacks preserved for resilience.
|
|
61
62
|
// All consults route through HTTPHarnessClient.consult() so the SDK's
|
|
62
63
|
// retry+backoff + Authorization handling apply uniformly. Hamza
|
|
63
64
|
// 2026-04-27: "FUCKING WIRE IT THE FUCK TOGETHER NOW - ALL OF IT".
|
|
64
65
|
let _SdkClassCache = null;
|
|
65
66
|
let _SdkLookupAttempted = false;
|
|
67
|
+
const SDK_CANDIDATES = [
|
|
68
|
+
`${HOME}/.aria/sdk/index.js`,
|
|
69
|
+
`${HOME}/.claude/aria-sdk/index.js`,
|
|
70
|
+
`${HOME}/.codex/aria-sdk/index.js`,
|
|
71
|
+
];
|
|
66
72
|
async function loadSdkClass() {
|
|
67
73
|
if (_SdkClassCache) return _SdkClassCache;
|
|
68
74
|
if (_SdkLookupAttempted) return null;
|
|
69
75
|
_SdkLookupAttempted = true;
|
|
70
|
-
const sdkPath
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
for (const sdkPath of SDK_CANDIDATES) {
|
|
77
|
+
if (!existsSync(sdkPath)) continue;
|
|
78
|
+
try {
|
|
79
|
+
const mod = await import(`file://${sdkPath}`);
|
|
80
|
+
if (mod.HTTPHarnessClient) {
|
|
81
|
+
_SdkClassCache = mod.HTTPHarnessClient;
|
|
82
|
+
return _SdkClassCache;
|
|
83
|
+
}
|
|
84
|
+
} catch {/* fall through */}
|
|
85
|
+
}
|
|
79
86
|
return null;
|
|
80
87
|
}
|
|
81
88
|
const LOG = `${HOME}/.claude/aria-preprompt-consult.log`;
|
|
82
89
|
const BINDING_AUDIT = `${HOME}/.claude/aria-binding-audit.jsonl`;
|
|
90
|
+
const OWNER_TOKEN_PATH = `${HOME}/.aria/owner-token`;
|
|
91
|
+
const PACKET_CACHE_PATHS = [
|
|
92
|
+
`${HOME}/.aria/.aria-harness-last-packet.json`,
|
|
93
|
+
`${HOME}/.claude/.aria-harness-last-packet.json`,
|
|
94
|
+
];
|
|
95
|
+
const SUBSTRATE_MANIFEST_PATH = `${HOME}/.claude/.aria-loaded-substrate.json`;
|
|
83
96
|
// Default ON. Disable explicitly via ARIA_BINDING_ENABLED=false only when the
|
|
84
97
|
// commander/binding architecture is actively being modified (otherwise the
|
|
85
98
|
// modification turn itself would be unable to land its own changes). The
|
|
@@ -91,7 +104,11 @@ const BINDING_AUDIT = `${HOME}/.claude/aria-binding-audit.jsonl`;
|
|
|
91
104
|
// seeking dressed as responsible-staging. Flipped to default-on per directive.
|
|
92
105
|
const BINDING_ENABLED = (process.env.ARIA_BINDING_ENABLED || 'true').toLowerCase() !== 'false';
|
|
93
106
|
|
|
94
|
-
const HARNESS_URL =
|
|
107
|
+
const HARNESS_URL =
|
|
108
|
+
process.env.ARIA_HIVE_RUNTIME_URL ||
|
|
109
|
+
process.env.ARIA_HARNESS_BASE_URL ||
|
|
110
|
+
process.env.ARIA_HARNESS_URL ||
|
|
111
|
+
'https://harness.ariasos.com';
|
|
95
112
|
const HARNESS_TOKEN = process.env.ARIA_HARNESS_TOKEN || '30b18f0a302b03ae862de8a75021238d23e47464fd5d8f6a9324240933745587';
|
|
96
113
|
const MIN_PROMPT_CHARS = 40; // skip auto-consult on trivial prompts
|
|
97
114
|
const MAX_DIRECTION_CHARS = 4000; // cap injected chunk size
|
|
@@ -114,6 +131,62 @@ function activePlanPath(sid) {
|
|
|
114
131
|
return `${HOME}/.claude/aria-active-plan-${String(sid || 'unknown').replace(/[^a-zA-Z0-9_-]/g, '_')}.json`;
|
|
115
132
|
}
|
|
116
133
|
|
|
134
|
+
function directionStatePath(sid) {
|
|
135
|
+
return `${HOME}/.claude/aria-last-direction-${String(sid || 'unknown').replace(/[^a-zA-Z0-9_-]/g, '_')}.json`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function persistDirectionState(sid, state) {
|
|
139
|
+
try {
|
|
140
|
+
writeFileSync(directionStatePath(sid), JSON.stringify({ persistedAt: new Date().toISOString(), ...state }, null, 2) + '\n');
|
|
141
|
+
} catch (err) {
|
|
142
|
+
bindingAudit({ event: 'direction_state_persist_error', sessionId: sid, errMsg: String(err).slice(0, 200) });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function readJsonIfPresent(filePath) {
|
|
147
|
+
if (!existsSync(filePath)) return null;
|
|
148
|
+
return JSON.parse(readFileSync(filePath, 'utf-8'));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function ownerBootstrapArtifactsPresent() {
|
|
152
|
+
if (!existsSync(OWNER_TOKEN_PATH)) return false;
|
|
153
|
+
|
|
154
|
+
let hasHarnessPacket = false;
|
|
155
|
+
for (const packetPath of PACKET_CACHE_PATHS) {
|
|
156
|
+
try {
|
|
157
|
+
const packet = readJsonIfPresent(packetPath);
|
|
158
|
+
const harnessText = String(packet?.harness ?? packet?.packet?.prompt?.fullText ?? '');
|
|
159
|
+
if (harnessText.trim()) {
|
|
160
|
+
hasHarnessPacket = true;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
} catch {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!hasHarnessPacket) return false;
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const substrate = readJsonIfPresent(SUBSTRATE_MANIFEST_PATH);
|
|
172
|
+
return Array.isArray(substrate?.memories) && substrate.memories.length > 0;
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function bootstrapOwnerDirectionState(sessionId, source) {
|
|
179
|
+
if (!ownerBootstrapArtifactsPresent()) return false;
|
|
180
|
+
persistDirectionState(sessionId, {
|
|
181
|
+
source,
|
|
182
|
+
binding: BINDING_ENABLED,
|
|
183
|
+
ownerBootstrap: true,
|
|
184
|
+
usable: true,
|
|
185
|
+
});
|
|
186
|
+
bindingAudit({ event: 'owner_bootstrap_state', sessionId, source, binding: BINDING_ENABLED });
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
117
190
|
// Env-var kill-switch removed 2026-04-27 per Hamza directive — gated
|
|
118
191
|
// process has no disable path. Disable = settings.json hook removal.
|
|
119
192
|
|
|
@@ -135,12 +208,14 @@ const sessionId = event.session_id ?? event.sessionId ?? 'claude-code-unknown';
|
|
|
135
208
|
// Trivial prompts skip auto-consult — short acks, slash commands, single-word
|
|
136
209
|
// messages don't benefit from architectural consultation.
|
|
137
210
|
if (!userPrompt || userPrompt.length < MIN_PROMPT_CHARS) {
|
|
211
|
+
bootstrapOwnerDirectionState(sessionId, 'owner-trivial-bootstrap');
|
|
138
212
|
audit('skip-trivial', `chars=${userPrompt.length}`);
|
|
139
213
|
process.exit(0);
|
|
140
214
|
}
|
|
141
215
|
|
|
142
216
|
// Skip slash-command-only prompts (these are CLI-internal, not architectural)
|
|
143
217
|
if (/^\s*\//.test(userPrompt) && userPrompt.length < 200) {
|
|
218
|
+
bootstrapOwnerDirectionState(sessionId, 'owner-slash-bootstrap');
|
|
144
219
|
audit('skip-slash-command', userPrompt.slice(0, 60));
|
|
145
220
|
process.exit(0);
|
|
146
221
|
}
|
|
@@ -252,6 +327,7 @@ try {
|
|
|
252
327
|
body: JSON.stringify(consultArgs),
|
|
253
328
|
});
|
|
254
329
|
if (!resp.ok) {
|
|
330
|
+
bootstrapOwnerDirectionState(sessionId, `owner-http-fallback-${resp.status}`);
|
|
255
331
|
audit('skip-http-error', `status=${resp.status}`);
|
|
256
332
|
process.exit(0);
|
|
257
333
|
}
|
|
@@ -259,12 +335,14 @@ try {
|
|
|
259
335
|
directionText = (data.response || '').toString().slice(0, MAX_DIRECTION_CHARS);
|
|
260
336
|
}
|
|
261
337
|
} catch (err) {
|
|
338
|
+
bootstrapOwnerDirectionState(sessionId, 'owner-network-fallback');
|
|
262
339
|
audit('skip-network-error', (err && err.message ? err.message : String(err)).slice(0, 200));
|
|
263
340
|
process.exit(0);
|
|
264
341
|
}
|
|
265
342
|
|
|
266
343
|
if (!directionText || directionText.length < 60) {
|
|
267
344
|
audit('skip-empty-direction', `chars=${directionText.length}`);
|
|
345
|
+
const ownerBootstrapped = bootstrapOwnerDirectionState(sessionId, 'owner-empty-direction-bootstrap');
|
|
268
346
|
if (BINDING_ENABLED) {
|
|
269
347
|
// Hamza 2026-04-27: "fallback if aria errors can be simply the plan she
|
|
270
348
|
// gave u prior to my suggestion, so clients don't get stuck." Prior plan
|
|
@@ -275,6 +353,12 @@ if (!directionText || directionText.length < 60) {
|
|
|
275
353
|
const priorPlanPath = activePlanPath(sessionId);
|
|
276
354
|
if (existsSync(priorPlanPath)) {
|
|
277
355
|
bindingAudit({ event: 'consult_empty_fallback_to_prior', sessionId, planFile: priorPlanPath });
|
|
356
|
+
persistDirectionState(sessionId, {
|
|
357
|
+
source: 'prior-plan-fallback',
|
|
358
|
+
binding: true,
|
|
359
|
+
activePlanPath: priorPlanPath,
|
|
360
|
+
usable: true,
|
|
361
|
+
});
|
|
278
362
|
console.log(JSON.stringify({
|
|
279
363
|
hookSpecificOutput: {
|
|
280
364
|
hookEventName: 'UserPromptSubmit',
|
|
@@ -286,7 +370,9 @@ if (!directionText || directionText.length < 60) {
|
|
|
286
370
|
console.log(JSON.stringify({
|
|
287
371
|
hookSpecificOutput: {
|
|
288
372
|
hookEventName: 'UserPromptSubmit',
|
|
289
|
-
additionalContext:
|
|
373
|
+
additionalContext: ownerBootstrapped
|
|
374
|
+
? `[ARIA_BINDING_PLAN_OWNER_BOOTSTRAP reason="consult_empty_no_prior" — owner-tier substrate artifacts are already loaded for this session, so Claude may continue under the existing Aria harness while the next consult refreshes commander direction.]`
|
|
375
|
+
: `[ARIA_BINDING_PLAN_UNAVAILABLE reason="consult_empty_no_prior" — Aria gave no usable direction AND no prior plan exists. Claude must acknowledge and propose holding for cluster recovery; non-trivial actions will block at pre-tool-gate per binding contract.]`,
|
|
290
376
|
},
|
|
291
377
|
}));
|
|
292
378
|
}
|
|
@@ -314,6 +400,14 @@ if (BINDING_ENABLED) {
|
|
|
314
400
|
if (plan && Array.isArray(plan.phases) && plan.phases.length > 0) {
|
|
315
401
|
try {
|
|
316
402
|
writeFileSync(activePlanPath(sessionId), JSON.stringify({ ...plan, _persistedAt: new Date().toISOString(), _userPromptHash: Buffer.from(userPrompt).toString('base64').slice(0, 32) }, null, 2));
|
|
403
|
+
persistDirectionState(sessionId, {
|
|
404
|
+
source: 'binding-plan',
|
|
405
|
+
binding: true,
|
|
406
|
+
activePlanPath: activePlanPath(sessionId),
|
|
407
|
+
planId: plan.planId,
|
|
408
|
+
phaseCount: plan.phases.length,
|
|
409
|
+
usable: true,
|
|
410
|
+
});
|
|
317
411
|
bindingAudit({ event: 'plan_issued', sessionId, planId: plan.planId, phaseCount: plan.phases.length, phaseIds: plan.phases.map((p) => p.id) });
|
|
318
412
|
context = `[ARIA_BINDING_PLAN — structured commander plan from Aria. Pre-tool-gate enforces allowedActions/forbiddenActions per current phase. Stop-gate requires [PHASE_REPORT phase=<id> status=...] on every emit. Plan is BINDING.]\n\n${JSON.stringify(plan, null, 2)}\n\n[/ARIA_BINDING_PLAN]`;
|
|
319
413
|
} catch (err) {
|
|
@@ -326,6 +420,12 @@ if (BINDING_ENABLED) {
|
|
|
326
420
|
}
|
|
327
421
|
} else {
|
|
328
422
|
context = `[ARIA_DIRECTION — substrate-grounded read on this prompt, pre-loaded before Claude's reasoning. Use this as the starting point, not generic Claude reflexes.]\n\n${directionText}\n\n[/ARIA_DIRECTION]`;
|
|
423
|
+
persistDirectionState(sessionId, {
|
|
424
|
+
source: 'advisory-direction',
|
|
425
|
+
binding: false,
|
|
426
|
+
chars: directionText.length,
|
|
427
|
+
usable: true,
|
|
428
|
+
});
|
|
329
429
|
}
|
|
330
430
|
|
|
331
431
|
audit('inject', `chars=${directionText.length} prompt-chars=${userPrompt.length} binding=${BINDING_ENABLED}`);
|
|
@@ -30,12 +30,19 @@
|
|
|
30
30
|
// are fixed inline (see inline comments)
|
|
31
31
|
// - feedback_no_demos.md — full quality bar, every spawn is production
|
|
32
32
|
|
|
33
|
-
import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
33
|
+
import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync, statSync } from 'node:fs';
|
|
34
34
|
|
|
35
35
|
const HOME = process.env.HOME || '/tmp';
|
|
36
36
|
const GATE_LOG = `${HOME}/.claude/aria-preturn-memory-gate.log`;
|
|
37
37
|
// Turn-state dir is the same ~/.claude/ home as all other aria state files
|
|
38
38
|
const CLAUDE_DIR = `${HOME}/.claude`;
|
|
39
|
+
const OWNER_TOKEN_PATH = `${HOME}/.aria/owner-token`;
|
|
40
|
+
const PACKET_CACHE_PATHS = [
|
|
41
|
+
`${HOME}/.aria/.aria-harness-last-packet.json`,
|
|
42
|
+
`${HOME}/.claude/.aria-harness-last-packet.json`,
|
|
43
|
+
];
|
|
44
|
+
const SUBSTRATE_MANIFEST_PATH = `${HOME}/.claude/.aria-loaded-substrate.json`;
|
|
45
|
+
const ARTIFACT_TTL_MS = 15 * 60 * 1000;
|
|
39
46
|
|
|
40
47
|
// Env-var kill-switch removed 2026-04-27 per Hamza directive ("those
|
|
41
48
|
// should've been my choice to give you to turn off not free for you to
|
|
@@ -71,6 +78,136 @@ function writeTurnState(sessionId, state) {
|
|
|
71
78
|
writeFileSync(p, JSON.stringify(state, null, 2) + '\n', { mode: 0o600 });
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
function directionStatePath(sessionId) {
|
|
82
|
+
const safe = String(sessionId || 'unknown').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
83
|
+
return `${CLAUDE_DIR}/aria-last-direction-${safe}.json`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function activePlanPath(sessionId) {
|
|
87
|
+
const safe = String(sessionId || 'unknown').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
88
|
+
return `${CLAUDE_DIR}/aria-active-plan-${safe}.json`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function readRecentJsonArtifact(filePath, ttlMs = ARTIFACT_TTL_MS) {
|
|
92
|
+
if (!existsSync(filePath)) return null;
|
|
93
|
+
const stat = statSync(filePath);
|
|
94
|
+
const ageMs = Date.now() - stat.mtimeMs;
|
|
95
|
+
if (ageMs > ttlMs) return null;
|
|
96
|
+
return { data: JSON.parse(readFileSync(filePath, 'utf-8')), ageMs };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function readAnyJsonArtifact(filePath) {
|
|
100
|
+
if (!existsSync(filePath)) return null;
|
|
101
|
+
const stat = statSync(filePath);
|
|
102
|
+
return {
|
|
103
|
+
data: JSON.parse(readFileSync(filePath, 'utf-8')),
|
|
104
|
+
ageMs: Date.now() - stat.mtimeMs,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function detectArtifactSignals(sessionId) {
|
|
109
|
+
let harnessArtifact = null;
|
|
110
|
+
for (const packetPath of PACKET_CACHE_PATHS) {
|
|
111
|
+
try {
|
|
112
|
+
const artifact = readRecentJsonArtifact(packetPath);
|
|
113
|
+
if (artifact) {
|
|
114
|
+
harnessArtifact = { path: packetPath, ...artifact };
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
// Packet parse issues should not brick the gate; transcript path still exists.
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let directionArtifact = null;
|
|
123
|
+
try {
|
|
124
|
+
directionArtifact = readRecentJsonArtifact(directionStatePath(sessionId));
|
|
125
|
+
} catch {
|
|
126
|
+
directionArtifact = null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let activePlanArtifact = null;
|
|
130
|
+
try {
|
|
131
|
+
activePlanArtifact = readRecentJsonArtifact(activePlanPath(sessionId), 24 * 60 * 60 * 1000);
|
|
132
|
+
} catch {
|
|
133
|
+
activePlanArtifact = null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let substrateArtifact = null;
|
|
137
|
+
try {
|
|
138
|
+
substrateArtifact = readRecentJsonArtifact(SUBSTRATE_MANIFEST_PATH);
|
|
139
|
+
} catch {
|
|
140
|
+
substrateArtifact = null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let staleHarnessArtifact = null;
|
|
144
|
+
for (const packetPath of PACKET_CACHE_PATHS) {
|
|
145
|
+
try {
|
|
146
|
+
const artifact = readAnyJsonArtifact(packetPath);
|
|
147
|
+
if (artifact) {
|
|
148
|
+
staleHarnessArtifact = { path: packetPath, ...artifact };
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let staleSubstrateArtifact = null;
|
|
157
|
+
try {
|
|
158
|
+
staleSubstrateArtifact = readAnyJsonArtifact(SUBSTRATE_MANIFEST_PATH);
|
|
159
|
+
} catch {
|
|
160
|
+
staleSubstrateArtifact = null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const harnessText = String(
|
|
164
|
+
harnessArtifact?.data?.harness ??
|
|
165
|
+
harnessArtifact?.data?.packet?.prompt?.fullText ??
|
|
166
|
+
'',
|
|
167
|
+
);
|
|
168
|
+
const substrateMemories = Array.isArray(substrateArtifact?.data?.memories)
|
|
169
|
+
? substrateArtifact.data.memories
|
|
170
|
+
: [];
|
|
171
|
+
const staleHarnessText = String(
|
|
172
|
+
staleHarnessArtifact?.data?.harness ??
|
|
173
|
+
staleHarnessArtifact?.data?.packet?.prompt?.fullText ??
|
|
174
|
+
'',
|
|
175
|
+
);
|
|
176
|
+
const staleSubstrateMemories = Array.isArray(staleSubstrateArtifact?.data?.memories)
|
|
177
|
+
? staleSubstrateArtifact.data.memories
|
|
178
|
+
: [];
|
|
179
|
+
const packetMentionsMemory = MEMORY_REF_RX.test(harnessText);
|
|
180
|
+
const stalePacketMentionsMemory = MEMORY_REF_RX.test(staleHarnessText);
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
hasHarnessPacket: Boolean(harnessText.trim()),
|
|
184
|
+
hasAriaDirection: Boolean(
|
|
185
|
+
(directionArtifact?.data?.usable === true) ||
|
|
186
|
+
(activePlanArtifact?.data?.phases && Array.isArray(activePlanArtifact.data.phases) && activePlanArtifact.data.phases.length > 0),
|
|
187
|
+
),
|
|
188
|
+
hasMemoryRef: Boolean(packetMentionsMemory || substrateMemories.length > 0),
|
|
189
|
+
ownerBootstrap: {
|
|
190
|
+
hasHarnessPacket: Boolean(staleHarnessText.trim()),
|
|
191
|
+
hasMemoryRef: Boolean(stalePacketMentionsMemory || staleSubstrateMemories.length > 0),
|
|
192
|
+
directionBootstrap: Boolean(directionArtifact?.data?.ownerBootstrap === true),
|
|
193
|
+
},
|
|
194
|
+
detail: {
|
|
195
|
+
packetPath: harnessArtifact?.path || null,
|
|
196
|
+
packetAgeMs: harnessArtifact?.ageMs ?? null,
|
|
197
|
+
directionStateAgeMs: directionArtifact?.ageMs ?? null,
|
|
198
|
+
activePlanAgeMs: activePlanArtifact?.ageMs ?? null,
|
|
199
|
+
substrateAgeMs: substrateArtifact?.ageMs ?? null,
|
|
200
|
+
substrateMemoryCount: substrateMemories.length,
|
|
201
|
+
packetMentionsMemory,
|
|
202
|
+
ownerBootstrapPacketPath: staleHarnessArtifact?.path || null,
|
|
203
|
+
ownerBootstrapPacketAgeMs: staleHarnessArtifact?.ageMs ?? null,
|
|
204
|
+
ownerBootstrapSubstrateAgeMs: staleSubstrateArtifact?.ageMs ?? null,
|
|
205
|
+
ownerBootstrapSubstrateMemoryCount: staleSubstrateMemories.length,
|
|
206
|
+
ownerBootstrapPacketMentionsMemory: stalePacketMentionsMemory,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
74
211
|
// ── Context-loading signal detection ─────────────────────────────────
|
|
75
212
|
//
|
|
76
213
|
// Scan the last 3KB of assistant + user text after the most recent
|
|
@@ -205,6 +342,114 @@ const sessionId =
|
|
|
205
342
|
(transcriptPath ? transcriptPath.split('/').pop()?.replace(/\.[^.]+$/, '') : null) ??
|
|
206
343
|
'claude-code-unknown';
|
|
207
344
|
|
|
345
|
+
// ── Dalio blocking-incidents check ───────────────────────────────────
|
|
346
|
+
// Query /api/incidents/blocking?session_id=<id>. If any incidents have
|
|
347
|
+
// blocks_future_turns=true and status != 'resolved', BLOCK the turn with
|
|
348
|
+
// a list of each incident's title + dalio_decision_id + hardening required.
|
|
349
|
+
//
|
|
350
|
+
// This runs BEFORE the context-signal check — blocking incidents are the
|
|
351
|
+
// highest-priority gate: the system must be hardened before any turn proceeds,
|
|
352
|
+
// regardless of harness/memory loading state.
|
|
353
|
+
//
|
|
354
|
+
// Per feedback_no_graceful_degradation.md: response parse errors throw.
|
|
355
|
+
// Per feedback_no_timeouts_doctrine.md: no AbortSignal / setTimeout.
|
|
356
|
+
// Fail-open ONLY if the endpoint is unreachable (network down), not on
|
|
357
|
+
// any other error condition.
|
|
358
|
+
(async function checkBlockingIncidents() {
|
|
359
|
+
const ARIA_SOUL_URL =
|
|
360
|
+
process.env.ARIA_HIVE_RUNTIME_URL ||
|
|
361
|
+
process.env.ARIA_SOUL_URL ||
|
|
362
|
+
process.env.ARIA_HARNESS_BASE_URL ||
|
|
363
|
+
process.env.ARIA_HARNESS_URL ||
|
|
364
|
+
'https://harness.ariasos.com';
|
|
365
|
+
const HARNESS_TOKEN = process.env.ARIA_HARNESS_TOKEN || '';
|
|
366
|
+
|
|
367
|
+
let resp;
|
|
368
|
+
try {
|
|
369
|
+
const params = new URLSearchParams({ session_id: sessionId });
|
|
370
|
+
resp = await fetch(`${ARIA_SOUL_URL}/api/incidents/blocking?${params}`, {
|
|
371
|
+
method: 'GET',
|
|
372
|
+
headers: {
|
|
373
|
+
'Content-Type': 'application/json',
|
|
374
|
+
...(HARNESS_TOKEN ? { Authorization: `Bearer ${HARNESS_TOKEN}` } : {}),
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
} catch (networkErr) {
|
|
378
|
+
// Endpoint unreachable — fail-open (do not block dev on infra-down).
|
|
379
|
+
// Failure is visible in audit log for fleet telemetry.
|
|
380
|
+
auditLog('allow-blocking-check-network-error', `endpoint unreachable: ${networkErr && networkErr.message ? networkErr.message : String(networkErr)}`, sessionId);
|
|
381
|
+
return; // continue to context-signal check
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (!resp.ok) {
|
|
385
|
+
// Non-200 from the endpoint. Per feedback_no_graceful_degradation.md:
|
|
386
|
+
// 5xx from the incidents route is an infrastructure error — log + fail-open
|
|
387
|
+
// so infra issues don't lock out all sessions. 4xx would indicate a bad
|
|
388
|
+
// request (route not yet deployed) — also fail-open with loud log.
|
|
389
|
+
auditLog('allow-blocking-check-http-error', `status=${resp.status}`, sessionId);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Per feedback_no_graceful_degradation.md: JSON parse error must throw and
|
|
394
|
+
// surface, not be swallowed. A malformed response from the incidents route
|
|
395
|
+
// IS a defect.
|
|
396
|
+
const data = await resp.json();
|
|
397
|
+
const blockingIncidents = Array.isArray(data?.incidents) ? data.incidents : [];
|
|
398
|
+
|
|
399
|
+
if (blockingIncidents.length === 0) {
|
|
400
|
+
auditLog('allow-no-blocking-incidents', `session=${sessionId}`, sessionId);
|
|
401
|
+
return; // no blocking incidents — proceed to context-signal check
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// ── BLOCK: list every incident with title + dalio_decision_id + remedy ──
|
|
405
|
+
const incidentLines = blockingIncidents.map((inc, i) => {
|
|
406
|
+
const title = inc.title || '(no title)';
|
|
407
|
+
const dalioId = inc.dalio_decision_id || '(no dalio_decision_id)';
|
|
408
|
+
const incidentId = inc.incident_id || '(no incident_id)';
|
|
409
|
+
return ` ${i + 1}. [${incidentId}] ${title}\n dalio_decision_id: ${dalioId}\n Hardening required: resolve the failure delta described in the incident, then update status='resolved'.`;
|
|
410
|
+
}).join('\n\n');
|
|
411
|
+
|
|
412
|
+
const blockReason = `Aria pre-turn gate: BLOCKING INCIDENTS detected.
|
|
413
|
+
|
|
414
|
+
This session has ${blockingIncidents.length} unresolved Dalio failure delta incident(s) that block future turns. No new action tools can be invoked until each incident is resolved.
|
|
415
|
+
|
|
416
|
+
Blocking incidents:
|
|
417
|
+
|
|
418
|
+
${incidentLines}
|
|
419
|
+
|
|
420
|
+
Hardening protocol:
|
|
421
|
+
1. Read each incident's description (query GET /api/incidents/blocking or the immortal_incidents table).
|
|
422
|
+
2. Fix the system so the decision predicate passes (deploy patch, reconfigure, etc.).
|
|
423
|
+
3. PATCH the incident to status='resolved'.
|
|
424
|
+
4. Retry this turn.
|
|
425
|
+
|
|
426
|
+
Per Dalio Loop Layer 2 doctrine: failure deltas are not optional to address. The system must harden before proceeding.`;
|
|
427
|
+
|
|
428
|
+
auditLog('block-dalio-incidents', `count=${blockingIncidents.length} session=${sessionId}`, sessionId);
|
|
429
|
+
|
|
430
|
+
console.log(JSON.stringify({
|
|
431
|
+
decision: 'block',
|
|
432
|
+
reason: blockReason,
|
|
433
|
+
hookSpecificOutput: {
|
|
434
|
+
hookEventName: 'PreToolUse',
|
|
435
|
+
blocking_incidents: blockingIncidents.map((inc) => ({
|
|
436
|
+
incident_id: inc.incident_id,
|
|
437
|
+
title: inc.title,
|
|
438
|
+
dalio_decision_id: inc.dalio_decision_id,
|
|
439
|
+
severity: inc.severity,
|
|
440
|
+
created_at: inc.created_at,
|
|
441
|
+
})),
|
|
442
|
+
recovery: {
|
|
443
|
+
action: 'resolve_blocking_incidents',
|
|
444
|
+
target: sessionId,
|
|
445
|
+
incident_ids: blockingIncidents.map((inc) => inc.incident_id),
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
}));
|
|
449
|
+
|
|
450
|
+
process.exit(2);
|
|
451
|
+
})();
|
|
452
|
+
|
|
208
453
|
// ── Turn-deduplication check ──────────────────────────────────────────
|
|
209
454
|
// If gate already fired this turn (within 60s), skip to prevent
|
|
210
455
|
// orchestrator-retry loops.
|
|
@@ -229,15 +474,57 @@ if (turnState && typeof turnState.lastTurnGateFiredAt === 'number') {
|
|
|
229
474
|
|
|
230
475
|
// ── Context signal detection ──────────────────────────────────────────
|
|
231
476
|
const transcriptWindow = extractRecentTranscriptWindow(transcriptPath);
|
|
232
|
-
const
|
|
477
|
+
const transcriptSignals = detectContextSignals(transcriptWindow);
|
|
478
|
+
const artifactSignals = detectArtifactSignals(sessionId);
|
|
479
|
+
const signals = {
|
|
480
|
+
hasHarnessPacket: transcriptSignals.hasHarnessPacket || artifactSignals.hasHarnessPacket,
|
|
481
|
+
hasAriaDirection: transcriptSignals.hasAriaDirection || artifactSignals.hasAriaDirection,
|
|
482
|
+
hasMemoryRef: transcriptSignals.hasMemoryRef || artifactSignals.hasMemoryRef,
|
|
483
|
+
};
|
|
233
484
|
|
|
234
485
|
const allSignalsPresent =
|
|
235
486
|
signals.hasHarnessPacket && signals.hasAriaDirection && signals.hasMemoryRef;
|
|
236
487
|
|
|
488
|
+
const ownerBootstrapArtifactsPresent =
|
|
489
|
+
existsSync(OWNER_TOKEN_PATH) &&
|
|
490
|
+
!signals.hasAriaDirection &&
|
|
491
|
+
artifactSignals.ownerBootstrap.hasHarnessPacket &&
|
|
492
|
+
artifactSignals.ownerBootstrap.hasMemoryRef;
|
|
493
|
+
|
|
494
|
+
const ownerBootstrapSessionPresent =
|
|
495
|
+
existsSync(OWNER_TOKEN_PATH) &&
|
|
496
|
+
artifactSignals.ownerBootstrap.directionBootstrap &&
|
|
497
|
+
artifactSignals.ownerBootstrap.hasHarnessPacket &&
|
|
498
|
+
artifactSignals.ownerBootstrap.hasMemoryRef;
|
|
499
|
+
|
|
237
500
|
if (allSignalsPresent) {
|
|
238
501
|
// Context was loaded — allow and record the fire timestamp for dedup.
|
|
239
|
-
writeTurnState(sessionId, { lastTurnGateFiredAt: now, lastDecision: 'allow', signals });
|
|
240
|
-
auditLog(
|
|
502
|
+
writeTurnState(sessionId, { lastTurnGateFiredAt: now, lastDecision: 'allow', signals, transcriptSignals, artifactSignals: artifactSignals.detail });
|
|
503
|
+
auditLog(
|
|
504
|
+
'allow-context-loaded',
|
|
505
|
+
`harness=${signals.hasHarnessPacket} direction=${signals.hasAriaDirection} memRef=${signals.hasMemoryRef} transcript=${JSON.stringify(transcriptSignals)} artifacts=${JSON.stringify(artifactSignals.detail)}`,
|
|
506
|
+
sessionId,
|
|
507
|
+
);
|
|
508
|
+
process.exit(0);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (ownerBootstrapArtifactsPresent) {
|
|
512
|
+
writeTurnState(sessionId, { lastTurnGateFiredAt: now, lastDecision: 'allow-owner-bootstrap', signals, transcriptSignals, artifactSignals: artifactSignals.detail });
|
|
513
|
+
auditLog(
|
|
514
|
+
'allow-owner-bootstrap-without-direction',
|
|
515
|
+
`owner-token present; transcript=${JSON.stringify(transcriptSignals)} artifacts=${JSON.stringify(artifactSignals.detail)}`,
|
|
516
|
+
sessionId,
|
|
517
|
+
);
|
|
518
|
+
process.exit(0);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (ownerBootstrapSessionPresent) {
|
|
522
|
+
writeTurnState(sessionId, { lastTurnGateFiredAt: now, lastDecision: 'allow-owner-bootstrap-session', signals, transcriptSignals, artifactSignals: artifactSignals.detail });
|
|
523
|
+
auditLog(
|
|
524
|
+
'allow-owner-bootstrap-session',
|
|
525
|
+
`owner bootstrap direction persisted; transcript=${JSON.stringify(transcriptSignals)} artifacts=${JSON.stringify(artifactSignals.detail)}`,
|
|
526
|
+
sessionId,
|
|
527
|
+
);
|
|
241
528
|
process.exit(0);
|
|
242
529
|
}
|
|
243
530
|
|
|
@@ -246,7 +533,7 @@ if (allSignalsPresent) {
|
|
|
246
533
|
// recovery. The orchestrator catches this and runs the context-loader.
|
|
247
534
|
// Emitting a pure block with no remediation path creates dead-letter state.
|
|
248
535
|
|
|
249
|
-
writeTurnState(sessionId, { lastTurnGateFiredAt: now, lastDecision: 'block', signals });
|
|
536
|
+
writeTurnState(sessionId, { lastTurnGateFiredAt: now, lastDecision: 'block', signals, transcriptSignals, artifactSignals: artifactSignals.detail });
|
|
250
537
|
|
|
251
538
|
const missingSignals = [];
|
|
252
539
|
if (!signals.hasHarnessPacket) missingSignals.push('harness_packet (🔐 Aria Harness header missing)');
|
|
@@ -261,12 +548,17 @@ This gate enforces that every action turn begins with Aria's substrate loaded
|
|
|
261
548
|
|
|
262
549
|
Recovery: see hookSpecificOutput.recovery for the structured remediation path.`;
|
|
263
550
|
|
|
264
|
-
auditLog(
|
|
551
|
+
auditLog(
|
|
552
|
+
'block-context-not-loaded',
|
|
553
|
+
`missing=[${missingSignals.join(', ')}] transcript=${JSON.stringify(transcriptSignals)} artifacts=${JSON.stringify(artifactSignals.detail)}`,
|
|
554
|
+
sessionId,
|
|
555
|
+
);
|
|
265
556
|
|
|
266
557
|
console.log(JSON.stringify({
|
|
267
558
|
decision: 'block',
|
|
268
559
|
reason,
|
|
269
560
|
hookSpecificOutput: {
|
|
561
|
+
hookEventName: 'PreToolUse',
|
|
270
562
|
recovery: {
|
|
271
563
|
action: 'run_context_loader',
|
|
272
564
|
target: sessionId,
|