instar 0.9.11 → 0.9.13
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/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +78 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +86 -7
- package/dist/commands/server.js.map +1 -1
- package/dist/core/CanonicalState.d.ts +132 -0
- package/dist/core/CanonicalState.d.ts.map +1 -0
- package/dist/core/CanonicalState.js +297 -0
- package/dist/core/CanonicalState.js.map +1 -0
- package/dist/core/CoherenceGate.d.ts +122 -0
- package/dist/core/CoherenceGate.d.ts.map +1 -0
- package/dist/core/CoherenceGate.js +347 -0
- package/dist/core/CoherenceGate.js.map +1 -0
- package/dist/core/ContextHierarchy.d.ts +100 -0
- package/dist/core/ContextHierarchy.d.ts.map +1 -0
- package/dist/core/ContextHierarchy.js +454 -0
- package/dist/core/ContextHierarchy.js.map +1 -0
- package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
- package/dist/core/PostUpdateMigrator.js +140 -0
- package/dist/core/PostUpdateMigrator.js.map +1 -1
- package/dist/core/ProjectMapper.d.ts +97 -0
- package/dist/core/ProjectMapper.d.ts.map +1 -0
- package/dist/core/ProjectMapper.js +364 -0
- package/dist/core/ProjectMapper.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/messaging/TelegramAdapter.d.ts +5 -0
- package/dist/messaging/TelegramAdapter.d.ts.map +1 -1
- package/dist/messaging/TelegramAdapter.js +7 -0
- package/dist/messaging/TelegramAdapter.js.map +1 -1
- package/dist/monitoring/StallTriageNurse.d.ts.map +1 -1
- package/dist/monitoring/StallTriageNurse.js +77 -13
- package/dist/monitoring/StallTriageNurse.js.map +1 -1
- package/dist/scaffold/templates.d.ts.map +1 -1
- package/dist/scaffold/templates.js +10 -0
- package/dist/scaffold/templates.js.map +1 -1
- package/dist/scheduler/JobLoader.d.ts.map +1 -1
- package/dist/scheduler/JobLoader.js +1 -0
- package/dist/scheduler/JobLoader.js.map +1 -1
- package/dist/server/AgentServer.d.ts +4 -0
- package/dist/server/AgentServer.d.ts.map +1 -1
- package/dist/server/AgentServer.js +4 -0
- package/dist/server/AgentServer.js.map +1 -1
- package/dist/server/routes.d.ts +8 -0
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +228 -0
- package/dist/server/routes.js.map +1 -1
- package/package.json +1 -1
- package/upgrades/0.9.12.md +42 -0
- package/upgrades/0.9.13.md +55 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coherence Gate — Pre-action verification for agent coherence.
|
|
3
|
+
*
|
|
4
|
+
* Before high-risk actions (deployment, git push, external API calls),
|
|
5
|
+
* the agent pauses to verify: "Am I in the right project? Does this
|
|
6
|
+
* action match my identity and mission?"
|
|
7
|
+
*
|
|
8
|
+
* Born from the Luna incident (2026-02-25): An agent deployed to the
|
|
9
|
+
* wrong production target because nothing validated that the intended
|
|
10
|
+
* action matched the agent's current context.
|
|
11
|
+
*
|
|
12
|
+
* Design principle: Not a dumb pattern match — an intelligent
|
|
13
|
+
* self-verification that gives the agent the ability to step back,
|
|
14
|
+
* review what it's doing, and catch incoherence before it manifests.
|
|
15
|
+
*
|
|
16
|
+
* Three verification levels:
|
|
17
|
+
* 1. Structural — git remote, working directory, project name match
|
|
18
|
+
* 2. Contextual — action aligns with current topic/conversation scope
|
|
19
|
+
* 3. Intent — action aligns with stated mission/boundaries in AGENT.md
|
|
20
|
+
*/
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { execFileSync } from 'node:child_process';
|
|
24
|
+
export class CoherenceGate {
|
|
25
|
+
config;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Run a full coherence check for a proposed action.
|
|
31
|
+
*/
|
|
32
|
+
check(action, context) {
|
|
33
|
+
const checks = [];
|
|
34
|
+
// Check 1: Working directory matches expected project
|
|
35
|
+
checks.push(this.checkWorkingDirectory());
|
|
36
|
+
// Check 2: Git remote matches expected project
|
|
37
|
+
checks.push(this.checkGitRemote());
|
|
38
|
+
// Check 3: If topic is specified, verify topic-project alignment
|
|
39
|
+
if (context?.topicId) {
|
|
40
|
+
checks.push(this.checkTopicProjectAlignment(context.topicId));
|
|
41
|
+
}
|
|
42
|
+
// Check 4: If deploying, verify deployment target
|
|
43
|
+
if ((action === 'deploy' || action === 'production-change') && context?.targetUrl) {
|
|
44
|
+
checks.push(this.checkDeploymentTarget(context.targetUrl, context.topicId));
|
|
45
|
+
}
|
|
46
|
+
// Check 5: If modifying files, verify path is within project scope
|
|
47
|
+
if (context?.targetPath) {
|
|
48
|
+
checks.push(this.checkPathScope(context.targetPath));
|
|
49
|
+
}
|
|
50
|
+
// Check 6: Agent identity consistency
|
|
51
|
+
checks.push(this.checkAgentIdentity());
|
|
52
|
+
// Determine overall result
|
|
53
|
+
const hasErrors = checks.some(c => !c.passed && c.severity === 'error');
|
|
54
|
+
const hasWarnings = checks.some(c => !c.passed && c.severity === 'warning');
|
|
55
|
+
const passed = !hasErrors;
|
|
56
|
+
const recommendation = hasErrors ? 'block' : hasWarnings ? 'warn' : 'proceed';
|
|
57
|
+
const failedChecks = checks.filter(c => !c.passed);
|
|
58
|
+
const summary = passed
|
|
59
|
+
? `All ${checks.length} coherence checks passed.`
|
|
60
|
+
: `${failedChecks.length}/${checks.length} checks failed: ${failedChecks.map(c => c.message).join('; ')}`;
|
|
61
|
+
return {
|
|
62
|
+
passed,
|
|
63
|
+
checks,
|
|
64
|
+
summary,
|
|
65
|
+
recommendation,
|
|
66
|
+
checkedAt: new Date().toISOString(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generate a self-verification prompt for the agent to reflect before acting.
|
|
71
|
+
* This is the "step back and review" mechanism.
|
|
72
|
+
*/
|
|
73
|
+
generateReflectionPrompt(action, context) {
|
|
74
|
+
const result = this.check(action, context);
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push('=== PRE-ACTION COHERENCE CHECK ===');
|
|
77
|
+
lines.push('');
|
|
78
|
+
lines.push('Before proceeding, verify these assertions are correct:');
|
|
79
|
+
lines.push('');
|
|
80
|
+
// Identity
|
|
81
|
+
lines.push(`1. I am working on: ${this.config.projectName}`);
|
|
82
|
+
lines.push(` Project directory: ${this.config.projectDir}`);
|
|
83
|
+
// Git
|
|
84
|
+
const gitRemote = this.detectGitRemote();
|
|
85
|
+
if (gitRemote) {
|
|
86
|
+
lines.push(` Git remote: ${gitRemote}`);
|
|
87
|
+
}
|
|
88
|
+
// Topic context
|
|
89
|
+
if (context?.topicId && context?.topicName) {
|
|
90
|
+
const binding = this.getTopicBinding(context.topicId);
|
|
91
|
+
if (binding) {
|
|
92
|
+
lines.push(`2. This topic (${context.topicName}) is for: ${binding.projectName}`);
|
|
93
|
+
lines.push(` Expected project dir: ${binding.projectDir}`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
lines.push(`2. This topic (${context.topicName}) has NO project binding.`);
|
|
97
|
+
lines.push(` WARNING: Verify which project this topic is for before proceeding.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Action
|
|
101
|
+
lines.push('');
|
|
102
|
+
lines.push(`Action: ${action}`);
|
|
103
|
+
if (context?.description) {
|
|
104
|
+
lines.push(`Description: ${context.description}`);
|
|
105
|
+
}
|
|
106
|
+
if (context?.targetUrl) {
|
|
107
|
+
lines.push(`Target URL: ${context.targetUrl}`);
|
|
108
|
+
}
|
|
109
|
+
if (context?.targetPath) {
|
|
110
|
+
lines.push(`Target path: ${context.targetPath}`);
|
|
111
|
+
}
|
|
112
|
+
// Check results
|
|
113
|
+
if (!result.passed) {
|
|
114
|
+
lines.push('');
|
|
115
|
+
lines.push('WARNING — COHERENCE ISSUES DETECTED:');
|
|
116
|
+
for (const check of result.checks.filter(c => !c.passed)) {
|
|
117
|
+
const icon = check.severity === 'error' ? '[BLOCK]' : '[WARN]';
|
|
118
|
+
lines.push(` ${icon} ${check.message}`);
|
|
119
|
+
lines.push(` Expected: ${check.expected}`);
|
|
120
|
+
lines.push(` Found: ${check.actual}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
lines.push('');
|
|
124
|
+
lines.push('If any of the above is incorrect, STOP and verify before proceeding.');
|
|
125
|
+
lines.push('=== END COHERENCE CHECK ===');
|
|
126
|
+
return lines.join('\n');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the topic-project binding for a specific topic.
|
|
130
|
+
*/
|
|
131
|
+
getTopicBinding(topicId) {
|
|
132
|
+
return this.config.topicProjects?.[String(topicId)] ?? null;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Register a topic-to-project binding.
|
|
136
|
+
*/
|
|
137
|
+
setTopicBinding(topicId, binding) {
|
|
138
|
+
if (!this.config.topicProjects) {
|
|
139
|
+
this.config.topicProjects = {};
|
|
140
|
+
}
|
|
141
|
+
this.config.topicProjects[String(topicId)] = binding;
|
|
142
|
+
this.saveTopicBindings();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Load topic-project bindings from disk.
|
|
146
|
+
*/
|
|
147
|
+
loadTopicBindings() {
|
|
148
|
+
const bindingsPath = path.join(this.config.stateDir, 'topic-project-bindings.json');
|
|
149
|
+
try {
|
|
150
|
+
if (fs.existsSync(bindingsPath)) {
|
|
151
|
+
const data = JSON.parse(fs.readFileSync(bindingsPath, 'utf-8'));
|
|
152
|
+
this.config.topicProjects = data;
|
|
153
|
+
return data;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch { /* corrupt file */ }
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Save topic-project bindings to disk.
|
|
161
|
+
*/
|
|
162
|
+
saveTopicBindings() {
|
|
163
|
+
const bindingsPath = path.join(this.config.stateDir, 'topic-project-bindings.json');
|
|
164
|
+
fs.mkdirSync(path.dirname(bindingsPath), { recursive: true });
|
|
165
|
+
fs.writeFileSync(bindingsPath, JSON.stringify(this.config.topicProjects || {}, null, 2));
|
|
166
|
+
}
|
|
167
|
+
// ── Individual Checks ──────────────────────────────────────────
|
|
168
|
+
checkWorkingDirectory() {
|
|
169
|
+
let cwd;
|
|
170
|
+
try {
|
|
171
|
+
cwd = process.cwd();
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
cwd = 'unknown';
|
|
175
|
+
}
|
|
176
|
+
const expected = this.config.projectDir;
|
|
177
|
+
const isWithin = cwd.startsWith(expected);
|
|
178
|
+
return {
|
|
179
|
+
name: 'working-directory',
|
|
180
|
+
passed: isWithin,
|
|
181
|
+
expected: `Within ${expected}`,
|
|
182
|
+
actual: cwd,
|
|
183
|
+
severity: 'warning',
|
|
184
|
+
message: isWithin
|
|
185
|
+
? `Working directory is within project scope`
|
|
186
|
+
: `Working directory (${cwd}) is outside project scope (${expected})`,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
checkGitRemote() {
|
|
190
|
+
const actual = this.detectGitRemote();
|
|
191
|
+
const expected = this.config.expectedGitRemote;
|
|
192
|
+
// If no expected remote configured, just report what we found
|
|
193
|
+
if (!expected) {
|
|
194
|
+
return {
|
|
195
|
+
name: 'git-remote',
|
|
196
|
+
passed: true,
|
|
197
|
+
expected: 'any (no expected remote configured)',
|
|
198
|
+
actual: actual || 'no git remote',
|
|
199
|
+
severity: 'info',
|
|
200
|
+
message: actual ? `Git remote: ${actual}` : 'No git remote detected',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const matches = actual !== null && this.normalizeGitUrl(actual) === this.normalizeGitUrl(expected);
|
|
204
|
+
return {
|
|
205
|
+
name: 'git-remote',
|
|
206
|
+
passed: matches,
|
|
207
|
+
expected,
|
|
208
|
+
actual: actual || 'no git remote',
|
|
209
|
+
severity: 'error',
|
|
210
|
+
message: matches
|
|
211
|
+
? `Git remote matches expected project`
|
|
212
|
+
: `Git remote MISMATCH: expected ${expected}, found ${actual || 'none'}`,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
checkTopicProjectAlignment(topicId) {
|
|
216
|
+
const binding = this.getTopicBinding(topicId);
|
|
217
|
+
if (!binding) {
|
|
218
|
+
return {
|
|
219
|
+
name: 'topic-project-alignment',
|
|
220
|
+
passed: false,
|
|
221
|
+
expected: `Topic ${topicId} bound to a specific project`,
|
|
222
|
+
actual: 'No topic-project binding exists',
|
|
223
|
+
severity: 'warning',
|
|
224
|
+
message: `Topic ${topicId} has no project binding — verify which project this topic is for`,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// Check if current project matches the topic's expected project
|
|
228
|
+
const currentProject = this.config.projectDir;
|
|
229
|
+
const expectedProject = binding.projectDir;
|
|
230
|
+
const matches = this.normalizePath(currentProject) === this.normalizePath(expectedProject);
|
|
231
|
+
return {
|
|
232
|
+
name: 'topic-project-alignment',
|
|
233
|
+
passed: matches,
|
|
234
|
+
expected: `${binding.projectName} (${expectedProject})`,
|
|
235
|
+
actual: `${this.config.projectName} (${currentProject})`,
|
|
236
|
+
severity: 'error',
|
|
237
|
+
message: matches
|
|
238
|
+
? `Topic is correctly bound to ${binding.projectName}`
|
|
239
|
+
: `WRONG PROJECT: Topic ${topicId} is for ${binding.projectName} but current project is ${this.config.projectName}`,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
checkDeploymentTarget(targetUrl, topicId) {
|
|
243
|
+
// If we have a topic binding with deployment targets, check against those
|
|
244
|
+
if (topicId) {
|
|
245
|
+
const binding = this.getTopicBinding(topicId);
|
|
246
|
+
if (binding?.deploymentTargets && binding.deploymentTargets.length > 0) {
|
|
247
|
+
const allowed = binding.deploymentTargets.some(t => targetUrl.includes(t) || t.includes(targetUrl));
|
|
248
|
+
return {
|
|
249
|
+
name: 'deployment-target',
|
|
250
|
+
passed: allowed,
|
|
251
|
+
expected: binding.deploymentTargets.join(', '),
|
|
252
|
+
actual: targetUrl,
|
|
253
|
+
severity: 'error',
|
|
254
|
+
message: allowed
|
|
255
|
+
? `Deployment target matches project configuration`
|
|
256
|
+
: `WRONG DEPLOY TARGET: ${targetUrl} is not in allowed targets for ${binding.projectName}`,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// No specific check possible without bindings
|
|
261
|
+
return {
|
|
262
|
+
name: 'deployment-target',
|
|
263
|
+
passed: true,
|
|
264
|
+
expected: 'any (no deployment targets configured)',
|
|
265
|
+
actual: targetUrl,
|
|
266
|
+
severity: 'warning',
|
|
267
|
+
message: `Deploying to ${targetUrl} — no deployment target restrictions configured`,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
checkPathScope(targetPath) {
|
|
271
|
+
const resolvedPath = path.resolve(targetPath);
|
|
272
|
+
const projectDir = path.resolve(this.config.projectDir);
|
|
273
|
+
const isWithin = resolvedPath.startsWith(projectDir);
|
|
274
|
+
return {
|
|
275
|
+
name: 'path-scope',
|
|
276
|
+
passed: isWithin,
|
|
277
|
+
expected: `Within ${projectDir}`,
|
|
278
|
+
actual: resolvedPath,
|
|
279
|
+
severity: 'error',
|
|
280
|
+
message: isWithin
|
|
281
|
+
? `Target path is within project scope`
|
|
282
|
+
: `PATH OUTSIDE PROJECT: ${resolvedPath} is outside ${projectDir}`,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
checkAgentIdentity() {
|
|
286
|
+
const agentMdPath = path.join(this.config.stateDir, 'AGENT.md');
|
|
287
|
+
if (!fs.existsSync(agentMdPath)) {
|
|
288
|
+
return {
|
|
289
|
+
name: 'agent-identity',
|
|
290
|
+
passed: false,
|
|
291
|
+
expected: 'AGENT.md exists with identity',
|
|
292
|
+
actual: 'AGENT.md not found',
|
|
293
|
+
severity: 'warning',
|
|
294
|
+
message: 'No AGENT.md found — agent identity not established',
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const content = fs.readFileSync(agentMdPath, 'utf-8');
|
|
299
|
+
const hasName = /^#\s+.+/m.test(content);
|
|
300
|
+
const hasIntent = /##\s+Intent/i.test(content);
|
|
301
|
+
return {
|
|
302
|
+
name: 'agent-identity',
|
|
303
|
+
passed: hasName,
|
|
304
|
+
expected: 'AGENT.md with name and intent',
|
|
305
|
+
actual: `Name: ${hasName ? 'yes' : 'no'}, Intent: ${hasIntent ? 'yes' : 'no'}`,
|
|
306
|
+
severity: hasName ? 'info' : 'warning',
|
|
307
|
+
message: hasName
|
|
308
|
+
? `Agent identity established${hasIntent ? ' with intent section' : ''}`
|
|
309
|
+
: 'AGENT.md exists but has no agent name',
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
return {
|
|
314
|
+
name: 'agent-identity',
|
|
315
|
+
passed: false,
|
|
316
|
+
expected: 'Readable AGENT.md',
|
|
317
|
+
actual: 'Failed to read AGENT.md',
|
|
318
|
+
severity: 'warning',
|
|
319
|
+
message: 'Failed to read AGENT.md',
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// ── Helpers ──────────────────────────────────────────
|
|
324
|
+
detectGitRemote() {
|
|
325
|
+
try {
|
|
326
|
+
return execFileSync('git', ['remote', 'get-url', 'origin'], {
|
|
327
|
+
cwd: this.config.projectDir,
|
|
328
|
+
encoding: 'utf-8',
|
|
329
|
+
stdio: 'pipe',
|
|
330
|
+
}).trim() || null;
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
normalizeGitUrl(url) {
|
|
337
|
+
return url
|
|
338
|
+
.replace(/\.git$/, '')
|
|
339
|
+
.replace(/^https:\/\/github\.com\//, '')
|
|
340
|
+
.replace(/^git@github\.com:/, '')
|
|
341
|
+
.toLowerCase();
|
|
342
|
+
}
|
|
343
|
+
normalizePath(p) {
|
|
344
|
+
return path.resolve(p).replace(/\/+$/, '');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=CoherenceGate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoherenceGate.js","sourceRoot":"","sources":["../../src/core/CoherenceGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAgElD,MAAM,OAAO,aAAa;IAChB,MAAM,CAAsB;IAEpC,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAsB,EAAE,OAK7B;QACC,MAAM,MAAM,GAAqB,EAAE,CAAC;QAEpC,sDAAsD;QACtD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;QAE1C,+CAA+C;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAEnC,iEAAiE;QACjE,IAAI,OAAO,EAAE,OAAO,EAAE,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAChE,CAAC;QAED,kDAAkD;QAClD,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,mBAAmB,CAAC,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;YAClF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9E,CAAC;QAED,mEAAmE;QACnE,IA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AC;IACnB,CAAC;IAEO,aAAa,CAAC,CAAS;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Hierarchy — Tiered context loading for efficient agent awareness.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Dawn's context dispatch system (PROP-088): right context at
|
|
5
|
+
* the right moment > all context all the time.
|
|
6
|
+
*
|
|
7
|
+
* Three tiers:
|
|
8
|
+
* Tier 0: Always loaded (identity, project scope, safety rules)
|
|
9
|
+
* Tier 1: Session boundaries (continuity, compaction recovery, topic context)
|
|
10
|
+
* Tier 2: On-demand (task-specific depth when context matches)
|
|
11
|
+
*
|
|
12
|
+
* The hierarchy creates a `.instar/context/` directory with structured
|
|
13
|
+
* segment files that hooks and sessions can load selectively.
|
|
14
|
+
*
|
|
15
|
+
* Born from the Luna incident (2026-02-25): An agent had no systematic
|
|
16
|
+
* way to load task-relevant context efficiently. Without a hierarchy,
|
|
17
|
+
* agents either load everything (context bloat) or nothing (incoherence).
|
|
18
|
+
*/
|
|
19
|
+
export interface ContextSegment {
|
|
20
|
+
/** Unique identifier for this segment */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Human-readable name */
|
|
23
|
+
name: string;
|
|
24
|
+
/** Context tier: 0 = always, 1 = session boundaries, 2 = on-demand */
|
|
25
|
+
tier: 0 | 1 | 2;
|
|
26
|
+
/** When to load this context (for tier 2) */
|
|
27
|
+
triggers: string[];
|
|
28
|
+
/** File path relative to .instar/context/ */
|
|
29
|
+
file: string;
|
|
30
|
+
/** Description of what this context provides */
|
|
31
|
+
description: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ContextHierarchyConfig {
|
|
34
|
+
/** Instar state directory */
|
|
35
|
+
stateDir: string;
|
|
36
|
+
/** Project root directory */
|
|
37
|
+
projectDir: string;
|
|
38
|
+
/** Project name */
|
|
39
|
+
projectName: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ContextDispatchTable {
|
|
42
|
+
/** When this task arises... */
|
|
43
|
+
trigger: string;
|
|
44
|
+
/** Load this context file */
|
|
45
|
+
file: string;
|
|
46
|
+
/** Why this context helps */
|
|
47
|
+
reason: string;
|
|
48
|
+
}
|
|
49
|
+
export declare class ContextHierarchy {
|
|
50
|
+
private config;
|
|
51
|
+
private contextDir;
|
|
52
|
+
constructor(config: ContextHierarchyConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Initialize the context directory with default segment files.
|
|
55
|
+
* Only creates files that don't already exist (additive only).
|
|
56
|
+
*/
|
|
57
|
+
initialize(): {
|
|
58
|
+
created: string[];
|
|
59
|
+
skipped: string[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Get the dispatch table — a mapping of triggers to context files.
|
|
63
|
+
* This is what agents read to know "when X happens, load Y."
|
|
64
|
+
*/
|
|
65
|
+
getDispatchTable(): ContextDispatchTable[];
|
|
66
|
+
/**
|
|
67
|
+
* Write the dispatch table to a human-readable file.
|
|
68
|
+
*/
|
|
69
|
+
writeDispatchTable(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Load all segments for a given tier.
|
|
72
|
+
* Returns concatenated content suitable for hook injection.
|
|
73
|
+
*/
|
|
74
|
+
loadTier(tier: 0 | 1 | 2): string;
|
|
75
|
+
/**
|
|
76
|
+
* Load a specific context segment by ID.
|
|
77
|
+
*/
|
|
78
|
+
loadSegment(segmentId: string): string | null;
|
|
79
|
+
/**
|
|
80
|
+
* List all context segments with their status.
|
|
81
|
+
*/
|
|
82
|
+
listSegments(): Array<ContextSegment & {
|
|
83
|
+
exists: boolean;
|
|
84
|
+
sizeBytes: number;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Get the context directory path.
|
|
88
|
+
*/
|
|
89
|
+
getContextDir(): string;
|
|
90
|
+
private generateSegmentTemplate;
|
|
91
|
+
private identityTemplate;
|
|
92
|
+
private safetyTemplate;
|
|
93
|
+
private projectTemplate;
|
|
94
|
+
private sessionTemplate;
|
|
95
|
+
private relationshipsTemplate;
|
|
96
|
+
private developmentTemplate;
|
|
97
|
+
private deploymentTemplate;
|
|
98
|
+
private communicationTemplate;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=ContextHierarchy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextHierarchy.d.ts","sourceRoot":"","sources":["../../src/core/ContextHierarchy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAsED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,sBAAsB;IAK1C;;;OAGG;IACH,UAAU,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,CA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