@ornexus/neocortex 4.0.1 → 4.0.2
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/install.ps1 +92 -33
- package/install.sh +15 -1
- package/package.json +3 -3
- package/packages/client/dist/adapters/adapter-registry.js +1 -106
- 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/index.js +1 -21
- package/packages/client/dist/adapters/platform-detector.js +1 -106
- 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 -234
- 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 -76
- package/packages/client/dist/cache/encrypted-cache.js +1 -94
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -70
- package/packages/client/dist/cache/index.js +1 -13
- package/packages/client/dist/cli.js +2 -163
- package/packages/client/dist/commands/activate.js +8 -390
- package/packages/client/dist/commands/cache-status.js +2 -112
- package/packages/client/dist/commands/invoke.js +28 -490
- package/packages/client/dist/config/resolver-selection.js +1 -278
- package/packages/client/dist/config/secure-config.js +12 -269
- 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/index.js +1 -38
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.js +1 -257
- package/packages/client/dist/machine/fingerprint.js +2 -160
- package/packages/client/dist/machine/index.js +1 -5
- 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 -218
- package/packages/client/dist/resolvers/remote-resolver.js +1 -282
- 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 -260
- package/packages/client/dist/types/index.js +1 -38
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/install-antigravity.sh +49 -3
- package/targets-stubs/antigravity/skill/SKILL.md +23 -4
- package/targets-stubs/claude-code/neocortex.agent.yaml +19 -1
- package/targets-stubs/claude-code/neocortex.md +64 -29
- package/targets-stubs/codex/agents.md +20 -3
- package/targets-stubs/codex/config-mcp.toml +5 -0
- package/targets-stubs/cursor/agent.md +23 -5
- package/targets-stubs/cursor/install-cursor.sh +51 -3
- package/targets-stubs/cursor/mcp.json +7 -0
- package/targets-stubs/gemini-cli/agent.md +37 -6
- package/targets-stubs/gemini-cli/install-gemini.sh +50 -17
- package/targets-stubs/vscode/agent.md +47 -10
- package/targets-stubs/vscode/install-vscode.sh +50 -3
- package/targets-stubs/vscode/mcp.json +8 -0
|
@@ -1,164 +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
|
-
// ── Types ─────────────────────────────────────────────────────────────────
|
|
14
|
-
export var DegradationLevel;
|
|
15
|
-
(function (DegradationLevel) {
|
|
16
|
-
/** Server available, fresh data, optimal performance */
|
|
17
|
-
DegradationLevel[DegradationLevel["ONLINE"] = 0] = "ONLINE";
|
|
18
|
-
/** Server slow (>2s), use cache when available */
|
|
19
|
-
DegradationLevel[DegradationLevel["HIGH_LATENCY"] = 1] = "HIGH_LATENCY";
|
|
20
|
-
/** Server down, use cache exclusively */
|
|
21
|
-
DegradationLevel[DegradationLevel["SERVER_DOWN"] = 2] = "SERVER_DOWN";
|
|
22
|
-
/** Cache expired (>24h), use with warning */
|
|
23
|
-
DegradationLevel[DegradationLevel["STALE_CACHE"] = 3] = "STALE_CACHE";
|
|
24
|
-
/** No cache and no server - error state */
|
|
25
|
-
DegradationLevel[DegradationLevel["NO_CACHE"] = 4] = "NO_CACHE";
|
|
26
|
-
})(DegradationLevel || (DegradationLevel = {}));
|
|
27
|
-
// ── Defaults ──────────────────────────────────────────────────────────────
|
|
28
|
-
const DEFAULT_CONFIG = {
|
|
29
|
-
staleThresholdMs: 86_400_000, // 24 hours
|
|
30
|
-
warningThresholdMs: 43_200_000, // 12 hours
|
|
31
|
-
latencyThresholdMs: 2_000, // 2 seconds
|
|
32
|
-
};
|
|
33
|
-
// ── DegradationManager ───────────────────────────────────────────────────
|
|
34
|
-
export class DegradationManager {
|
|
35
|
-
config;
|
|
36
|
-
constructor(config) {
|
|
37
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Evaluate the current degradation level based on context.
|
|
41
|
-
*/
|
|
42
|
-
evaluate(context) {
|
|
43
|
-
// Force-offline mode: always use cache
|
|
44
|
-
if (context.forceOffline) {
|
|
45
|
-
return this.buildCacheOnlyDecision(context, '[OFFLINE]');
|
|
46
|
-
}
|
|
47
|
-
// Circuit is OPEN: server known to be down
|
|
48
|
-
if (context.circuitState === 'OPEN') {
|
|
49
|
-
return this.buildServerDownDecision(context);
|
|
50
|
-
}
|
|
51
|
-
// Circuit is HALF_OPEN: probing server
|
|
52
|
-
if (context.circuitState === 'HALF_OPEN') {
|
|
53
|
-
// Allow server request (probe), but prepare cache fallback
|
|
54
|
-
return {
|
|
55
|
-
level: DegradationLevel.SERVER_DOWN,
|
|
56
|
-
useCache: true,
|
|
57
|
-
useServer: true,
|
|
58
|
-
prefix: '[PROBING]',
|
|
59
|
-
warning: null,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
// Circuit is CLOSED: server available
|
|
63
|
-
if (context.latencyMs != null && context.latencyMs > this.config.latencyThresholdMs) {
|
|
64
|
-
// High latency: prefer cache if available
|
|
65
|
-
if (context.cacheAvailable) {
|
|
66
|
-
return {
|
|
67
|
-
level: DegradationLevel.HIGH_LATENCY,
|
|
68
|
-
useCache: true,
|
|
69
|
-
useServer: false,
|
|
70
|
-
prefix: '[CACHED]',
|
|
71
|
-
warning: null,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// No cache available: still use server (slow is better than nothing)
|
|
75
|
-
return {
|
|
76
|
-
level: DegradationLevel.HIGH_LATENCY,
|
|
77
|
-
useCache: false,
|
|
78
|
-
useServer: true,
|
|
79
|
-
prefix: '',
|
|
80
|
-
warning: 'Server response is slow. Consider running `neocortex cache warmup`.',
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
// Normal operation
|
|
84
|
-
return {
|
|
85
|
-
level: DegradationLevel.ONLINE,
|
|
86
|
-
useCache: false,
|
|
87
|
-
useServer: true,
|
|
88
|
-
prefix: '',
|
|
89
|
-
warning: null,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
// ── Private ─────────────────────────────────────────────────────────
|
|
93
|
-
buildServerDownDecision(context) {
|
|
94
|
-
if (!context.cacheAvailable) {
|
|
95
|
-
return {
|
|
96
|
-
level: DegradationLevel.NO_CACHE,
|
|
97
|
-
useCache: false,
|
|
98
|
-
useServer: false,
|
|
99
|
-
prefix: '[ERROR]',
|
|
100
|
-
warning: 'Server unavailable and no cached data. Run `neocortex cache warmup` when online.',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const cacheAgeMs = context.cacheAgeMs ?? 0;
|
|
104
|
-
if (cacheAgeMs > this.config.staleThresholdMs) {
|
|
105
|
-
const ageStr = this.formatAge(cacheAgeMs);
|
|
106
|
-
return {
|
|
107
|
-
level: DegradationLevel.STALE_CACHE,
|
|
108
|
-
useCache: true,
|
|
109
|
-
useServer: false,
|
|
110
|
-
prefix: `[STALE CACHE - ${ageStr}]`,
|
|
111
|
-
warning: `Cache is stale (${ageStr} old). Data may be outdated.`,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
level: DegradationLevel.SERVER_DOWN,
|
|
116
|
-
useCache: true,
|
|
117
|
-
useServer: false,
|
|
118
|
-
prefix: '[CACHED]',
|
|
119
|
-
warning: cacheAgeMs > this.config.warningThresholdMs
|
|
120
|
-
? `Cache is ${this.formatAge(cacheAgeMs)} old.`
|
|
121
|
-
: null,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
buildCacheOnlyDecision(context, prefix) {
|
|
125
|
-
if (!context.cacheAvailable) {
|
|
126
|
-
return {
|
|
127
|
-
level: DegradationLevel.NO_CACHE,
|
|
128
|
-
useCache: false,
|
|
129
|
-
useServer: false,
|
|
130
|
-
prefix: '[ERROR]',
|
|
131
|
-
warning: 'Offline mode active but no cached data available. Run `neocortex cache warmup` when online.',
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const cacheAgeMs = context.cacheAgeMs ?? 0;
|
|
135
|
-
if (cacheAgeMs > this.config.staleThresholdMs) {
|
|
136
|
-
const ageStr = this.formatAge(cacheAgeMs);
|
|
137
|
-
return {
|
|
138
|
-
level: DegradationLevel.STALE_CACHE,
|
|
139
|
-
useCache: true,
|
|
140
|
-
useServer: false,
|
|
141
|
-
prefix: `[STALE CACHE - ${ageStr}]`,
|
|
142
|
-
warning: `Using stale cache (${ageStr} old) in offline mode.`,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
level: DegradationLevel.SERVER_DOWN,
|
|
147
|
-
useCache: true,
|
|
148
|
-
useServer: false,
|
|
149
|
-
prefix,
|
|
150
|
-
warning: null,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
formatAge(ms) {
|
|
154
|
-
const hours = Math.floor(ms / 3_600_000);
|
|
155
|
-
if (hours >= 48)
|
|
156
|
-
return `${Math.floor(hours / 24)}d`;
|
|
157
|
-
if (hours >= 1)
|
|
158
|
-
return `${hours}h`;
|
|
159
|
-
const minutes = Math.floor(ms / 60_000);
|
|
160
|
-
if (minutes >= 1)
|
|
161
|
-
return `${minutes}m`;
|
|
162
|
-
return '<1m';
|
|
163
|
-
}
|
|
164
|
-
}
|
|
1
|
+
var r;(function(s){s[s.ONLINE=0]="ONLINE",s[s.HIGH_LATENCY=1]="HIGH_LATENCY",s[s.SERVER_DOWN=2]="SERVER_DOWN",s[s.STALE_CACHE=3]="STALE_CACHE",s[s.NO_CACHE=4]="NO_CACHE"})(r||(r={}));const i={staleThresholdMs:864e5,warningThresholdMs:432e5,latencyThresholdMs:2e3};class u{config;constructor(e){this.config={...i,...e}}evaluate(e){return e.forceOffline?this.buildCacheOnlyDecision(e,"[OFFLINE]"):e.circuitState==="OPEN"?this.buildServerDownDecision(e):e.circuitState==="HALF_OPEN"?{level:r.SERVER_DOWN,useCache:!0,useServer:!0,prefix:"[PROBING]",warning:null}:e.latencyMs!=null&&e.latencyMs>this.config.latencyThresholdMs?e.cacheAvailable?{level:r.HIGH_LATENCY,useCache:!0,useServer:!1,prefix:"[CACHED]",warning:null}:{level:r.HIGH_LATENCY,useCache:!1,useServer:!0,prefix:"",warning:"Server response is slow. Consider running `neocortex cache warmup`."}:{level:r.ONLINE,useCache:!1,useServer:!0,prefix:"",warning:null}}buildServerDownDecision(e){if(!e.cacheAvailable)return{level:r.NO_CACHE,useCache:!1,useServer:!1,prefix:"[ERROR]",warning:"Server unavailable and no cached data. Run `neocortex cache warmup` when online."};const a=e.cacheAgeMs??0;if(a>this.config.staleThresholdMs){const n=this.formatAge(a);return{level:r.STALE_CACHE,useCache:!0,useServer:!1,prefix:`[STALE CACHE - ${n}]`,warning:`Cache is stale (${n} old). Data may be outdated.`}}return{level:r.SERVER_DOWN,useCache:!0,useServer:!1,prefix:"[CACHED]",warning:a>this.config.warningThresholdMs?`Cache is ${this.formatAge(a)} old.`:null}}buildCacheOnlyDecision(e,a){if(!e.cacheAvailable)return{level:r.NO_CACHE,useCache:!1,useServer:!1,prefix:"[ERROR]",warning:"Offline mode active but no cached data available. Run `neocortex cache warmup` when online."};const n=e.cacheAgeMs??0;if(n>this.config.staleThresholdMs){const l=this.formatAge(n);return{level:r.STALE_CACHE,useCache:!0,useServer:!1,prefix:`[STALE CACHE - ${l}]`,warning:`Using stale cache (${l} old) in offline mode.`}}return{level:r.SERVER_DOWN,useCache:!0,useServer:!1,prefix:a,warning:null}}formatAge(e){const a=Math.floor(e/36e5);if(a>=48)return`${Math.floor(a/24)}d`;if(a>=1)return`${a}h`;const n=Math.floor(e/6e4);return n>=1?`${n}m`:"<1m"}}export{r as DegradationLevel,u as DegradationManager};
|
|
@@ -1,100 +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 - Freshness Indicator
|
|
15
|
-
*
|
|
16
|
-
* Enriches cache responses with freshness metadata for user-facing display.
|
|
17
|
-
* Formats cache age as human-readable strings and generates appropriate
|
|
18
|
-
* warning prefixes based on degradation level.
|
|
19
|
-
*
|
|
20
|
-
* Story 42.9
|
|
21
|
-
*/
|
|
22
|
-
import { DegradationLevel } from './degradation-manager.js';
|
|
23
|
-
// ── Defaults ──────────────────────────────────────────────────────────────
|
|
24
|
-
const DEFAULT_CONFIG = {
|
|
25
|
-
staleThresholdMs: 86_400_000, // 24 hours
|
|
26
|
-
warningThresholdMs: 43_200_000, // 12 hours
|
|
27
|
-
};
|
|
28
|
-
// ── FreshnessIndicator ──────────────────────────────────────────────────
|
|
29
|
-
export class FreshnessIndicator {
|
|
30
|
-
config;
|
|
31
|
-
constructor(config) {
|
|
32
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Format a duration in ms as human-readable age string.
|
|
36
|
-
* Examples: "30m ago", "4h ago", "2d ago"
|
|
37
|
-
*/
|
|
38
|
-
formatAge(ageMs) {
|
|
39
|
-
if (ageMs < 0)
|
|
40
|
-
return 'just now';
|
|
41
|
-
const seconds = Math.floor(ageMs / 1_000);
|
|
42
|
-
const minutes = Math.floor(ageMs / 60_000);
|
|
43
|
-
const hours = Math.floor(ageMs / 3_600_000);
|
|
44
|
-
const days = Math.floor(ageMs / 86_400_000);
|
|
45
|
-
if (days >= 1)
|
|
46
|
-
return `${days}d ago`;
|
|
47
|
-
if (hours >= 1)
|
|
48
|
-
return `${hours}h ago`;
|
|
49
|
-
if (minutes >= 1)
|
|
50
|
-
return `${minutes}m ago`;
|
|
51
|
-
if (seconds >= 1)
|
|
52
|
-
return `${seconds}s ago`;
|
|
53
|
-
return 'just now';
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Evaluate freshness of a cache entry.
|
|
57
|
-
*/
|
|
58
|
-
evaluate(cacheAgeMs, _ttlMs) {
|
|
59
|
-
const stale = cacheAgeMs > this.config.staleThresholdMs;
|
|
60
|
-
const aged = cacheAgeMs > this.config.warningThresholdMs;
|
|
61
|
-
let warning = null;
|
|
62
|
-
let prefix = '[CACHED]';
|
|
63
|
-
if (stale) {
|
|
64
|
-
const ageStr = this.formatAge(cacheAgeMs);
|
|
65
|
-
prefix = `[STALE CACHE - ${ageStr}]`;
|
|
66
|
-
warning = `WARNING: STALE - cached ${ageStr}`;
|
|
67
|
-
}
|
|
68
|
-
else if (aged) {
|
|
69
|
-
const ageStr = this.formatAge(cacheAgeMs);
|
|
70
|
-
prefix = `[CACHED]`;
|
|
71
|
-
warning = `WARNING - cached ${ageStr}`;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
cached: true,
|
|
75
|
-
cacheAgeMs,
|
|
76
|
-
stale,
|
|
77
|
-
warning,
|
|
78
|
-
prefix,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Format prefix string based on degradation level and optional age.
|
|
83
|
-
*/
|
|
84
|
-
formatPrefix(level, ageMs) {
|
|
85
|
-
switch (level) {
|
|
86
|
-
case DegradationLevel.ONLINE:
|
|
87
|
-
return '';
|
|
88
|
-
case DegradationLevel.HIGH_LATENCY:
|
|
89
|
-
return ageMs != null ? `[CACHED] cached ${this.formatAge(ageMs)}` : '[CACHED]';
|
|
90
|
-
case DegradationLevel.SERVER_DOWN:
|
|
91
|
-
return ageMs != null ? `[CACHED] cached ${this.formatAge(ageMs)}` : '[CACHED]';
|
|
92
|
-
case DegradationLevel.STALE_CACHE:
|
|
93
|
-
return ageMs != null ? `[STALE CACHE - ${this.formatAge(ageMs)}]` : '[STALE CACHE]';
|
|
94
|
-
case DegradationLevel.NO_CACHE:
|
|
95
|
-
return '[ERROR]';
|
|
96
|
-
default:
|
|
97
|
-
return '';
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
1
|
+
import{DegradationLevel as e}from"./degradation-manager.js";const l={staleThresholdMs:864e5,warningThresholdMs:432e5};class h{config;constructor(t){this.config={...l,...t}}formatAge(t){if(t<0)return"just now";const r=Math.floor(t/1e3),n=Math.floor(t/6e4),s=Math.floor(t/36e5),o=Math.floor(t/864e5);return o>=1?`${o}d ago`:s>=1?`${s}h ago`:n>=1?`${n}m ago`:r>=1?`${r}s ago`:"just now"}evaluate(t,r){const n=t>this.config.staleThresholdMs,s=t>this.config.warningThresholdMs;let o=null,i="[CACHED]";if(n){const a=this.formatAge(t);i=`[STALE CACHE - ${a}]`,o=`WARNING: STALE - cached ${a}`}else if(s){const a=this.formatAge(t);i="[CACHED]",o=`WARNING - cached ${a}`}return{cached:!0,cacheAgeMs:t,stale:n,warning:o,prefix:i}}formatPrefix(t,r){switch(t){case e.ONLINE:return"";case e.HIGH_LATENCY:return r!=null?`[CACHED] cached ${this.formatAge(r)}`:"[CACHED]";case e.SERVER_DOWN:return r!=null?`[CACHED] cached ${this.formatAge(r)}`:"[CACHED]";case e.STALE_CACHE:return r!=null?`[STALE CACHE - ${this.formatAge(r)}]`:"[STALE CACHE]";case e.NO_CACHE:return"[ERROR]";default:return""}}}export{h as FreshnessIndicator};
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @license FSL-1.1
|
|
3
|
-
* Copyright (c) 2026 OrNexus AI
|
|
4
|
-
*/
|
|
5
|
-
export { ClientCircuitBreaker } from './circuit-breaker.js';
|
|
6
|
-
export { DegradationManager, DegradationLevel } from './degradation-manager.js';
|
|
7
|
-
export { FreshnessIndicator } from './freshness-indicator.js';
|
|
8
|
-
export { RecoveryDetector } from './recovery-detector.js';
|
|
1
|
+
import{ClientCircuitBreaker as o}from"./circuit-breaker.js";import{DegradationManager as a,DegradationLevel as i}from"./degradation-manager.js";import{FreshnessIndicator as c}from"./freshness-indicator.js";import{RecoveryDetector as m}from"./recovery-detector.js";export{o as ClientCircuitBreaker,i as DegradationLevel,a as DegradationManager,c as FreshnessIndicator,m as RecoveryDetector};
|
|
@@ -1,74 +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
|
-
// ── RecoveryDetector ─────────────────────────────────────────────────────
|
|
14
|
-
export class RecoveryDetector {
|
|
15
|
-
actions;
|
|
16
|
-
constructor(actions) {
|
|
17
|
-
this.actions = actions;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Execute full recovery sequence.
|
|
21
|
-
* Each step is independent - failures are captured but don't block others.
|
|
22
|
-
*/
|
|
23
|
-
async onRecovery() {
|
|
24
|
-
const result = {
|
|
25
|
-
circuitClosed: false,
|
|
26
|
-
jwtRefreshed: false,
|
|
27
|
-
cacheSynced: false,
|
|
28
|
-
telemetryFlushed: { sent: 0, failed: 0 },
|
|
29
|
-
notification: '[ONLINE] Server connection restored',
|
|
30
|
-
};
|
|
31
|
-
// Step 1: Close circuit breaker
|
|
32
|
-
try {
|
|
33
|
-
await this.actions.circuitBreaker.recordSuccess();
|
|
34
|
-
result.circuitClosed = true;
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
// Non-critical: breaker will close on next successful call
|
|
38
|
-
}
|
|
39
|
-
// Step 2: Re-validate JWT
|
|
40
|
-
try {
|
|
41
|
-
const token = await this.actions.licenseClient.getToken();
|
|
42
|
-
result.jwtRefreshed = token !== null;
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// Non-critical: will be retried on next server call
|
|
46
|
-
}
|
|
47
|
-
// Step 3: Sync cache (background - just attempt, don't block)
|
|
48
|
-
try {
|
|
49
|
-
// We don't actually sync here - the next resolver call will
|
|
50
|
-
// update the cache automatically via fetchWithCacheFallback.
|
|
51
|
-
// We just mark as synced since the circuit is now closed.
|
|
52
|
-
result.cacheSynced = true;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
// Non-critical
|
|
56
|
-
}
|
|
57
|
-
// Step 4: Flush telemetry queue
|
|
58
|
-
try {
|
|
59
|
-
const flushResult = await this.actions.telemetryQueue.flush(async (events) => {
|
|
60
|
-
const response = await fetch(`${this.actions.serverUrl}/api/v1/telemetry/batch`, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: { 'Content-Type': 'application/json' },
|
|
63
|
-
body: JSON.stringify({ events }),
|
|
64
|
-
});
|
|
65
|
-
return response.ok;
|
|
66
|
-
});
|
|
67
|
-
result.telemetryFlushed = flushResult;
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
// Non-critical: queue will be flushed on next recovery
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
class n{actions;constructor(e){this.actions=e}async onRecovery(){const e={circuitClosed:!1,jwtRefreshed:!1,cacheSynced:!1,telemetryFlushed:{sent:0,failed:0},notification:"[ONLINE] Server connection restored"};try{await this.actions.circuitBreaker.recordSuccess(),e.circuitClosed=!0}catch{}try{const t=await this.actions.licenseClient.getToken();e.jwtRefreshed=t!==null}catch{}try{e.cacheSynced=!0}catch{}try{const t=await this.actions.telemetryQueue.flush(async c=>(await fetch(`${this.actions.serverUrl}/api/v1/telemetry/batch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:c})})).ok);e.telemetryFlushed=t}catch{}return e}}export{n as RecoveryDetector};
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
export {};
|
|
@@ -1,218 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Change License: MIT
|
|
10
|
-
*
|
|
11
|
-
* See the LICENSE file in the project root for full license text.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* @neocortex/client - LocalResolver
|
|
15
|
-
*
|
|
16
|
-
* Resolves pipeline assets from the local filesystem.
|
|
17
|
-
* Used in development mode when core/ directory is available locally.
|
|
18
|
-
* Replicates the current CLI behavior of reading .md files directly.
|
|
19
|
-
*/
|
|
20
|
-
import { readFile, access } from 'node:fs/promises';
|
|
21
|
-
import { join, resolve } from 'node:path';
|
|
22
|
-
import { ResolverMode, } from '../types/index.js';
|
|
23
|
-
// ── Frontmatter Parser ───────────────────────────────────────────────────
|
|
24
|
-
const FRONTMATTER_REGEX = /^---\n([\s\S]*?)\n---/;
|
|
25
|
-
/**
|
|
26
|
-
* Parse YAML-like frontmatter from markdown content.
|
|
27
|
-
* Simple key-value parser sufficient for step/skill frontmatter.
|
|
28
|
-
*/
|
|
29
|
-
function parseFrontmatter(content) {
|
|
30
|
-
const match = content.match(FRONTMATTER_REGEX);
|
|
31
|
-
if (!match) {
|
|
32
|
-
return { frontmatter: {}, body: content };
|
|
33
|
-
}
|
|
34
|
-
const frontmatter = {};
|
|
35
|
-
const lines = match[1].split('\n');
|
|
36
|
-
for (const line of lines) {
|
|
37
|
-
const colonIndex = line.indexOf(':');
|
|
38
|
-
if (colonIndex === -1)
|
|
39
|
-
continue;
|
|
40
|
-
const key = line.slice(0, colonIndex).trim().replace(/^['"]|['"]$/g, '');
|
|
41
|
-
let value = line.slice(colonIndex + 1).trim();
|
|
42
|
-
// Remove surrounding quotes
|
|
43
|
-
if (typeof value === 'string') {
|
|
44
|
-
value = value.replace(/^['"]|['"]$/g, '');
|
|
45
|
-
}
|
|
46
|
-
// Parse booleans
|
|
47
|
-
if (value === 'true')
|
|
48
|
-
value = true;
|
|
49
|
-
else if (value === 'false')
|
|
50
|
-
value = false;
|
|
51
|
-
frontmatter[key] = value;
|
|
52
|
-
}
|
|
53
|
-
const body = content.slice(match[0].length).trimStart();
|
|
54
|
-
return { frontmatter, body };
|
|
55
|
-
}
|
|
56
|
-
// ── Step ID to File Path Mapping ─────────────────────────────────────────
|
|
57
|
-
/**
|
|
58
|
-
* Map step ID to file path within core/steps/.
|
|
59
|
-
*
|
|
60
|
-
* Step IDs follow the pattern: step-{category}-{order}-{name}
|
|
61
|
-
* File paths: core/steps/steps-{category}/{id}.md
|
|
62
|
-
*/
|
|
63
|
-
function stepIdToPath(stepId) {
|
|
64
|
-
// Extract category from step ID: step-c-01-setup-branch -> c
|
|
65
|
-
// step-r-fix-blocked -> r, step-u-init -> u, step-p-01-idea-diagnose -> p, step-e-01-epic-init -> e
|
|
66
|
-
const parts = stepId.split('-');
|
|
67
|
-
if (parts.length < 3) {
|
|
68
|
-
throw new Error(`Invalid step ID format: ${stepId}`);
|
|
69
|
-
}
|
|
70
|
-
const category = parts[1]; // c, r, u, p, e
|
|
71
|
-
const categoryMap = {
|
|
72
|
-
c: 'steps-c',
|
|
73
|
-
r: 'steps-r',
|
|
74
|
-
u: 'steps-u',
|
|
75
|
-
p: 'steps-p',
|
|
76
|
-
e: 'steps-e',
|
|
77
|
-
};
|
|
78
|
-
const dir = categoryMap[category];
|
|
79
|
-
if (!dir) {
|
|
80
|
-
throw new Error(`Unknown step category '${category}' in step ID: ${stepId}`);
|
|
81
|
-
}
|
|
82
|
-
return `core/steps/${dir}/${stepId}.md`;
|
|
83
|
-
}
|
|
84
|
-
// ── LocalResolver Implementation ─────────────────────────────────────────
|
|
85
|
-
export class LocalResolver {
|
|
86
|
-
mode = ResolverMode.LOCAL;
|
|
87
|
-
projectRoot;
|
|
88
|
-
constructor(options) {
|
|
89
|
-
this.projectRoot = resolve(options.projectRoot);
|
|
90
|
-
}
|
|
91
|
-
async resolveStep(stepId, _context) {
|
|
92
|
-
const relativePath = stepIdToPath(stepId);
|
|
93
|
-
const fullPath = join(this.projectRoot, relativePath);
|
|
94
|
-
const raw = await readFile(fullPath, 'utf-8');
|
|
95
|
-
const { frontmatter, body } = parseFrontmatter(raw);
|
|
96
|
-
return {
|
|
97
|
-
id: stepId,
|
|
98
|
-
content: body,
|
|
99
|
-
frontmatter,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async resolveSkill(skillId, _context) {
|
|
103
|
-
// Skills are organized in: core/skills/{category}/{skillId}.md
|
|
104
|
-
// or: core/skills/step-skills/{step}/{skillId}.md
|
|
105
|
-
// Try multiple paths to find the skill
|
|
106
|
-
const searchPaths = [
|
|
107
|
-
`core/skills/${skillId}.md`,
|
|
108
|
-
`core/skills/step-skills/${skillId}.md`,
|
|
109
|
-
];
|
|
110
|
-
// Also try with nested path: "diagnose/prompt-enricher" -> core/skills/step-skills/diagnose/prompt-enricher.md
|
|
111
|
-
if (skillId.includes('/')) {
|
|
112
|
-
searchPaths.unshift(`core/skills/step-skills/${skillId}.md`);
|
|
113
|
-
searchPaths.unshift(`core/skills/${skillId}.md`);
|
|
114
|
-
}
|
|
115
|
-
let raw = null;
|
|
116
|
-
let resolvedPath = '';
|
|
117
|
-
for (const searchPath of searchPaths) {
|
|
118
|
-
const fullPath = join(this.projectRoot, searchPath);
|
|
119
|
-
try {
|
|
120
|
-
raw = await readFile(fullPath, 'utf-8');
|
|
121
|
-
resolvedPath = searchPath;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
// Try next path
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (raw === null) {
|
|
129
|
-
throw new Error(`Skill '${skillId}' not found. Searched: ${searchPaths.join(', ')}`);
|
|
130
|
-
}
|
|
131
|
-
const { frontmatter, body } = parseFrontmatter(raw);
|
|
132
|
-
return {
|
|
133
|
-
id: skillId,
|
|
134
|
-
content: body,
|
|
135
|
-
metadata: { ...frontmatter, resolvedPath },
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
async resolveStandard(standardId) {
|
|
139
|
-
const fullPath = join(this.projectRoot, 'core', 'standards', standardId);
|
|
140
|
-
let content;
|
|
141
|
-
try {
|
|
142
|
-
content = await readFile(fullPath, 'utf-8');
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
// Try with .md extension if not present
|
|
146
|
-
if (!standardId.endsWith('.md')) {
|
|
147
|
-
content = await readFile(`${fullPath}.md`, 'utf-8');
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
throw new Error(`Standard '${standardId}' not found at ${fullPath}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
id: standardId,
|
|
155
|
-
content,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
async resolveRegistry() {
|
|
159
|
-
const fullPath = join(this.projectRoot, 'core', 'data', 'step-registry.json');
|
|
160
|
-
const raw = await readFile(fullPath, 'utf-8');
|
|
161
|
-
return JSON.parse(raw);
|
|
162
|
-
}
|
|
163
|
-
async assemblePrompt(stepId, context) {
|
|
164
|
-
// Resolve the step content
|
|
165
|
-
const step = await this.resolveStep(stepId, context);
|
|
166
|
-
// Build variables map from context
|
|
167
|
-
const variables = {
|
|
168
|
-
'{story_id}': context.storyId,
|
|
169
|
-
'{story_title}': context.storyTitle,
|
|
170
|
-
'{step_id}': stepId,
|
|
171
|
-
'{step_name}': step.frontmatter['name'] || stepId,
|
|
172
|
-
'{current_status}': context.currentStatus,
|
|
173
|
-
'{epic_id}': context.epicId,
|
|
174
|
-
'{branch_name}': context.branchName,
|
|
175
|
-
'{platform_target}': context.platformTarget,
|
|
176
|
-
};
|
|
177
|
-
// Substitute variables in step content
|
|
178
|
-
let prompt = step.content;
|
|
179
|
-
for (const [key, value] of Object.entries(variables)) {
|
|
180
|
-
prompt = prompt.replaceAll(key, value);
|
|
181
|
-
}
|
|
182
|
-
// Resolve skills referenced in step frontmatter
|
|
183
|
-
const includedSkills = [];
|
|
184
|
-
const skillsRef = step.frontmatter['skills'];
|
|
185
|
-
if (skillsRef && typeof skillsRef === 'string') {
|
|
186
|
-
const skillIds = skillsRef.split(',').map((s) => s.trim());
|
|
187
|
-
for (const sid of skillIds) {
|
|
188
|
-
try {
|
|
189
|
-
const skill = await this.resolveSkill(sid, context);
|
|
190
|
-
prompt += `\n\n---\n\n# Skill: ${sid}\n\n${skill.content}`;
|
|
191
|
-
includedSkills.push(sid);
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
// Skill not found - skip
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
prompt,
|
|
200
|
-
variables,
|
|
201
|
-
includedSkills,
|
|
202
|
-
includedStandards: [],
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
async isAvailable() {
|
|
206
|
-
try {
|
|
207
|
-
const corePath = join(this.projectRoot, 'core');
|
|
208
|
-
await access(corePath);
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
catch {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
async dispose() {
|
|
216
|
-
// LocalResolver holds no resources to release
|
|
217
|
-
}
|
|
218
|
-
}
|
|
1
|
+
import{readFile as f,access as m}from"node:fs/promises";import{join as p,resolve as d}from"node:path";import{ResolverMode as y}from"../types/index.js";const w=/^---\n([\s\S]*?)\n---/;function u(c){const t=c.match(w);if(!t)return{frontmatter:{},body:c};const e={},r=t[1].split(`
|
|
2
|
+
`);for(const n of r){const a=n.indexOf(":");if(a===-1)continue;const i=n.slice(0,a).trim().replace(/^['"]|['"]$/g,"");let o=n.slice(a+1).trim();typeof o=="string"&&(o=o.replace(/^['"]|['"]$/g,"")),o==="true"?o=!0:o==="false"&&(o=!1),e[i]=o}const s=c.slice(t[0].length).trimStart();return{frontmatter:e,body:s}}function $(c){const t=c.split("-");if(t.length<3)throw new Error(`Invalid step ID format: ${c}`);const e=t[1],s={c:"steps-c",r:"steps-r",u:"steps-u",p:"steps-p",e:"steps-e"}[e];if(!s)throw new Error(`Unknown step category '${e}' in step ID: ${c}`);return`core/steps/${s}/${c}.md`}class g{mode=y.LOCAL;projectRoot;constructor(t){this.projectRoot=d(t.projectRoot)}async resolveStep(t,e){const r=$(t),s=p(this.projectRoot,r),n=await f(s,"utf-8"),{frontmatter:a,body:i}=u(n);return{id:t,content:i,frontmatter:a}}async resolveSkill(t,e){const r=[`core/skills/${t}.md`,`core/skills/step-skills/${t}.md`];t.includes("/")&&(r.unshift(`core/skills/step-skills/${t}.md`),r.unshift(`core/skills/${t}.md`));let s=null,n="";for(const o of r){const l=p(this.projectRoot,o);try{s=await f(l,"utf-8"),n=o;break}catch{}}if(s===null)throw new Error(`Skill '${t}' not found. Searched: ${r.join(", ")}`);const{frontmatter:a,body:i}=u(s);return{id:t,content:i,metadata:{...a,resolvedPath:n}}}async resolveStandard(t){const e=p(this.projectRoot,"core","standards",t);let r;try{r=await f(e,"utf-8")}catch{if(!t.endsWith(".md"))r=await f(`${e}.md`,"utf-8");else throw new Error(`Standard '${t}' not found at ${e}`)}return{id:t,content:r}}async resolveRegistry(){const t=p(this.projectRoot,"core","data","step-registry.json"),e=await f(t,"utf-8");return JSON.parse(e)}async assemblePrompt(t,e){const r=await this.resolveStep(t,e),s={"{story_id}":e.storyId,"{story_title}":e.storyTitle,"{step_id}":t,"{step_name}":r.frontmatter.name||t,"{current_status}":e.currentStatus,"{epic_id}":e.epicId,"{branch_name}":e.branchName,"{platform_target}":e.platformTarget};let n=r.content;for(const[o,l]of Object.entries(s))n=n.replaceAll(o,l);const a=[],i=r.frontmatter.skills;if(i&&typeof i=="string"){const o=i.split(",").map(l=>l.trim());for(const l of o)try{const h=await this.resolveSkill(l,e);n+=`
|
|
3
|
+
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Skill: ${l}
|
|
7
|
+
|
|
8
|
+
${h.content}`,a.push(l)}catch{}}return{prompt:n,variables:s,includedSkills:a,includedStandards:[]}}async isAvailable(){try{const t=p(this.projectRoot,"core");return await m(t),!0}catch{return!1}}async dispose(){}}export{g as LocalResolver};
|