@ornexus/neocortex 4.60.78 → 4.60.80
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/dist/release-source.json +1 -1
- package/dist/sbom.cdx.json +1193 -1206
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +214 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +443 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +260 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +338 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +358 -5
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.js +635 -2
- package/packages/client/dist/commands/invoke.js +7712 -143
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.d.ts +3 -1
- package/packages/client/dist/commands/refresh-memory.js +174 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/host-auth-broker.js +60 -1
- package/packages/client/dist/config/host-auth-reference.js +93 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +105 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +258 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1456 -4
- package/packages/client/dist/git/epic-operational-state.js +672 -2
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.js +2188 -10
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/neocortex-trailers.d.ts +26 -0
- package/packages/client/dist/git/neocortex-trailers.js +53 -0
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +50 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/host-auth-recovery.js +401 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +337 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.d.ts +16 -1
- package/packages/client/dist/memory/project-memory-writer.js +1117 -41
- package/packages/client/dist/memory/shared-project-memory-types.js +259 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -3
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.js +393 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/registry/registry-reconciliation.js +234 -1
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/epic-background-dispatcher.js +124 -1
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/background-root.js +85 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +111 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1464 -10
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +357 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-environment-cleanup.js +274 -1
- package/packages/client/dist/runner/headless/managed-profile.js +149 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +886 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2586 -2
- package/packages/client/dist/runner/headless/types.js +575 -2
- package/packages/client/dist/runner/host-capacity.js +59 -1
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.js +1751 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.d.ts +1 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +245 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +184 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yoloop/epic-terminal-git.js +12 -0
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1,3 +1,174 @@
|
|
|
1
|
-
import{createHash
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstatSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { getProjectMemoryTarget, isProjectMemoryTargetId, listProjectMemoryTargets } from '../memory/shared-project-memory-types.js';
|
|
5
|
+
import { LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON, writeProjectMemoryTargetFiles, } from '../memory/project-memory-writer.js';
|
|
6
|
+
function parseCsv(value) {
|
|
7
|
+
return (value ?? '').split(',').map((entry) => entry.trim()).filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
export function parseRefreshMemoryArgs(args) {
|
|
10
|
+
let projectRoot = process.cwd();
|
|
11
|
+
let dryRun = false;
|
|
12
|
+
let verify = false;
|
|
13
|
+
const requestedTargets = [];
|
|
14
|
+
const memoryNotes = [];
|
|
15
|
+
for (let index = 0; index < args.length; index++) {
|
|
16
|
+
const arg = args[index];
|
|
17
|
+
if (arg === '--dry-run' || arg === '--preview') {
|
|
18
|
+
dryRun = true;
|
|
19
|
+
}
|
|
20
|
+
else if (arg === '--verify') {
|
|
21
|
+
verify = true;
|
|
22
|
+
dryRun = true;
|
|
23
|
+
}
|
|
24
|
+
else if (arg === '--project-root') {
|
|
25
|
+
projectRoot = args[++index] ?? projectRoot;
|
|
26
|
+
}
|
|
27
|
+
else if (arg.startsWith('--project-root=')) {
|
|
28
|
+
projectRoot = arg.slice('--project-root='.length);
|
|
29
|
+
}
|
|
30
|
+
else if (arg === '--target' || arg === '--targets') {
|
|
31
|
+
requestedTargets.push(...parseCsv(args[++index]));
|
|
32
|
+
}
|
|
33
|
+
else if (arg.startsWith('--target=')) {
|
|
34
|
+
requestedTargets.push(...parseCsv(arg.slice('--target='.length)));
|
|
35
|
+
}
|
|
36
|
+
else if (arg.startsWith('--targets=')) {
|
|
37
|
+
requestedTargets.push(...parseCsv(arg.slice('--targets='.length)));
|
|
38
|
+
}
|
|
39
|
+
else if (arg === '--note' || arg === '--memory-note' || arg === '--change') {
|
|
40
|
+
const note = args[++index];
|
|
41
|
+
if (note)
|
|
42
|
+
memoryNotes.push(note);
|
|
43
|
+
}
|
|
44
|
+
else if (arg.startsWith('--note=')) {
|
|
45
|
+
memoryNotes.push(arg.slice('--note='.length));
|
|
46
|
+
}
|
|
47
|
+
else if (arg.startsWith('--memory-note=')) {
|
|
48
|
+
memoryNotes.push(arg.slice('--memory-note='.length));
|
|
49
|
+
}
|
|
50
|
+
else if (arg.startsWith('--change=')) {
|
|
51
|
+
memoryNotes.push(arg.slice('--change='.length));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (verify && (requestedTargets.length > 0 || memoryNotes.length > 0)) {
|
|
55
|
+
throw new Error('Project memory verification requires all targets and no update notes.');
|
|
56
|
+
}
|
|
57
|
+
const targetIds = requestedTargets.length > 0
|
|
58
|
+
? requestedTargets.map((target) => {
|
|
59
|
+
if (!isProjectMemoryTargetId(target))
|
|
60
|
+
throw new Error(`Unknown project-memory target: ${target}`);
|
|
61
|
+
return target;
|
|
62
|
+
})
|
|
63
|
+
: ['canonical', ...listProjectMemoryTargets().map((target) => target.targetId)];
|
|
64
|
+
return { projectRoot: resolve(projectRoot), targetIds: Array.from(new Set(targetIds)), dryRun, verify, memoryNotes };
|
|
65
|
+
}
|
|
66
|
+
export function refreshProjectMemoryTargets(options) {
|
|
67
|
+
return options.targetIds.map((targetId) => writeProjectMemoryTargetFiles({
|
|
68
|
+
projectRoot: options.projectRoot,
|
|
69
|
+
targetId,
|
|
70
|
+
dryRun: options.dryRun,
|
|
71
|
+
memoryNotes: options.memoryNotes ?? [],
|
|
72
|
+
backupDirectory: options.backupDirectory,
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/** Deduplicated (by path) tracked legacy wrappers that refresh refused to delete. */
|
|
76
|
+
export function trackedLegacyAgentPathWrappers(results) {
|
|
77
|
+
const byPath = new Map();
|
|
78
|
+
for (const entry of results.flatMap((result) => result.legacyAgentPathWrappers ?? [])) {
|
|
79
|
+
if (entry.status === 'tracked-blocked' && !byPath.has(entry.relativeFile))
|
|
80
|
+
byPath.set(entry.relativeFile, entry);
|
|
81
|
+
}
|
|
82
|
+
return [...byPath.values()].sort((a, b) => a.relativeFile.localeCompare(b.relativeFile));
|
|
83
|
+
}
|
|
84
|
+
/** Root-only, read-only physical check; this is not independent stage QA or server authority. */
|
|
85
|
+
export function verifyProjectMemoryTargets(options) {
|
|
86
|
+
if (!options.verify || !options.dryRun || options.memoryNotes?.length
|
|
87
|
+
|| options.targetIds.join(',') !== ['canonical', ...listProjectMemoryTargets().map((target) => target.targetId)].join(',')) {
|
|
88
|
+
throw new Error('Project memory verification requires the complete read-only target set.');
|
|
89
|
+
}
|
|
90
|
+
const canonicalPath = join(options.projectRoot, 'NEOCORTEX.md');
|
|
91
|
+
let entry;
|
|
92
|
+
try {
|
|
93
|
+
entry = lstatSync(canonicalPath);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new Error('Canonical project memory is missing or unsafe.');
|
|
97
|
+
}
|
|
98
|
+
if (!entry.isFile() || entry.isSymbolicLink())
|
|
99
|
+
throw new Error('Canonical project memory must be a regular file.');
|
|
100
|
+
const canonical = readFileSync(canonicalPath, 'utf8');
|
|
101
|
+
const start = '<!-- NEOCORTEX-MEMORY-START -->';
|
|
102
|
+
const end = '<!-- NEOCORTEX-MEMORY-END -->';
|
|
103
|
+
const budget = getProjectMemoryTarget('canonical').budget;
|
|
104
|
+
if (canonical.split(start).length !== 2 || canonical.split(end).length !== 2
|
|
105
|
+
|| canonical.indexOf(start) >= canonical.indexOf(end)
|
|
106
|
+
|| Buffer.byteLength(canonical, 'utf8') > budget.maxBytes
|
|
107
|
+
|| canonical.split('\n').length > budget.maxLines) {
|
|
108
|
+
throw new Error('Canonical project memory markers or budget are invalid.');
|
|
109
|
+
}
|
|
110
|
+
const refreshed = refreshProjectMemoryTargets(options);
|
|
111
|
+
const files = refreshed.flatMap((result) => result.files);
|
|
112
|
+
const trackedBlocked = trackedLegacyAgentPathWrappers(refreshed);
|
|
113
|
+
if (trackedBlocked.length > 0) {
|
|
114
|
+
throw new Error(`Project memory verification blocked: ${LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON} ${trackedBlocked.map((entry) => `${entry.relativeFile} hint=${entry.remediation ?? `git rm ${entry.relativeFile}`}`).join('; ')}`);
|
|
115
|
+
}
|
|
116
|
+
if (refreshed.some((result) => (result.retiredFiles?.length ?? 0) > 0) || files.some((file) => file.changed || file.mode === 'compatibility-materialized-fallback'
|
|
117
|
+
|| file.fallbackReason || file.remediationDebt)) {
|
|
118
|
+
throw new Error('Project memory verification found stale or fallback targets.');
|
|
119
|
+
}
|
|
120
|
+
let projection;
|
|
121
|
+
try {
|
|
122
|
+
projection = [...new Set(files.map((file) => file.relativeFile))].sort()
|
|
123
|
+
.map((relativeFile) => {
|
|
124
|
+
const bytes = readFileSync(join(options.projectRoot, relativeFile));
|
|
125
|
+
const mode = files.find((file) => file.relativeFile === relativeFile).mode;
|
|
126
|
+
return `${relativeFile}:${mode}:${createHash('sha256').update(bytes).digest('hex')}`;
|
|
127
|
+
});
|
|
128
|
+
if (readFileSync(canonicalPath, 'utf8') !== canonical
|
|
129
|
+
|| refreshProjectMemoryTargets(options).some((result) => result.changed)) {
|
|
130
|
+
throw new Error('project-memory-verification-race');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
throw new Error('Project memory changed during verification.');
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
schemaVersion: 'ProjectMemoryVerification/1',
|
|
138
|
+
canonicalSha256: createHash('sha256').update(canonical).digest('hex'),
|
|
139
|
+
projectionSha256: createHash('sha256').update(projection.join('\n')).digest('hex'),
|
|
140
|
+
fileCount: projection.length,
|
|
141
|
+
publicSafe: true,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export async function refreshMemoryCliHandler(args) {
|
|
145
|
+
try {
|
|
146
|
+
const options = parseRefreshMemoryArgs(args);
|
|
147
|
+
if (options.verify) {
|
|
148
|
+
const verification = verifyProjectMemoryTargets(options);
|
|
149
|
+
console.log(`Project memory verified: files=${verification.fileCount} canonical_sha256=${verification.canonicalSha256} projection_sha256=${verification.projectionSha256}`);
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
const results = refreshProjectMemoryTargets(options);
|
|
153
|
+
const rows = results.flatMap((result) => result.files.map((file) => [
|
|
154
|
+
file.changed ? (options.dryRun ? 'would-change' : 'changed') : 'unchanged',
|
|
155
|
+
file.mode,
|
|
156
|
+
file.relativeFile,
|
|
157
|
+
file.fallbackReason ? `warning=${file.fallbackReason}` : undefined,
|
|
158
|
+
file.remediationDebt ? `debt=${file.remediationDebt}` : undefined,
|
|
159
|
+
file.reasonCodes && file.reasonCodes.length > 0 ? `reasons=${file.reasonCodes.join(',')}` : undefined,
|
|
160
|
+
].filter(Boolean).join(' ')));
|
|
161
|
+
const retiredRows = [...new Set(results.flatMap((result) => result.retiredFiles ?? []))]
|
|
162
|
+
.map((relativeFile) => `${options.dryRun ? 'would-retire' : 'retired'} legacy-agent-path-wrapper ${relativeFile}`);
|
|
163
|
+
const blockedRows = trackedLegacyAgentPathWrappers(results)
|
|
164
|
+
.map((entry) => `blocked ${LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON} ${entry.relativeFile} hint=${entry.remediation ?? `git rm ${entry.relativeFile}`}`);
|
|
165
|
+
console.log(`${options.dryRun ? 'Project memory preview' : 'Project memory refreshed'}: ${options.projectRoot}`);
|
|
166
|
+
for (const row of [...rows, ...retiredRows, ...blockedRows])
|
|
167
|
+
console.log(row);
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
const
|
|
1
|
+
export const ARCHITECTURE_PUBLIC_COMMANDS = Object.freeze([
|
|
2
|
+
'arch-prd', 'arch-architecture', 'arch-fitness-functions', 'arch-api-contracts', 'generate-pacts',
|
|
3
|
+
'arch-api-integrations', 'arch-database', 'arch-security', 'arch-design-system', 'arch-ux-design',
|
|
4
|
+
'arch-performance', 'arch-testing', 'arch-infrastructure', 'arch-review', 'update-memory',
|
|
5
|
+
]);
|
|
6
|
+
export const ARCHITECTURE_NON_UI_COMMANDS = Object.freeze(ARCHITECTURE_PUBLIC_COMMANDS
|
|
7
|
+
.filter(command => command !== 'arch-design-system' && command !== 'arch-ux-design'));
|
|
8
|
+
const EXCLUDED = Object.freeze(['arch-design-system', 'arch-ux-design']);
|
|
9
|
+
export function parseArchitectureNonUiScopeReceipt(value) {
|
|
10
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
11
|
+
return undefined;
|
|
12
|
+
const receipt = value;
|
|
13
|
+
if (Object.keys(receipt).sort().join(',') !== ['schemaVersion', 'kind', 'licenseHash', 'projectHash', 'targetEpicId',
|
|
14
|
+
'graphRevision', 'rootInputSha256', 'accountingId', 'applicability', 'excludedStageCommands', 'macSha256', 'publicSafe'].sort().join(',')
|
|
15
|
+
|| receipt.schemaVersion !== 1 || receipt.kind !== 'ArchitectureNonUiScope/1' || receipt.publicSafe !== true
|
|
16
|
+
|| receipt.applicability !== 'non-ui' || typeof receipt.targetEpicId !== 'string'
|
|
17
|
+
|| !/^P[1-9][0-9]{0,11}$/.test(receipt.targetEpicId) || typeof receipt.accountingId !== 'string'
|
|
18
|
+
|| !/^arch-accounting-[a-f0-9]{32}$/.test(receipt.accountingId)
|
|
19
|
+
|| !['licenseHash', 'projectHash', 'graphRevision', 'rootInputSha256', 'macSha256'].every(key => typeof receipt[key] === 'string' && /^[a-f0-9]{64}$/.test(receipt[key]))
|
|
20
|
+
|| !Array.isArray(receipt.excludedStageCommands) || receipt.excludedStageCommands.length !== EXCLUDED.length
|
|
21
|
+
|| !receipt.excludedStageCommands.every((command, index) => command === EXCLUDED[index]))
|
|
22
|
+
return undefined;
|
|
23
|
+
return Object.freeze({ ...receipt, excludedStageCommands: EXCLUDED });
|
|
24
|
+
}
|
|
@@ -1 +1,171 @@
|
|
|
1
|
-
import{readFile
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { acceptDirectYoloSetupCheckpoint, beginDirectYoloStoryCommit, finalizeDirectYoloStoryCheckpoint, issueDirectYoloSetupLeaseHandoff, prepareDirectYoloSetup, recoverLegacyDirectYoloStoryCheckpoint, } from '../git/direct-yolo-checkpoint.js';
|
|
4
|
+
import { applyDirectYoloC01Retry, inspectDirectYoloC01Retry } from '../git/direct-yolo-c01-retry.js';
|
|
5
|
+
export function parseStoryCheckpointArgs(args) {
|
|
6
|
+
const action = args[0];
|
|
7
|
+
if (action !== 'setup' && action !== 'accept-setup' && action !== 'handoff' && action !== 'begin' && action !== 'finalize' && action !== 'recover' && action !== 'retry-c01') {
|
|
8
|
+
throw new Error('story-checkpoint-action-invalid');
|
|
9
|
+
}
|
|
10
|
+
let storyId = '';
|
|
11
|
+
let projectRoot = process.cwd();
|
|
12
|
+
let commitSha;
|
|
13
|
+
let remote = 'origin';
|
|
14
|
+
let push = false;
|
|
15
|
+
let format = 'plain';
|
|
16
|
+
let setupHandoffSessionId;
|
|
17
|
+
let setupHandoffTokenFile;
|
|
18
|
+
let expectedHeadSha;
|
|
19
|
+
let apply = false;
|
|
20
|
+
for (let index = 1; index < args.length; index++) {
|
|
21
|
+
const arg = args[index];
|
|
22
|
+
const next = () => args[++index] ?? '';
|
|
23
|
+
if (arg === '--story')
|
|
24
|
+
storyId = next();
|
|
25
|
+
else if (arg.startsWith('--story='))
|
|
26
|
+
storyId = arg.slice('--story='.length);
|
|
27
|
+
else if (arg === '--project-root')
|
|
28
|
+
projectRoot = next() || projectRoot;
|
|
29
|
+
else if (arg.startsWith('--project-root='))
|
|
30
|
+
projectRoot = arg.slice('--project-root='.length);
|
|
31
|
+
else if (arg === '--commit')
|
|
32
|
+
commitSha = next();
|
|
33
|
+
else if (arg.startsWith('--commit='))
|
|
34
|
+
commitSha = arg.slice('--commit='.length);
|
|
35
|
+
else if (arg === '--remote')
|
|
36
|
+
remote = next();
|
|
37
|
+
else if (arg.startsWith('--remote='))
|
|
38
|
+
remote = arg.slice('--remote='.length);
|
|
39
|
+
else if (arg === '--push' || arg === '--require-remote')
|
|
40
|
+
push = true;
|
|
41
|
+
else if (arg === '--setup-handoff-session')
|
|
42
|
+
setupHandoffSessionId = next();
|
|
43
|
+
else if (arg.startsWith('--setup-handoff-session='))
|
|
44
|
+
setupHandoffSessionId = arg.slice('--setup-handoff-session='.length);
|
|
45
|
+
else if (arg === '--setup-handoff-token-file')
|
|
46
|
+
setupHandoffTokenFile = next();
|
|
47
|
+
else if (arg.startsWith('--setup-handoff-token-file='))
|
|
48
|
+
setupHandoffTokenFile = arg.slice('--setup-handoff-token-file='.length);
|
|
49
|
+
else if (arg === '--expected-head')
|
|
50
|
+
expectedHeadSha = next();
|
|
51
|
+
else if (arg.startsWith('--expected-head='))
|
|
52
|
+
expectedHeadSha = arg.slice('--expected-head='.length);
|
|
53
|
+
else if (arg === '--apply')
|
|
54
|
+
apply = true;
|
|
55
|
+
else if (arg === '--format') {
|
|
56
|
+
const value = next();
|
|
57
|
+
if (value !== 'json' && value !== 'plain')
|
|
58
|
+
throw new Error('story-checkpoint-format-invalid');
|
|
59
|
+
format = value;
|
|
60
|
+
}
|
|
61
|
+
else if (arg.startsWith('--format=')) {
|
|
62
|
+
const value = arg.slice('--format='.length);
|
|
63
|
+
if (value !== 'json' && value !== 'plain')
|
|
64
|
+
throw new Error('story-checkpoint-format-invalid');
|
|
65
|
+
format = value;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error('story-checkpoint-argument-invalid');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!storyId)
|
|
72
|
+
throw new Error('story-checkpoint-story-required');
|
|
73
|
+
if (action === 'recover' && !commitSha)
|
|
74
|
+
throw new Error('story-checkpoint-commit-required');
|
|
75
|
+
if (action === 'recover' && !push)
|
|
76
|
+
throw new Error('story-checkpoint-remote-proof-required');
|
|
77
|
+
if (action === 'finalize' && !push)
|
|
78
|
+
throw new Error('story-checkpoint-push-required');
|
|
79
|
+
if (action === 'begin' && (commitSha || push || remote !== 'origin'))
|
|
80
|
+
throw new Error('story-checkpoint-option-invalid');
|
|
81
|
+
if ((action === 'setup' || action === 'accept-setup' || action === 'handoff') && (commitSha || push || remote !== 'origin')) {
|
|
82
|
+
throw new Error('story-checkpoint-option-invalid');
|
|
83
|
+
}
|
|
84
|
+
if (action === 'finalize' && commitSha)
|
|
85
|
+
throw new Error('story-checkpoint-option-invalid');
|
|
86
|
+
if ((setupHandoffSessionId === undefined) !== (setupHandoffTokenFile === undefined)) {
|
|
87
|
+
throw new Error('story-checkpoint-setup-handoff-incomplete');
|
|
88
|
+
}
|
|
89
|
+
if (action !== 'begin' && (setupHandoffSessionId || setupHandoffTokenFile)) {
|
|
90
|
+
throw new Error('story-checkpoint-option-invalid');
|
|
91
|
+
}
|
|
92
|
+
if (action !== 'retry-c01' && (expectedHeadSha || apply))
|
|
93
|
+
throw new Error('story-checkpoint-option-invalid');
|
|
94
|
+
if (action === 'retry-c01' && (commitSha || push || remote !== 'origin'
|
|
95
|
+
|| apply && !/^[a-f0-9]{40,64}$/.test(expectedHeadSha ?? '')))
|
|
96
|
+
throw new Error('story-checkpoint-option-invalid');
|
|
97
|
+
return {
|
|
98
|
+
action, storyId, projectRoot: resolve(projectRoot), commitSha, remote, push, format,
|
|
99
|
+
...(expectedHeadSha ? { expectedHeadSha } : {}), ...(apply ? { apply } : {}),
|
|
100
|
+
...(setupHandoffSessionId ? { setupHandoffSessionId } : {}),
|
|
101
|
+
...(setupHandoffTokenFile ? { setupHandoffTokenFile: resolve(setupHandoffTokenFile) } : {}),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export async function storyCheckpointCliHandler(args) {
|
|
105
|
+
let options;
|
|
106
|
+
try {
|
|
107
|
+
options = parseStoryCheckpointArgs(args);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error(error instanceof Error ? error.message : 'story-checkpoint-arguments-invalid');
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
if (options.action === 'retry-c01') {
|
|
114
|
+
try {
|
|
115
|
+
const result = options.apply
|
|
116
|
+
? await applyDirectYoloC01Retry(options.projectRoot, options.storyId, options.expectedHeadSha)
|
|
117
|
+
: await inspectDirectYoloC01Retry(options.projectRoot, options.storyId);
|
|
118
|
+
console.log(options.format === 'json' ? JSON.stringify(result, null, 2)
|
|
119
|
+
: `story-checkpoint retry-c01: ${options.apply ? 'committed' : 'eligible'}`);
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error(error instanceof Error ? error.message : 'direct-yolo-retry-unverified');
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
let setupLeaseHandoff;
|
|
128
|
+
if (options.setupHandoffSessionId && options.setupHandoffTokenFile) {
|
|
129
|
+
try {
|
|
130
|
+
setupLeaseHandoff = {
|
|
131
|
+
sessionId: options.setupHandoffSessionId,
|
|
132
|
+
token: (await readFile(options.setupHandoffTokenFile, 'utf8')).trim(),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
console.error('story-checkpoint-setup-handoff-read-failed');
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const result = options.action === 'setup'
|
|
141
|
+
? await prepareDirectYoloSetup(options)
|
|
142
|
+
: options.action === 'accept-setup'
|
|
143
|
+
? await acceptDirectYoloSetupCheckpoint(options)
|
|
144
|
+
: options.action === 'handoff'
|
|
145
|
+
? await issueDirectYoloSetupLeaseHandoff(options)
|
|
146
|
+
: options.action === 'begin'
|
|
147
|
+
? await beginDirectYoloStoryCommit({ ...options, ...(setupLeaseHandoff ? { setupLeaseHandoff } : {}) })
|
|
148
|
+
: options.action === 'finalize'
|
|
149
|
+
? await finalizeDirectYoloStoryCheckpoint(options)
|
|
150
|
+
: await recoverLegacyDirectYoloStoryCheckpoint({
|
|
151
|
+
...options,
|
|
152
|
+
commitSha: options.commitSha,
|
|
153
|
+
});
|
|
154
|
+
if (options.format === 'json') {
|
|
155
|
+
console.log(JSON.stringify({ action: options.action, ...result }, null, 2));
|
|
156
|
+
}
|
|
157
|
+
else if (result.ok) {
|
|
158
|
+
console.log(`story-checkpoint ${options.action}: ok`);
|
|
159
|
+
if (options.action === 'begin' && 'trailers' in result.value) {
|
|
160
|
+
for (const trailer of result.value.trailers)
|
|
161
|
+
console.log(trailer);
|
|
162
|
+
}
|
|
163
|
+
else if ('headSha' in result.value) {
|
|
164
|
+
console.log(`head=${result.value.headSha}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
console.error(`story-checkpoint ${options.action}: ${result.reasonCode}`);
|
|
169
|
+
}
|
|
170
|
+
return result.ok ? 0 : 1;
|
|
171
|
+
}
|
|
@@ -1 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { parseHostAuthReference, } from './host-auth-reference.js';
|
|
3
|
+
function sameDigest(actual, expected) {
|
|
4
|
+
if (!/^[a-f0-9]{64}$/.test(actual) || !/^[a-f0-9]{64}$/.test(expected))
|
|
5
|
+
return false;
|
|
6
|
+
return timingSafeEqual(Buffer.from(actual, 'hex'), Buffer.from(expected, 'hex'));
|
|
7
|
+
}
|
|
8
|
+
export function createHostAuthBroker(adapter) {
|
|
9
|
+
const capability = Object.freeze(Object.create(null));
|
|
10
|
+
const authorities = new WeakSet([capability]);
|
|
11
|
+
let active = false;
|
|
12
|
+
const broker = Object.freeze({
|
|
13
|
+
async execute(request) {
|
|
14
|
+
if (!request.capability || !authorities.has(request.capability) || request.caller !== 'host-runtime') {
|
|
15
|
+
return { status: 'denied', reasonCode: 'host-auth-origin-denied' };
|
|
16
|
+
}
|
|
17
|
+
let reference;
|
|
18
|
+
try {
|
|
19
|
+
reference = parseHostAuthReference(request.reference);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return { status: 'denied', reasonCode: error instanceof Error ? error.message : 'host-auth-reference-invalid' };
|
|
23
|
+
}
|
|
24
|
+
if (!sameDigest(reference.subjectDigest, request.expectedSubjectDigest)
|
|
25
|
+
|| !sameDigest(reference.policyDigest, request.expectedPolicyDigest)
|
|
26
|
+
|| !sameDigest(reference.dispatchDigest, request.expectedDispatchDigest)) {
|
|
27
|
+
return { status: 'denied', reasonCode: 'host-auth-reference-invalid' };
|
|
28
|
+
}
|
|
29
|
+
if (reference.revocationEpoch < request.minimumRevocationEpoch) {
|
|
30
|
+
return { status: 'denied', reasonCode: 'host-auth-reference-revoked' };
|
|
31
|
+
}
|
|
32
|
+
if (!request.requiredScopes.every((scope) => reference.scopes.includes(scope))) {
|
|
33
|
+
return { status: 'denied', reasonCode: 'host-auth-scope-denied' };
|
|
34
|
+
}
|
|
35
|
+
if (!adapter)
|
|
36
|
+
return { status: 'unavailable', reasonCode: 'host-auth-capability-unavailable' };
|
|
37
|
+
if (adapter.provider !== reference.provider || adapter.target !== reference.target) {
|
|
38
|
+
return { status: 'denied', reasonCode: 'host-auth-target-denied' };
|
|
39
|
+
}
|
|
40
|
+
const operation = adapter.operations[reference.operation];
|
|
41
|
+
if (!operation)
|
|
42
|
+
return { status: 'denied', reasonCode: 'host-auth-operation-denied' };
|
|
43
|
+
if (active)
|
|
44
|
+
return { status: 'unavailable', reasonCode: 'host-auth-capability-unavailable' };
|
|
45
|
+
active = true;
|
|
46
|
+
try {
|
|
47
|
+
// Mutable reference checks are deliberately repeated immediately before effect.
|
|
48
|
+
parseHostAuthReference(reference);
|
|
49
|
+
if (reference.revocationEpoch < request.minimumRevocationEpoch) {
|
|
50
|
+
return { status: 'denied', reasonCode: 'host-auth-reference-revoked' };
|
|
51
|
+
}
|
|
52
|
+
return await operation(reference);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
active = false;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return Object.freeze({ broker, capability });
|
|
60
|
+
}
|
|
@@ -1 +1,93 @@
|
|
|
1
|
-
import{randomBytes
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
export const HOST_AUTH_REFERENCE_SCHEMA = 'HostAuthReference/1.0';
|
|
3
|
+
export const HOST_AUTH_REFERENCE_MAX_BYTES = 4_096;
|
|
4
|
+
export const HOST_AUTH_REFERENCE_MAX_TTL_MS = 60_000;
|
|
5
|
+
const DIGEST = /^[a-f0-9]{64}$/;
|
|
6
|
+
const ID = /^[A-Za-z0-9_-]{16,128}$/;
|
|
7
|
+
const TARGET = /^[a-z0-9][a-z0-9._:-]{0,127}$/;
|
|
8
|
+
const SCOPE = /^[a-z][a-z0-9._:-]{0,79}$/;
|
|
9
|
+
const PROVIDERS = new Set(['codex', 'opencode']);
|
|
10
|
+
const OPERATIONS = new Set([
|
|
11
|
+
'inspect-session',
|
|
12
|
+
'prepare-license-auth',
|
|
13
|
+
'reconcile-license-auth',
|
|
14
|
+
'authorize-business-replay',
|
|
15
|
+
]);
|
|
16
|
+
const KEYS = [
|
|
17
|
+
'schemaVersion', 'referenceId', 'provider', 'authDomain', 'target', 'operation',
|
|
18
|
+
'scopes', 'issuedAt', 'expiresAt', 'revocationEpoch', 'subjectDigest',
|
|
19
|
+
'policyDigest', 'dispatchDigest',
|
|
20
|
+
];
|
|
21
|
+
export class HostAuthReferenceError extends Error {
|
|
22
|
+
reasonCode;
|
|
23
|
+
constructor(reasonCode) {
|
|
24
|
+
super(reasonCode);
|
|
25
|
+
this.reasonCode = reasonCode;
|
|
26
|
+
this.name = 'HostAuthReferenceError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function deny(reasonCode) {
|
|
30
|
+
throw new HostAuthReferenceError(reasonCode);
|
|
31
|
+
}
|
|
32
|
+
export function parseHostAuthReference(input, options = {}) {
|
|
33
|
+
let value = input;
|
|
34
|
+
if (typeof input === 'string') {
|
|
35
|
+
if (Buffer.byteLength(input, 'utf8') > HOST_AUTH_REFERENCE_MAX_BYTES)
|
|
36
|
+
deny('host-auth-reference-oversized');
|
|
37
|
+
try {
|
|
38
|
+
value = JSON.parse(input);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
deny('host-auth-reference-invalid');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
45
|
+
deny('host-auth-reference-invalid');
|
|
46
|
+
const raw = value;
|
|
47
|
+
const keys = Object.keys(raw);
|
|
48
|
+
if (keys.length !== KEYS.length || keys.some((key) => !KEYS.includes(key))) {
|
|
49
|
+
deny('host-auth-reference-invalid');
|
|
50
|
+
}
|
|
51
|
+
if (raw.schemaVersion !== HOST_AUTH_REFERENCE_SCHEMA || raw.authDomain !== 'model-provider')
|
|
52
|
+
deny('host-auth-reference-invalid');
|
|
53
|
+
if (typeof raw.provider !== 'string' || !PROVIDERS.has(raw.provider))
|
|
54
|
+
deny('host-auth-reference-invalid');
|
|
55
|
+
if (typeof raw.operation !== 'string' || !OPERATIONS.has(raw.operation))
|
|
56
|
+
deny('host-auth-operation-denied');
|
|
57
|
+
if (typeof raw.referenceId !== 'string' || !ID.test(raw.referenceId)
|
|
58
|
+
|| typeof raw.target !== 'string' || !TARGET.test(raw.target)
|
|
59
|
+
|| typeof raw.subjectDigest !== 'string' || !DIGEST.test(raw.subjectDigest)
|
|
60
|
+
|| typeof raw.policyDigest !== 'string' || !DIGEST.test(raw.policyDigest)
|
|
61
|
+
|| typeof raw.dispatchDigest !== 'string' || !DIGEST.test(raw.dispatchDigest))
|
|
62
|
+
deny('host-auth-reference-invalid');
|
|
63
|
+
if (!Array.isArray(raw.scopes) || raw.scopes.length === 0 || raw.scopes.length > 16
|
|
64
|
+
|| raw.scopes.some((scope) => typeof scope !== 'string' || !SCOPE.test(scope))
|
|
65
|
+
|| new Set(raw.scopes).size !== raw.scopes.length)
|
|
66
|
+
deny('host-auth-scope-denied');
|
|
67
|
+
if (!Number.isSafeInteger(raw.revocationEpoch) || raw.revocationEpoch < 0)
|
|
68
|
+
deny('host-auth-reference-invalid');
|
|
69
|
+
const issuedAt = Date.parse(String(raw.issuedAt));
|
|
70
|
+
const expiresAt = Date.parse(String(raw.expiresAt));
|
|
71
|
+
if (!Number.isFinite(issuedAt) || !Number.isFinite(expiresAt) || expiresAt <= issuedAt
|
|
72
|
+
|| expiresAt - issuedAt > HOST_AUTH_REFERENCE_MAX_TTL_MS)
|
|
73
|
+
deny('host-auth-reference-invalid');
|
|
74
|
+
const now = options.now ?? Date.now();
|
|
75
|
+
if (issuedAt > now + 30_000 || (!options.allowExpired && expiresAt <= now))
|
|
76
|
+
deny('host-auth-reference-expired');
|
|
77
|
+
const encoded = JSON.stringify(raw);
|
|
78
|
+
if (Buffer.byteLength(encoded, 'utf8') > HOST_AUTH_REFERENCE_MAX_BYTES)
|
|
79
|
+
deny('host-auth-reference-oversized');
|
|
80
|
+
return Object.freeze({ ...raw, scopes: Object.freeze([...raw.scopes]) });
|
|
81
|
+
}
|
|
82
|
+
export function createHostAuthReference(input) {
|
|
83
|
+
const now = input.now ?? Date.now();
|
|
84
|
+
const ttlMs = input.ttlMs ?? 30_000;
|
|
85
|
+
const { now: _now, ttlMs: _ttl, ...fields } = input;
|
|
86
|
+
return parseHostAuthReference({
|
|
87
|
+
schemaVersion: HOST_AUTH_REFERENCE_SCHEMA,
|
|
88
|
+
referenceId: randomBytes(18).toString('base64url'),
|
|
89
|
+
...fields,
|
|
90
|
+
issuedAt: new Date(now).toISOString(),
|
|
91
|
+
expiresAt: new Date(now + ttlMs).toISOString(),
|
|
92
|
+
}, { now });
|
|
93
|
+
}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{homedir
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { basename, isAbsolute, join, normalize } from 'node:path';
|
|
3
|
+
/** Explicit isolated profile for local integration runs; the default remains unchanged. */
|
|
4
|
+
export function neocortexProfileDirectory() {
|
|
5
|
+
const override = process.env.NEOCORTEX_PROFILE_DIR;
|
|
6
|
+
if (override === undefined)
|
|
7
|
+
return join(homedir(), '.neocortex');
|
|
8
|
+
const normalized = normalize(override);
|
|
9
|
+
if (!isAbsolute(override) || /[\r\n\0]/.test(override) || basename(normalized) !== '.neocortex') {
|
|
10
|
+
throw new Error('neocortex-profile-dir-invalid');
|
|
11
|
+
}
|
|
12
|
+
return normalized;
|
|
13
|
+
}
|