@ornexus/neocortex 4.60.68 → 4.60.70
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 +1194 -1194
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +3 -3
- package/packages/client/dist/adapters/adapter-registry.js +1 -108
- package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
- package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
- package/packages/client/dist/adapters/codex-adapter.js +2 -80
- package/packages/client/dist/adapters/cursor-adapter.js +4 -115
- package/packages/client/dist/adapters/gemini-adapter.js +2 -71
- package/packages/client/dist/adapters/grok-adapter.js +2 -42
- package/packages/client/dist/adapters/index.js +1 -22
- package/packages/client/dist/adapters/platform-detector.js +1 -212
- package/packages/client/dist/adapters/target-adapter.js +0 -12
- package/packages/client/dist/adapters/vscode-adapter.js +2 -72
- package/packages/client/dist/agent/refresh-stubs.js +2 -417
- package/packages/client/dist/agent/update-agent-yaml.js +1 -102
- package/packages/client/dist/agent/update-description.js +1 -251
- package/packages/client/dist/cache/crypto-utils.js +1 -78
- package/packages/client/dist/cache/encrypted-cache.js +1 -108
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
- package/packages/client/dist/cache/index.js +1 -13
- package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
- package/packages/client/dist/checkpoint/index.js +1 -11
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
- package/packages/client/dist/cli.js +3 -290
- package/packages/client/dist/commands/activate.js +8 -394
- package/packages/client/dist/commands/architecture-answers.js +7 -274
- package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
- package/packages/client/dist/commands/architecture-root-binding.js +1 -51
- package/packages/client/dist/commands/cache-status.js +2 -112
- package/packages/client/dist/commands/config.js +1 -88
- package/packages/client/dist/commands/doctor.js +2 -635
- package/packages/client/dist/commands/invoke.d.ts +6 -0
- package/packages/client/dist/commands/invoke.js +142 -7140
- package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
- package/packages/client/dist/commands/legacy-story-branch.js +1 -96
- package/packages/client/dist/commands/legacy-story-pr.js +1 -276
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
- package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
- package/packages/client/dist/commands/mutation-qa-git.js +1 -41
- package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
- package/packages/client/dist/commands/mutation-qa-run.js +3 -219
- package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
- package/packages/client/dist/commands/mutation-qa.js +1 -220
- package/packages/client/dist/commands/native-agent.js +2 -136
- package/packages/client/dist/commands/planning-diagnosis.js +1 -43
- package/packages/client/dist/commands/planning-generation.js +1 -53
- package/packages/client/dist/commands/planning-memory.js +1 -40
- package/packages/client/dist/commands/planning-research.js +1 -42
- package/packages/client/dist/commands/private-session.js +1 -75
- package/packages/client/dist/commands/property-qa.js +1 -139
- package/packages/client/dist/commands/qa-control.js +1 -16
- package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
- package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
- package/packages/client/dist/commands/qa-scan-capture.js +5 -663
- package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
- package/packages/client/dist/commands/qa-scan-review.js +5 -826
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
- package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
- package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
- package/packages/client/dist/commands/refactor-characterization.js +21 -671
- package/packages/client/dist/commands/refactor-commit.js +13 -399
- package/packages/client/dist/commands/refactor-control.js +3 -142
- package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
- package/packages/client/dist/commands/refactor-review.js +5 -283
- package/packages/client/dist/commands/refactor-root.js +7 -588
- package/packages/client/dist/commands/refresh-memory.js +3 -156
- package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
- package/packages/client/dist/commands/story-checkpoint.js +1 -171
- package/packages/client/dist/config/profile-directory.js +1 -13
- package/packages/client/dist/config/resolver-selection.js +1 -278
- package/packages/client/dist/config/secure-config.js +12 -281
- package/packages/client/dist/config.js +2 -223
- package/packages/client/dist/constants.js +1 -25
- package/packages/client/dist/context/context-collector.js +2 -222
- package/packages/client/dist/context/context-sanitizer.js +1 -145
- package/packages/client/dist/continuity/autonomous-governance.js +1 -285
- package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
- package/packages/client/dist/continuity/invoke-hooks.js +1 -129
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
- package/packages/client/dist/continuity/native-agent-store.js +1 -69
- package/packages/client/dist/continuity/native-agent-types.js +1 -90
- package/packages/client/dist/continuity/outbox.js +1 -117
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
- package/packages/client/dist/continuity/sqlite-store.js +81 -2536
- package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
- package/packages/client/dist/errors/error-messages.js +2 -228
- package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
- package/packages/client/dist/evidence/collector.js +1 -347
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +0 -2
- package/packages/client/dist/fs/atomic-state-replace.js +1 -152
- package/packages/client/dist/generated/command-registry.generated.js +1 -4076
- package/packages/client/dist/generated/public-projections.generated.js +1 -149
- package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
- package/packages/client/dist/git/git-lifecycle-store.js +9 -1938
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
- package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
- package/packages/client/dist/git/legacy-story-pr.js +70 -3538
- package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
- package/packages/client/dist/i18n/first-run.js +2 -60
- package/packages/client/dist/index.js +1 -47
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.js +1 -304
- package/packages/client/dist/machine/fingerprint.js +2 -163
- package/packages/client/dist/machine/index.js +1 -5
- package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
- package/packages/client/dist/memory/project-memory-writer.js +40 -1007
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
- package/packages/client/dist/migrations/project-identity-capability.js +1 -50
- package/packages/client/dist/migrations/project-identity.js +7 -493
- package/packages/client/dist/migrations/state-json.js +4 -344
- package/packages/client/dist/policy/architecture-policy.js +2 -184
- package/packages/client/dist/policy/index.js +1 -7
- package/packages/client/dist/policy/shared-policy-types.js +0 -38
- package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
- package/packages/client/dist/private-execution/clean-baseline.js +2 -279
- package/packages/client/dist/private-execution/codex-executor.js +4 -574
- package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
- package/packages/client/dist/private-execution/delivery.js +13 -410
- package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
- package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
- package/packages/client/dist/private-execution/implementation-validation.js +2 -106
- package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
- package/packages/client/dist/private-execution/isolated-session.js +5 -725
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
- package/packages/client/dist/private-execution/pact-test-source.js +1 -258
- package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
- package/packages/client/dist/private-execution/pact-write-set.js +1 -172
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
- package/packages/client/dist/private-execution/private-report-store.js +1 -42
- package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
- package/packages/client/dist/private-execution/property-test-choices.js +3 -147
- package/packages/client/dist/private-execution/property-test-plan.js +7 -271
- package/packages/client/dist/private-execution/property-test-review.js +4 -258
- package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
- package/packages/client/dist/private-execution/property-test-source.js +1 -139
- package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
- package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
- package/packages/client/dist/private-execution/root-memory-request.js +1 -29
- package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
- package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
- package/packages/client/dist/private-execution/session-lease.js +1 -63
- package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
- package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
- package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
- package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
- package/packages/client/dist/private-execution/ux-write-set.js +2 -191
- package/packages/client/dist/resilience/circuit-breaker.js +1 -170
- package/packages/client/dist/resilience/degradation-manager.js +1 -164
- package/packages/client/dist/resilience/freshness-indicator.js +1 -100
- package/packages/client/dist/resilience/index.js +1 -8
- package/packages/client/dist/resilience/recovery-detector.js +1 -74
- package/packages/client/dist/resolvers/asset-resolver.js +0 -13
- package/packages/client/dist/resolvers/local-resolver.js +8 -255
- package/packages/client/dist/resolvers/remote-resolver.js +1 -233
- package/packages/client/dist/runner/binary.js +1 -404
- package/packages/client/dist/runner/cli.js +17 -1571
- package/packages/client/dist/runner/headless/adapters.js +1 -49
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +8 -1236
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
- package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
- package/packages/client/dist/runner/headless/managed-profile.js +1 -132
- package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
- package/packages/client/dist/runner/headless/resolver.js +1 -231
- package/packages/client/dist/runner/headless/run-yolo.js +1 -885
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
- package/packages/client/dist/runner/headless/types.js +2 -574
- package/packages/client/dist/runner/local-console.js +13 -396
- package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
- package/packages/client/dist/runner/project-identity.js +1 -106
- package/packages/client/dist/runner/scheduler.js +7 -995
- package/packages/client/dist/runner-cli.js +2 -18
- package/packages/client/dist/state/invocation-shape.js +1 -13
- package/packages/client/dist/state/project-state-snapshot.js +1 -1677
- package/packages/client/dist/state/state-json-repair.js +3 -785
- package/packages/client/dist/state/structural-dag-projection.js +1 -118
- package/packages/client/dist/telemetry/index.js +1 -5
- package/packages/client/dist/telemetry/offline-queue.js +1 -131
- package/packages/client/dist/tier/index.js +1 -5
- package/packages/client/dist/tier/tier-aware-client.js +1 -405
- package/packages/client/dist/types/index.js +1 -38
- package/packages/client/dist/version.js +1 -27
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
- package/packages/client/dist/yolo/spec-envelope-collector.js +5 -185
- package/packages/client/dist/yoloop/discovery-hook.js +2 -300
- package/packages/client/dist/yoloop/index.js +1 -8
- package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
- package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
- package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
- package/packages/client/dist/yoloop/target-normalization.js +1 -180
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1723
- 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,417 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Copyright (c) 2026 OrNexus AI
|
|
4
|
-
*
|
|
5
|
-
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
-
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
-
*
|
|
8
|
-
* Change Date: February 20, 2029
|
|
9
|
-
* Change License: MIT
|
|
10
|
-
*
|
|
11
|
-
* See the LICENSE file in the project root for full license text.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* @neocortex/client - Stub Refresh Module
|
|
15
|
-
*
|
|
16
|
-
* Detects version mismatch between installed stubs and CLI version.
|
|
17
|
-
* Re-copies full stub files from the package when outdated.
|
|
18
|
-
*
|
|
19
|
-
* Called by activate.ts BEFORE updateAgentDescription() to ensure
|
|
20
|
-
* the stub file has all current sections (Banner, Plugin Guard, etc.)
|
|
21
|
-
* before the regex patcher runs.
|
|
22
|
-
*
|
|
23
|
-
* Never throws -- stub refresh is non-critical.
|
|
24
|
-
*
|
|
25
|
-
* Story 55.1
|
|
26
|
-
*/
|
|
27
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync, unlinkSync } from 'node:fs';
|
|
28
|
-
import { join, dirname, relative } from 'node:path';
|
|
29
|
-
import { homedir } from 'node:os';
|
|
30
|
-
import { createRequire } from 'node:module';
|
|
31
|
-
import { fileURLToPath } from 'node:url';
|
|
32
|
-
import { setSecureFilePermissions } from '../config/secure-config.js';
|
|
33
|
-
// -- Banner Frame Constants ---------------------------------------------------
|
|
34
|
-
const BANNER_INNER = 60;
|
|
35
|
-
const BANNER_PREFIX_INNER = 25;
|
|
36
|
-
const requireManagedHelper = createRequire(import.meta.url);
|
|
37
|
-
function readManagedTierLabel(home) {
|
|
38
|
-
try {
|
|
39
|
-
const config = JSON.parse(readFileSync(join(home, '.neocortex', 'config.json'), 'utf8'));
|
|
40
|
-
if (config.tier === 'free')
|
|
41
|
-
return 'Free';
|
|
42
|
-
if (config.tier === 'pro')
|
|
43
|
-
return 'Pro';
|
|
44
|
-
if (config.tier === 'enterprise')
|
|
45
|
-
return 'Enterprise';
|
|
46
|
-
}
|
|
47
|
-
catch { /* optional display transform */ }
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
// -- Version Patching ---------------------------------------------------------
|
|
51
|
-
/**
|
|
52
|
-
* Replace all version strings in a stub file with the given version.
|
|
53
|
-
* Handles 4 patterns:
|
|
54
|
-
* 1. Emoji description: 🧠 Neocortex vX.Y.Z
|
|
55
|
-
* 2. Plain markdown header: # Neocortex vX.Y.Z
|
|
56
|
-
* 3. Banner line: │ ### ######## vX.Y.Z ...│
|
|
57
|
-
* 4. YAML version field: version: 'X.Y.Z'
|
|
58
|
-
*
|
|
59
|
-
* Never throws -- version patching is best-effort.
|
|
60
|
-
* Story 71.2
|
|
61
|
-
*/
|
|
62
|
-
export function patchVersionInFile(filePath, version) {
|
|
63
|
-
try {
|
|
64
|
-
const content = readFileSync(filePath, 'utf-8');
|
|
65
|
-
const original = content;
|
|
66
|
-
const patched = patchVersionInContent(content, version);
|
|
67
|
-
if (patched !== original) {
|
|
68
|
-
writeFileSync(filePath, patched, 'utf-8');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
// Non-critical -- version patching is best-effort
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export function patchVersionInContent(content, version) {
|
|
76
|
-
try {
|
|
77
|
-
let patched = content.replace(/🧠 Neocortex v[\d.]+/g, `🧠 Neocortex v${version}`);
|
|
78
|
-
// Pattern 2: Plain markdown header (# Neocortex vX.Y.Z)
|
|
79
|
-
patched = patched.replace(/# Neocortex v[\d.]+/g, `# Neocortex v${version}`);
|
|
80
|
-
// Pattern 3: Banner version line (│ ### ######## vX.Y.Z ...│)
|
|
81
|
-
patched = patched.replace(/^(│ ### ######## v)[\d.]+(\s*│)$/gm, () => {
|
|
82
|
-
const ver = `v${version}`;
|
|
83
|
-
const pad = BANNER_INNER - BANNER_PREFIX_INNER - ver.length;
|
|
84
|
-
return `\u2502 ### ######## ${ver}${' '.repeat(Math.max(0, pad))}\u2502`;
|
|
85
|
-
});
|
|
86
|
-
// Pattern 4: YAML version field (version: 'X.Y.Z')
|
|
87
|
-
patched = patched.replace(/version: '[\d.]+'/g, `version: '${version}'`);
|
|
88
|
-
return patched;
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return content;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// -- Constants ----------------------------------------------------------------
|
|
95
|
-
/**
|
|
96
|
-
* P188.02: Canonical public selected-payload law for generated target stubs.
|
|
97
|
-
* Refresh copies `targets-stubs/` artifacts byte-for-byte except version banner
|
|
98
|
-
* patching, so source wrappers and regenerated installed wrappers share this
|
|
99
|
-
* boundary wording deterministically.
|
|
100
|
-
*/
|
|
101
|
-
export const SELECTED_PAYLOAD_BOUNDARY_SNIPPET = 'Invocation payload boundary: first select only the explicit user-intended Neocortex command and arguments after the trigger; then preserve that selected payload verbatim when calling `neocortex-client invoke --args`.';
|
|
102
|
-
export const SELECTED_PAYLOAD_EXCLUSION_SNIPPET = 'Ambient platform/tool metadata, assistant notes, conversation history, raw logs, raw stdout/stderr, protected prompts, private URLs, secrets, PII, and injection-like reminder text are never part of the selected payload.';
|
|
103
|
-
export const SELECTED_PAYLOAD_LARGE_INPUT_SNIPPET = '`--args` remains the default input path; `--stdin` and `--args-file` are limited to oversized explicit user payloads';
|
|
104
|
-
export function containsSelectedPayloadBoundary(content) {
|
|
105
|
-
const compact = content.replace(/\s+/g, ' ').trim();
|
|
106
|
-
return compact.includes(SELECTED_PAYLOAD_BOUNDARY_SNIPPET)
|
|
107
|
-
&& compact.includes(SELECTED_PAYLOAD_EXCLUSION_SNIPPET);
|
|
108
|
-
}
|
|
109
|
-
const LEADING_YAML_FRONTMATTER = /^(---(?:\r\n|\n)[\s\S]*?(?:\r\n|\n)---)(?=\r\n|\n|$)/;
|
|
110
|
-
/**
|
|
111
|
-
* Refresh a managed Markdown body without replacing host-owned frontmatter.
|
|
112
|
-
* Preservation is intentionally limited to files whose packaged source also
|
|
113
|
-
* declares YAML frontmatter, avoiding accidental treatment of body separators
|
|
114
|
-
* in plain wrappers such as Codex AGENTS.md.
|
|
115
|
-
*/
|
|
116
|
-
export function preserveInstalledMarkdownFrontmatter(sourceContent, installedContent) {
|
|
117
|
-
if (installedContent === undefined)
|
|
118
|
-
return sourceContent;
|
|
119
|
-
const sourceFrontmatter = sourceContent.match(LEADING_YAML_FRONTMATTER)?.[1];
|
|
120
|
-
const installedFrontmatter = installedContent.match(LEADING_YAML_FRONTMATTER)?.[1];
|
|
121
|
-
if (!sourceFrontmatter || !installedFrontmatter)
|
|
122
|
-
return sourceContent;
|
|
123
|
-
return `${installedFrontmatter}${sourceContent.slice(sourceFrontmatter.length)}`;
|
|
124
|
-
}
|
|
125
|
-
export const STUB_TARGETS = [
|
|
126
|
-
{
|
|
127
|
-
// P148.05 AC2: claude-code now ships both subagent profile (neocortex.md +
|
|
128
|
-
// neocortex.agent.yaml) and root profile (neocortex-root.md +
|
|
129
|
-
// neocortex-root.agent.yaml) in the same canonical Custom Agents dir.
|
|
130
|
-
// Two-file split per P148.03: subagent has guard wording, root does not.
|
|
131
|
-
destDir: join(homedir(), '.claude', 'agents', 'neocortex'),
|
|
132
|
-
sourceDir: 'claude-code',
|
|
133
|
-
files: [
|
|
134
|
-
'neocortex.md',
|
|
135
|
-
'neocortex.agent.yaml',
|
|
136
|
-
'neocortex-root.md',
|
|
137
|
-
'neocortex-root.agent.yaml',
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
destDir: join(homedir(), '.gemini', 'agents'),
|
|
142
|
-
sourceDir: 'gemini-cli',
|
|
143
|
-
files: ['agent.md'],
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
destDir: join(homedir(), '.cursor', 'agents'),
|
|
147
|
-
sourceDir: 'cursor',
|
|
148
|
-
files: ['agent.md'],
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
destDir: join(homedir(), '.kimi-code', 'agents'),
|
|
152
|
-
sourceDir: 'kimi',
|
|
153
|
-
files: ['neocortex.md'],
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
// P148.05 AC1: opencode root profile (root agent owns *yoloop loop) and
|
|
157
|
-
// subagent profile (mode: subagent, recused outer root invocations) ship
|
|
158
|
-
// in the canonical OpenCode Custom Agents dir. P148.01 introduced the
|
|
159
|
-
// root/child split. Two-file topology mirrors claude-code, vscode, etc.
|
|
160
|
-
destDir: join(homedir(), '.opencode', 'agents'),
|
|
161
|
-
sourceDir: 'opencode',
|
|
162
|
-
files: ['neocortex.md', 'neocortex-root.md'],
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
destDir: join(homedir(), '.codex'),
|
|
166
|
-
sourceDir: 'codex',
|
|
167
|
-
// P124.01: Codex CLI requires uppercase AGENTS.md per docs
|
|
168
|
-
// (https://developers.openai.com/codex/guides/agents-md). Lowercase
|
|
169
|
-
// `agents.md` is silently ignored on case-sensitive filesystems
|
|
170
|
-
// (Linux + APFS case-sensitive volumes).
|
|
171
|
-
//
|
|
172
|
-
// P148.05 AC3: Codex ships AGENTS.md as the project-root entrypoint
|
|
173
|
-
// (root agent contract per P148.02). The subagent profile lives in
|
|
174
|
-
// ~/.codex/agents/neocortex.toml and is installed via the dedicated
|
|
175
|
-
// codex-subagent target below (different parent dir).
|
|
176
|
-
files: ['AGENTS.md'],
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
// P148.05 AC3: Codex subagent profile (neocortex.toml) lives in
|
|
180
|
-
// ~/.codex/agents/, distinct from root AGENTS.md in ~/.codex/. Codex
|
|
181
|
-
// discovers subagents via the agents/ dir per the official subagents
|
|
182
|
-
// docs (https://developers.openai.com/codex/subagents). Refreshing this
|
|
183
|
-
// target keeps the subagent guard wording (P127.06 isolation contract)
|
|
184
|
-
// in sync with the published CLI version.
|
|
185
|
-
destDir: join(homedir(), '.codex', 'agents'),
|
|
186
|
-
sourceDir: 'codex',
|
|
187
|
-
files: ['neocortex.toml'],
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
// P124.02: VS Code Copilot canonical Custom Agents path is ~/.copilot/agents/<name>.agent.md
|
|
191
|
-
// Source: https://code.visualstudio.com/docs/copilot/customization/custom-agents
|
|
192
|
-
destDir: join(homedir(), '.copilot', 'agents'),
|
|
193
|
-
sourceDir: 'vscode',
|
|
194
|
-
files: ['neocortex.agent.md'],
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
destDir: join(homedir(), '.agent', 'skills', 'neocortex'),
|
|
198
|
-
sourceDir: 'antigravity',
|
|
199
|
-
files: ['skill/SKILL.md'],
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
destDir: join(homedir(), '.gemini', 'config', 'agents'),
|
|
203
|
-
sourceDir: 'antigravity',
|
|
204
|
-
files: ['neocortex.md'],
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
destDir: join(homedir(), '.grok', 'skills', 'neocortex'),
|
|
208
|
-
sourceDir: 'grok',
|
|
209
|
-
files: ['SKILL.md'],
|
|
210
|
-
},
|
|
211
|
-
];
|
|
212
|
-
// -- Package Root Resolution --------------------------------------------------
|
|
213
|
-
/**
|
|
214
|
-
* Find the monorepo / npm package root by walking up from this file's location.
|
|
215
|
-
* Looks for a package.json with name '@ornexus/neocortex' (monorepo root) or
|
|
216
|
-
* '@neocortex/client' (client package root that contains targets-stubs after build).
|
|
217
|
-
*
|
|
218
|
-
* Returns null if not found within 10 levels.
|
|
219
|
-
*/
|
|
220
|
-
export function findPackageRoot() {
|
|
221
|
-
try {
|
|
222
|
-
const thisFile = fileURLToPath(import.meta.url);
|
|
223
|
-
let dir = dirname(thisFile);
|
|
224
|
-
for (let i = 0; i < 10; i++) {
|
|
225
|
-
try {
|
|
226
|
-
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));
|
|
227
|
-
if (pkg.name === '@ornexus/neocortex') {
|
|
228
|
-
return dir;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch { /* no package.json at this level */ }
|
|
232
|
-
dir = dirname(dir);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
catch { /* fallback */ }
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
// -- Version Comparison -------------------------------------------------------
|
|
239
|
-
/**
|
|
240
|
-
* Read the installed version from .version file in the dest directory.
|
|
241
|
-
* Returns null if file doesn't exist or is unreadable.
|
|
242
|
-
*/
|
|
243
|
-
function readInstalledVersion(destDir) {
|
|
244
|
-
try {
|
|
245
|
-
const versionFile = join(destDir, '.version');
|
|
246
|
-
if (existsSync(versionFile)) {
|
|
247
|
-
return readFileSync(versionFile, 'utf-8').trim() || null;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
catch { /* unreadable */ }
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
function writeTextAtomic(filePath, content) {
|
|
254
|
-
const temporaryPath = `${filePath}.tmp-${process.pid}`;
|
|
255
|
-
try {
|
|
256
|
-
writeFileSync(temporaryPath, content, 'utf8');
|
|
257
|
-
setSecureFilePermissions(temporaryPath);
|
|
258
|
-
renameSync(temporaryPath, filePath);
|
|
259
|
-
setSecureFilePermissions(filePath);
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
try {
|
|
263
|
-
if (existsSync(temporaryPath))
|
|
264
|
-
unlinkSync(temporaryPath);
|
|
265
|
-
}
|
|
266
|
-
catch { /* best effort */ }
|
|
267
|
-
throw error;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Refresh installed stubs if CLI version differs from installed version.
|
|
272
|
-
*
|
|
273
|
-
* For each stub target:
|
|
274
|
-
* 1. Read .version from install dir
|
|
275
|
-
* 2. Compare with cliVersion
|
|
276
|
-
* 3. If different (or .version missing): re-copy all stub files + write .version
|
|
277
|
-
* 4. If same: skip (no-op)
|
|
278
|
-
*
|
|
279
|
-
* When options.forceCreate is true, creates destDir if it doesn't exist.
|
|
280
|
-
* When options.targetFilter is set, only processes matching target.
|
|
281
|
-
*
|
|
282
|
-
* Never throws -- stub refresh is non-critical.
|
|
283
|
-
* Returns the number of targets that were refreshed.
|
|
284
|
-
*/
|
|
285
|
-
export function refreshStubs(cliVersion, options) {
|
|
286
|
-
try {
|
|
287
|
-
const forceCreate = options?.forceCreate ?? false;
|
|
288
|
-
const targetFilter = options?.targetFilter;
|
|
289
|
-
const dryRun = options?.dryRun ?? false;
|
|
290
|
-
const defaultHome = homedir();
|
|
291
|
-
const home = options?.homeDir ?? defaultHome;
|
|
292
|
-
const packageRoot = options?.packageRoot ?? findPackageRoot();
|
|
293
|
-
if (!packageRoot) {
|
|
294
|
-
return 0;
|
|
295
|
-
}
|
|
296
|
-
// targets-stubs/ is at the package root level
|
|
297
|
-
const stubsRoot = join(packageRoot, 'targets-stubs');
|
|
298
|
-
if (!existsSync(stubsRoot)) {
|
|
299
|
-
return 0;
|
|
300
|
-
}
|
|
301
|
-
const helperPath = join(stubsRoot, 'lib', 'managed-config-merge.js');
|
|
302
|
-
if (!existsSync(helperPath))
|
|
303
|
-
return 0;
|
|
304
|
-
const managed = requireManagedHelper(helperPath);
|
|
305
|
-
const manifestFile = join(home, '.neocortex', 'managed-config-manifest.json');
|
|
306
|
-
const tierLabel = readManagedTierLabel(home);
|
|
307
|
-
try {
|
|
308
|
-
managed.applyPolicy({
|
|
309
|
-
configFile: join(home, '.neocortex', 'config.json'),
|
|
310
|
-
manifestFile,
|
|
311
|
-
baseDir: home,
|
|
312
|
-
dryRun,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
catch {
|
|
316
|
-
// Approval config mutation fails closed; profile refresh can remain independent.
|
|
317
|
-
}
|
|
318
|
-
let refreshed = 0;
|
|
319
|
-
for (const target of STUB_TARGETS) {
|
|
320
|
-
try {
|
|
321
|
-
const destDir = options?.homeDir
|
|
322
|
-
? join(home, relative(defaultHome, target.destDir))
|
|
323
|
-
: target.destDir;
|
|
324
|
-
// If targetFilter is set, skip non-matching targets
|
|
325
|
-
if (targetFilter && target.sourceDir !== targetFilter) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
// Epic 67 - Story 67.3: If forceCreate, create destDir when it doesn't exist
|
|
329
|
-
if (!existsSync(destDir)) {
|
|
330
|
-
if (forceCreate && !dryRun) {
|
|
331
|
-
mkdirSync(destDir, { recursive: true });
|
|
332
|
-
}
|
|
333
|
-
else if (forceCreate && dryRun) {
|
|
334
|
-
// A dry-run may plan creation without touching the destination.
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
const installedVersion = readInstalledVersion(destDir);
|
|
341
|
-
if (installedVersion === cliVersion) {
|
|
342
|
-
continue; // Already up to date
|
|
343
|
-
}
|
|
344
|
-
// Source directory for this target
|
|
345
|
-
const sourceDir = join(stubsRoot, target.sourceDir);
|
|
346
|
-
if (!existsSync(sourceDir)) {
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
// Copy each file
|
|
350
|
-
let copiedAny = false;
|
|
351
|
-
for (const file of target.files) {
|
|
352
|
-
const src = join(sourceDir, file);
|
|
353
|
-
const dest = join(destDir, file);
|
|
354
|
-
if (existsSync(src)) {
|
|
355
|
-
let content = readFileSync(src, 'utf8');
|
|
356
|
-
if (file.endsWith('.md')) {
|
|
357
|
-
const installedContent = existsSync(dest) ? readFileSync(dest, 'utf8') : undefined;
|
|
358
|
-
content = preserveInstalledMarkdownFrontmatter(content, installedContent);
|
|
359
|
-
}
|
|
360
|
-
if (file.endsWith('.md') || file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
361
|
-
content = patchVersionInContent(content, cliVersion);
|
|
362
|
-
}
|
|
363
|
-
const relativeDest = relative(home, dest).split('\\').join('/');
|
|
364
|
-
const result = managed.applyProfileBytes({
|
|
365
|
-
id: `profile-${target.sourceDir}-${relativeDest}`,
|
|
366
|
-
content,
|
|
367
|
-
destination: dest,
|
|
368
|
-
manifestFile,
|
|
369
|
-
baseDir: home,
|
|
370
|
-
dryRun,
|
|
371
|
-
allowLegacyAdoption: true,
|
|
372
|
-
tierLabel,
|
|
373
|
-
});
|
|
374
|
-
if (result.action !== 'failed')
|
|
375
|
-
copiedAny = true;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
// Write .version file
|
|
379
|
-
if (copiedAny && !dryRun) {
|
|
380
|
-
const versionPath = join(destDir, '.version');
|
|
381
|
-
writeTextAtomic(versionPath, cliVersion + '\n');
|
|
382
|
-
refreshed++;
|
|
383
|
-
}
|
|
384
|
-
else if (copiedAny) {
|
|
385
|
-
refreshed++;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
catch {
|
|
389
|
-
// Non-critical -- continue with next target
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
// P85.07: Touch update-check marker after stub refresh to prevent
|
|
393
|
-
// redundant agent-side auto-update check immediately after postinstall.
|
|
394
|
-
// This is complementary to P50 server-side version gate (426 UPGRADE_REQUIRED):
|
|
395
|
-
// - Server-side (P50): hard block when version < MIN_CLIENT_VERSION
|
|
396
|
-
// - Agent-side (P85): soft update when version < LATEST (npm registry)
|
|
397
|
-
if (refreshed > 0) {
|
|
398
|
-
try {
|
|
399
|
-
// Keep explicit synthetic-home runs fully isolated from the real user
|
|
400
|
-
// home. Production still resolves `home` from os.homedir().
|
|
401
|
-
const markerDir = join(home, '.neocortex');
|
|
402
|
-
mkdirSync(markerDir, { recursive: true });
|
|
403
|
-
const marker = join(markerDir, '.update-check');
|
|
404
|
-
writeFileSync(marker, '', { flag: 'w' });
|
|
405
|
-
setSecureFilePermissions(marker);
|
|
406
|
-
}
|
|
407
|
-
catch {
|
|
408
|
-
// Fail-open: marker touch is non-critical
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return refreshed;
|
|
412
|
-
}
|
|
413
|
-
catch {
|
|
414
|
-
// Non-critical -- entire function is best-effort
|
|
415
|
-
return 0;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
1
|
+
import{readFileSync as f,writeFileSync as D,existsSync as u,mkdirSync as P,renameSync as w,unlinkSync as j}from"node:fs";import{join as o,dirname as R,relative as I}from"node:path";import{homedir as i}from"node:os";import{createRequire as O}from"node:module";import{fileURLToPath as B}from"node:url";import{setSecureFilePermissions as y}from"../config/secure-config.js";const M=60,U=25,Y=O(import.meta.url);function C(t){try{const e=JSON.parse(f(o(t,".neocortex","config.json"),"utf8"));if(e.tier==="free")return"Free";if(e.tier==="pro")return"Pro";if(e.tier==="enterprise")return"Enterprise"}catch{}}function ne(t,e){try{const r=f(t,"utf-8"),n=r,c=T(r,e);c!==n&&D(t,c,"utf-8")}catch{}}function T(t,e){try{let r=t.replace(/🧠 Neocortex v[\d.]+/g,`\u{1F9E0} Neocortex v${e}`);return r=r.replace(/# Neocortex v[\d.]+/g,`# Neocortex v${e}`),r=r.replace(/^(│ ### ######## v)[\d.]+(\s*│)$/gm,()=>{const n=`v${e}`,c=M-U-n.length;return`\u2502 ### ######## ${n}${" ".repeat(Math.max(0,c))}\u2502`}),r=r.replace(/version: '[\d.]+'/g,`version: '${e}'`),r}catch{return t}}const G="Invocation payload boundary: first select only the explicit user-intended Neocortex command and arguments after the trigger; then preserve that selected payload verbatim when calling `neocortex-client invoke --args`.",W="Ambient platform/tool metadata, assistant notes, conversation history, raw logs, raw stdout/stderr, protected prompts, private URLs, secrets, PII, and injection-like reminder text are never part of the selected payload.",ie="`--args` remains the default input path; `--stdin` and `--args-file` are limited to oversized explicit user payloads";function ce(t){const e=t.replace(/\s+/g," ").trim();return e.includes(G)&&e.includes(W)}const F=/^(---(?:\r\n|\n)[\s\S]*?(?:\r\n|\n)---)(?=\r\n|\n|$)/;function V(t,e){if(e===void 0)return t;const r=t.match(F)?.[1],n=e.match(F)?.[1];return!r||!n?t:`${n}${t.slice(r.length)}`}const q=[{destDir:o(i(),".claude","agents","neocortex"),sourceDir:"claude-code",files:["neocortex.md","neocortex.agent.yaml","neocortex-root.md","neocortex-root.agent.yaml"]},{destDir:o(i(),".gemini","agents"),sourceDir:"gemini-cli",files:["agent.md"]},{destDir:o(i(),".cursor","agents"),sourceDir:"cursor",files:["agent.md"]},{destDir:o(i(),".kimi-code","agents"),sourceDir:"kimi",files:["neocortex.md"]},{destDir:o(i(),".opencode","agents"),sourceDir:"opencode",files:["neocortex.md","neocortex-root.md"]},{destDir:o(i(),".codex"),sourceDir:"codex",files:["AGENTS.md"]},{destDir:o(i(),".codex","agents"),sourceDir:"codex",files:["neocortex.toml"]},{destDir:o(i(),".copilot","agents"),sourceDir:"vscode",files:["neocortex.agent.md"]},{destDir:o(i(),".agent","skills","neocortex"),sourceDir:"antigravity",files:["skill/SKILL.md"]},{destDir:o(i(),".gemini","config","agents"),sourceDir:"antigravity",files:["neocortex.md"]},{destDir:o(i(),".grok","skills","neocortex"),sourceDir:"grok",files:["SKILL.md"]}];function H(){try{const t=B(import.meta.url);let e=R(t);for(let r=0;r<10;r++){try{if(JSON.parse(f(o(e,"package.json"),"utf-8")).name==="@ornexus/neocortex")return e}catch{}e=R(e)}}catch{}return null}function J(t){try{const e=o(t,".version");if(u(e))return f(e,"utf-8").trim()||null}catch{}return null}function K(t,e){const r=`${t}.tmp-${process.pid}`;try{D(r,e,"utf8"),y(r),w(r,t),y(t)}catch(n){try{u(r)&&j(r)}catch{}throw n}}function se(t,e){try{const r=e?.forceCreate??!1,n=e?.targetFilter,c=e?.dryRun??!1,v=i(),a=e?.homeDir??v,E=e?.packageRoot??H();if(!E)return 0;const h=o(E,"targets-stubs");if(!u(h))return 0;const N=o(h,"lib","managed-config-merge.js");if(!u(N))return 0;const S=Y(N),k=o(a,".neocortex","managed-config-manifest.json"),_=C(a);try{S.applyPolicy({configFile:o(a,".neocortex","config.json"),manifestFile:k,baseDir:a,dryRun:c})}catch{}let p=0;for(const s of q)try{const l=e?.homeDir?o(a,I(v,s.destDir)):s.destDir;if(n&&s.sourceDir!==n)continue;if(!u(l)){if(r&&!c)P(l,{recursive:!0});else if(!(r&&c))continue}if(J(l)===t)continue;const A=o(h,s.sourceDir);if(!u(A))continue;let x=!1;for(const d of s.files){const L=o(A,d),g=o(l,d);if(u(L)){let m=f(L,"utf8");if(d.endsWith(".md")){const b=u(g)?f(g,"utf8"):void 0;m=V(m,b)}(d.endsWith(".md")||d.endsWith(".yaml")||d.endsWith(".yml"))&&(m=T(m,t));const $=I(a,g).split("\\").join("/");S.applyProfileBytes({id:`profile-${s.sourceDir}-${$}`,content:m,destination:g,manifestFile:k,baseDir:a,dryRun:c,allowLegacyAdoption:!0,tierLabel:_}).action!=="failed"&&(x=!0)}}if(x&&!c){const d=o(l,".version");K(d,t+`
|
|
2
|
+
`),p++}else x&&p++}catch{}if(p>0)try{const s=o(a,".neocortex");P(s,{recursive:!0});const l=o(s,".update-check");D(l,"",{flag:"w"}),y(l)}catch{}return p}catch{return 0}}export{G as SELECTED_PAYLOAD_BOUNDARY_SNIPPET,W as SELECTED_PAYLOAD_EXCLUSION_SNIPPET,ie as SELECTED_PAYLOAD_LARGE_INPUT_SNIPPET,q as STUB_TARGETS,ce as containsSelectedPayloadBoundary,H as findPackageRoot,T as patchVersionInContent,ne as patchVersionInFile,V as preserveInstalledMarkdownFrontmatter,se as refreshStubs};
|
|
@@ -1,102 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @license FSL-1.1
|
|
3
|
-
* Copyright (c) 2026 OrNexus AI
|
|
4
|
-
*
|
|
5
|
-
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
-
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
-
*
|
|
8
|
-
* Change Date: February 20, 2029
|
|
9
|
-
* Change License: MIT
|
|
10
|
-
*
|
|
11
|
-
* See the LICENSE file in the project root for full license text.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* @neocortex/client - Agent YAML Updater
|
|
15
|
-
*
|
|
16
|
-
* Patches neocortex.agent.yaml with current version and tier-based title.
|
|
17
|
-
*
|
|
18
|
-
* Patches TWO fields:
|
|
19
|
-
* 1. version: 'X.X.X'
|
|
20
|
-
* 2. title: 'Development Orchestrator (Tier)'
|
|
21
|
-
*
|
|
22
|
-
* Called after:
|
|
23
|
-
* - refreshStubs() (ensures YAML exists with current structure)
|
|
24
|
-
* - updateAgentDescription() (ensures consistency across all surfaces)
|
|
25
|
-
*
|
|
26
|
-
* Never throws -- YAML update is non-critical.
|
|
27
|
-
*
|
|
28
|
-
* Story 55.2
|
|
29
|
-
*/
|
|
30
|
-
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
31
|
-
import { join } from 'node:path';
|
|
32
|
-
import { homedir } from 'node:os';
|
|
33
|
-
// -- Constants ----------------------------------------------------------------
|
|
34
|
-
const TIER_LABELS = {
|
|
35
|
-
free: 'Free',
|
|
36
|
-
pro: 'Pro',
|
|
37
|
-
enterprise: 'Enterprise',
|
|
38
|
-
};
|
|
39
|
-
// Regex patterns for YAML fields (simple key: 'value' format)
|
|
40
|
-
const VERSION_PATTERN = /^(\s*version:\s*)'[^']*'/m;
|
|
41
|
-
const TITLE_PATTERN = /^(\s*title:\s*)'[^']*'/m;
|
|
42
|
-
const HOME_YAML_FILES = [
|
|
43
|
-
join(homedir(), '.claude', 'agents', 'neocortex', 'neocortex.agent.yaml'),
|
|
44
|
-
];
|
|
45
|
-
// -- Internal -----------------------------------------------------------------
|
|
46
|
-
/**
|
|
47
|
-
* Patch a single agent.yaml file with version and tier.
|
|
48
|
-
* Returns true if file was modified.
|
|
49
|
-
*/
|
|
50
|
-
function patchYamlFile(filePath, version, tier) {
|
|
51
|
-
try {
|
|
52
|
-
if (!existsSync(filePath)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
let content = readFileSync(filePath, 'utf-8');
|
|
56
|
-
const original = content;
|
|
57
|
-
const label = TIER_LABELS[tier.toLowerCase()] ?? 'Free';
|
|
58
|
-
// Patch version
|
|
59
|
-
if (VERSION_PATTERN.test(content)) {
|
|
60
|
-
content = content.replace(VERSION_PATTERN, `$1'${version}'`);
|
|
61
|
-
}
|
|
62
|
-
// Patch title
|
|
63
|
-
if (TITLE_PATTERN.test(content)) {
|
|
64
|
-
content = content.replace(TITLE_PATTERN, `$1'Development Orchestrator (${label})'`);
|
|
65
|
-
}
|
|
66
|
-
if (content === original) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
writeFileSync(filePath, content, 'utf-8');
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// -- Public API ---------------------------------------------------------------
|
|
77
|
-
/**
|
|
78
|
-
* Update agent.yaml files across all known locations.
|
|
79
|
-
* Returns count of files updated.
|
|
80
|
-
*
|
|
81
|
-
* Never throws.
|
|
82
|
-
*/
|
|
83
|
-
export function updateAgentYaml(version, tier) {
|
|
84
|
-
const resolvedTier = tier ?? 'free';
|
|
85
|
-
let updated = 0;
|
|
86
|
-
// Home-level files
|
|
87
|
-
for (const filePath of HOME_YAML_FILES) {
|
|
88
|
-
if (patchYamlFile(filePath, version, resolvedTier)) {
|
|
89
|
-
updated++;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return updated;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Update agent.yaml at a specific file path (used for testing).
|
|
96
|
-
* Returns true if the file was modified.
|
|
97
|
-
*
|
|
98
|
-
* Never throws.
|
|
99
|
-
*/
|
|
100
|
-
export function updateAgentYamlAt(filePath, version, tier) {
|
|
101
|
-
return patchYamlFile(filePath, version, tier ?? 'free');
|
|
102
|
-
}
|
|
1
|
+
import{readFileSync as f,writeFileSync as l,existsSync as u}from"node:fs";import{join as p}from"node:path";import{homedir as m}from"node:os";const E={free:"Free",pro:"Pro",enterprise:"Enterprise"},s=/^(\s*version:\s*)'[^']*'/m,c=/^(\s*title:\s*)'[^']*'/m,d=[p(m(),".claude","agents","neocortex","neocortex.agent.yaml")];function i(t,r,n){try{if(!u(t))return!1;let e=f(t,"utf-8");const o=e,a=E[n.toLowerCase()]??"Free";return s.test(e)&&(e=e.replace(s,`$1'${r}'`)),c.test(e)&&(e=e.replace(c,`$1'Development Orchestrator (${a})'`)),e===o?!1:(l(t,e,"utf-8"),!0)}catch{return!1}}function L(t,r){const n=r??"free";let e=0;for(const o of d)i(o,t,n)&&e++;return e}function S(t,r,n){return i(t,r,n??"free")}export{L as updateAgentYaml,S as updateAgentYamlAt};
|