@aaac/runtime 0.1.55 → 0.2.0
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/README.md +6 -11
- package/dist/adapters/adk-sdk.d.ts +3 -3
- package/dist/adapters/adk-sdk.js +6 -8
- package/dist/adapters/adk-sdk.js.map +1 -1
- package/dist/adapters/claude-agent-sdk.d.ts +3 -3
- package/dist/adapters/claude-agent-sdk.js +22 -23
- package/dist/adapters/claude-agent-sdk.js.map +1 -1
- package/dist/adapters/mock.d.ts +2 -3
- package/dist/adapters/openai-agents-sdk.d.ts +3 -3
- package/dist/adapters/openai-agents-sdk.js +6 -5
- package/dist/adapters/openai-agents-sdk.js.map +1 -1
- package/dist/chunk-2INQL5TG.js +298 -0
- package/dist/chunk-2INQL5TG.js.map +1 -0
- package/dist/chunk-3CLWG72V.js +47 -0
- package/dist/chunk-3CLWG72V.js.map +1 -0
- package/dist/chunk-3DDB34BU.js +237 -0
- package/dist/chunk-3DDB34BU.js.map +1 -0
- package/dist/chunk-ABXDSTUV.js +685 -0
- package/dist/chunk-ABXDSTUV.js.map +1 -0
- package/dist/{chunk-3H3PVPPF.js → chunk-F5R46S7I.js} +151 -204
- package/dist/chunk-F5R46S7I.js.map +1 -0
- package/dist/chunk-FKAI54OM.js +234 -0
- package/dist/chunk-FKAI54OM.js.map +1 -0
- package/dist/chunk-KTVMMG33.js +1111 -0
- package/dist/chunk-KTVMMG33.js.map +1 -0
- package/dist/chunk-MSVIEEGR.js +269 -0
- package/dist/chunk-MSVIEEGR.js.map +1 -0
- package/dist/chunk-VJXGCWSZ.js +36 -0
- package/dist/chunk-VJXGCWSZ.js.map +1 -0
- package/dist/claude-bundles/full.js +311 -309
- package/dist/claude-bundles/lean.js +6 -6
- package/dist/claude-bundles/prompt.js +17 -0
- package/dist/generator/index.d.ts +2 -2
- package/dist/generator/index.js +8 -7
- package/dist/guardrail-hooks-CB23nhZV.d.ts +202 -0
- package/dist/hook-protocol-CFnNudiV.d.ts +96 -0
- package/dist/hooks-lite-CoWWnCRH.d.ts +428 -0
- package/dist/index-BlSepCSZ.d.ts +296 -0
- package/dist/index.d.ts +785 -105
- package/dist/index.js +2189 -634
- package/dist/index.js.map +1 -1
- package/dist/lib/claude-native/hooks-lite.d.ts +3 -26
- package/dist/lib/claude-native/hooks-lite.js +18 -36
- package/dist/lib/claude-native/hooks-prompt.d.ts +5 -0
- package/dist/lib/claude-native/hooks-prompt.js +33 -0
- package/dist/lib/claude-native/hooks-prompt.js.map +1 -0
- package/dist/lib/claude-native/index.d.ts +56 -214
- package/dist/lib/claude-native/index.js +79 -280
- package/dist/lib/claude-native/index.js.map +1 -1
- package/dist/{navigation-context-D_E1NIUf.d.ts → navigation-context-B-RpUg3_.d.ts} +1 -1
- package/dist/navigation-index-prompt-CbrS5laO.d.ts +43 -0
- package/dist/{task-runner-DfIEorkU.d.ts → task-runner-GWoI7_71.d.ts} +100 -493
- package/dist/workspace-user-prompt-submit-D11Iu0zO.d.ts +269 -0
- package/package.json +15 -6
- package/dist/chunk-3H3PVPPF.js.map +0 -1
- package/dist/chunk-DBM5XN67.js +0 -354
- package/dist/chunk-DBM5XN67.js.map +0 -1
- package/dist/chunk-KXGUWBGK.js +0 -370
- package/dist/chunk-KXGUWBGK.js.map +0 -1
- package/dist/chunk-LDCQZPDG.js +0 -11
- package/dist/chunk-LDCQZPDG.js.map +0 -1
- package/dist/chunk-N4KNGDYY.js +0 -1963
- package/dist/chunk-N4KNGDYY.js.map +0 -1
- package/dist/chunk-NMX4C6LC.js +0 -332
- package/dist/chunk-NMX4C6LC.js.map +0 -1
- package/dist/chunk-QVH5KKBR.js +0 -374
- package/dist/chunk-QVH5KKBR.js.map +0 -1
- package/dist/context-DKkamYX_.d.ts +0 -31
- package/dist/guardrail-hooks-slK-z0Dz.d.ts +0 -83
- package/dist/index-LqEvaRk-.d.ts +0 -299
- package/dist/workspace-pre-tool-use-C6nidc0q.d.ts +0 -333
|
@@ -1,87 +1,93 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildNavigationContext,
|
|
3
|
-
|
|
4
|
-
} from "../../chunk-
|
|
3
|
+
resolveNavigationSources
|
|
4
|
+
} from "../../chunk-ABXDSTUV.js";
|
|
5
5
|
import "../../chunk-ET6TGQRT.js";
|
|
6
|
-
import "../../chunk-
|
|
6
|
+
import "../../chunk-F5R46S7I.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
createPreToolUseHandler,
|
|
9
|
+
createWorkspacePreToolUseHandler,
|
|
10
|
+
formatNdjson,
|
|
11
|
+
generateCandidates,
|
|
12
|
+
handleFileSuggestion,
|
|
13
|
+
handleWorkspaceFileSuggestion,
|
|
14
|
+
routePathToMember,
|
|
15
|
+
stripMemberPrefix
|
|
16
|
+
} from "../../chunk-2INQL5TG.js";
|
|
11
17
|
import {
|
|
12
|
-
|
|
18
|
+
createUserPromptSubmitHandler,
|
|
19
|
+
createWorkspaceUserPromptSubmitHandler,
|
|
20
|
+
readFreshMemberIndices,
|
|
21
|
+
renderMemberSection,
|
|
22
|
+
renderNavigationDiagnostics,
|
|
23
|
+
runEnsureNavigationIndexBin
|
|
24
|
+
} from "../../chunk-FKAI54OM.js";
|
|
25
|
+
import {
|
|
26
|
+
renderNavigationIndexPrompt
|
|
27
|
+
} from "../../chunk-3CLWG72V.js";
|
|
28
|
+
import {
|
|
29
|
+
DEFAULT_CACHE_KEY,
|
|
13
30
|
buildAllowResponse,
|
|
14
31
|
buildContextResponse,
|
|
15
32
|
buildDenyResponse,
|
|
33
|
+
computeCurrentHash,
|
|
16
34
|
computeSourceHash,
|
|
17
35
|
createCacheStore,
|
|
18
|
-
createExclusiveLock,
|
|
19
|
-
createPreToolUseHandler,
|
|
20
|
-
createWorkspacePreToolUseHandler,
|
|
21
36
|
emitHookOutput,
|
|
37
|
+
guardrailCacheKey,
|
|
38
|
+
isCachedRecord,
|
|
22
39
|
isProtectedArtifact,
|
|
23
40
|
listArtifacts,
|
|
24
41
|
parseHookInput,
|
|
42
|
+
readFreshNavigationBuild,
|
|
25
43
|
readHookInput,
|
|
26
|
-
resolvePathToArtifacts
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
withDegrade,
|
|
30
|
-
withTimeout
|
|
31
|
-
} from "../../chunk-QVH5KKBR.js";
|
|
32
|
-
import {
|
|
33
|
-
guardrailCacheKey
|
|
34
|
-
} from "../../chunk-LDCQZPDG.js";
|
|
35
|
-
import "../../chunk-NMX4C6LC.js";
|
|
44
|
+
resolvePathToArtifacts
|
|
45
|
+
} from "../../chunk-3DDB34BU.js";
|
|
46
|
+
import "../../chunk-MSVIEEGR.js";
|
|
36
47
|
import "../../chunk-BJ7B4R26.js";
|
|
37
48
|
|
|
38
|
-
// src/lib/claude-native/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!existsSync(manifestPath)) {
|
|
44
|
-
const projectDslPath2 = resolve(options.projectRoot, options.dslPath);
|
|
45
|
-
return {
|
|
46
|
-
navigationOptions: { projectDslPath: projectDslPath2, embeddedDsl: options.embeddedDsl },
|
|
47
|
-
sourceFiles: [projectDslPath2]
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const config = await loadProjectConfig(manifestPath);
|
|
51
|
-
const sourceFiles = [manifestPath];
|
|
52
|
-
const projectDslPath = config.dslDeclared ? config.dslPath : void 0;
|
|
53
|
-
if (projectDslPath) {
|
|
54
|
-
sourceFiles.push(projectDslPath);
|
|
49
|
+
// src/lib/claude-native/latency.ts
|
|
50
|
+
var TimeoutError = class extends Error {
|
|
51
|
+
constructor(ms) {
|
|
52
|
+
super(`Operation timed out after ${ms}ms`);
|
|
53
|
+
this.name = "TimeoutError";
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
};
|
|
56
|
+
async function withTimeout(promise, timeoutMs) {
|
|
57
|
+
if (timeoutMs <= 0) return promise;
|
|
58
|
+
let timer;
|
|
59
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
60
|
+
timer = setTimeout(() => reject(new TimeoutError(timeoutMs)), timeoutMs);
|
|
61
|
+
});
|
|
62
|
+
try {
|
|
63
|
+
return await Promise.race([promise, timeout]);
|
|
64
|
+
} finally {
|
|
65
|
+
clearTimeout(timer);
|
|
58
66
|
}
|
|
59
|
-
|
|
67
|
+
}
|
|
68
|
+
function createExclusiveLock() {
|
|
69
|
+
let pending = null;
|
|
60
70
|
return {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
sourceFiles
|
|
71
|
+
async run(fn) {
|
|
72
|
+
if (pending) return pending;
|
|
73
|
+
pending = fn().finally(() => {
|
|
74
|
+
pending = null;
|
|
75
|
+
});
|
|
76
|
+
return pending;
|
|
77
|
+
}
|
|
69
78
|
};
|
|
70
79
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const hidden = diagnostics.length - lines.length;
|
|
79
|
-
if (hidden > 0) {
|
|
80
|
-
lines.push(` - \u2026 ${hidden} more`);
|
|
80
|
+
async function withDegrade(operation, fallback, timeoutMs) {
|
|
81
|
+
try {
|
|
82
|
+
const value = await withTimeout(operation(), timeoutMs);
|
|
83
|
+
return { value, degraded: false };
|
|
84
|
+
} catch (err) {
|
|
85
|
+
const reason = err instanceof TimeoutError ? err.message : err instanceof Error ? err.message : String(err);
|
|
86
|
+
return { value: fallback, degraded: true, reason };
|
|
81
87
|
}
|
|
82
|
-
return [`${label} diagnostics (${diagnostics.length}):`, ...lines].join("\n");
|
|
83
88
|
}
|
|
84
|
-
|
|
89
|
+
|
|
90
|
+
// src/lib/claude-native/ensure-navigation-index.ts
|
|
85
91
|
var buildLocks = /* @__PURE__ */ new Map();
|
|
86
92
|
function getBuildLock(key) {
|
|
87
93
|
let lock = buildLocks.get(key);
|
|
@@ -91,34 +97,22 @@ function getBuildLock(key) {
|
|
|
91
97
|
}
|
|
92
98
|
return lock;
|
|
93
99
|
}
|
|
94
|
-
async function computeCurrentHash(sourceFiles) {
|
|
95
|
-
const mtimes = [];
|
|
96
|
-
for (const file of sourceFiles) {
|
|
97
|
-
try {
|
|
98
|
-
const s = await stat(file);
|
|
99
|
-
mtimes.push(s.mtimeMs);
|
|
100
|
-
} catch {
|
|
101
|
-
mtimes.push(`missing:${file}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return computeSourceHash(mtimes);
|
|
105
|
-
}
|
|
106
100
|
async function ensureNavigationIndex(options) {
|
|
107
101
|
const cacheKey = options.cacheKey ?? DEFAULT_CACHE_KEY;
|
|
108
102
|
return getBuildLock(cacheKey).run(async () => {
|
|
109
103
|
const store = createCacheStore({ cacheDir: options.cacheDir });
|
|
110
104
|
const currentHash = await computeCurrentHash(options.sourceFiles);
|
|
111
|
-
const cached = await
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
);
|
|
105
|
+
const cached = await readFreshNavigationBuild({
|
|
106
|
+
cacheDir: options.cacheDir,
|
|
107
|
+
cacheKey
|
|
108
|
+
});
|
|
115
109
|
if (cached) {
|
|
116
|
-
return { navigationIndex: cached, fromCache: true };
|
|
110
|
+
return { navigationIndex: cached.navigationIndex, fromCache: true };
|
|
117
111
|
}
|
|
118
112
|
const context = await buildNavigationContext(options.navigationOptions);
|
|
119
113
|
const navigationIndex = context.navigationIndex;
|
|
120
114
|
try {
|
|
121
|
-
await store.write(cacheKey, navigationIndex, currentHash);
|
|
115
|
+
await store.write(cacheKey, navigationIndex, currentHash, options.sourceFiles);
|
|
122
116
|
} catch {
|
|
123
117
|
}
|
|
124
118
|
try {
|
|
@@ -137,102 +131,6 @@ async function ensureNavigationIndex(options) {
|
|
|
137
131
|
});
|
|
138
132
|
}
|
|
139
133
|
|
|
140
|
-
// src/lib/claude-native/file-suggestion.ts
|
|
141
|
-
var DEFAULT_MAX_CANDIDATES = 100;
|
|
142
|
-
function generateCandidates(prefix, options) {
|
|
143
|
-
const { navigationIndex, maxCandidates = DEFAULT_MAX_CANDIDATES } = options;
|
|
144
|
-
const artifacts = listArtifacts(navigationIndex);
|
|
145
|
-
const candidates = [];
|
|
146
|
-
const lowerPrefix = prefix.toLowerCase();
|
|
147
|
-
const rootPath = (path) => joinPathPrefix(options.pathPrefix, path);
|
|
148
|
-
for (const { id, artifact } of artifacts) {
|
|
149
|
-
const props = artifact.properties ?? {};
|
|
150
|
-
const patterns = artifact.files?.path_patterns ?? [];
|
|
151
|
-
if (!prefix || id.toLowerCase().includes(lowerPrefix)) {
|
|
152
|
-
candidates.push({
|
|
153
|
-
label: id,
|
|
154
|
-
path: rootPath(patterns.length > 0 ? String(patterns[0]) : id),
|
|
155
|
-
kind: "artifact",
|
|
156
|
-
authority: props.authority,
|
|
157
|
-
manual_edit: props.manual_edit,
|
|
158
|
-
score: computeArtifactScore(id, artifact, prefix)
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
for (const pattern of patterns) {
|
|
162
|
-
if (typeof pattern !== "string") continue;
|
|
163
|
-
if (pattern.includes("*") || pattern.includes("?")) continue;
|
|
164
|
-
if (!prefix || pattern.toLowerCase().includes(lowerPrefix)) {
|
|
165
|
-
candidates.push({
|
|
166
|
-
label: pattern,
|
|
167
|
-
path: rootPath(pattern),
|
|
168
|
-
kind: "file",
|
|
169
|
-
artifact: id,
|
|
170
|
-
authority: props.authority,
|
|
171
|
-
manual_edit: props.manual_edit,
|
|
172
|
-
score: computeFileScore(pattern, prefix)
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
candidates.sort((a, b) => {
|
|
178
|
-
if (b.score !== a.score) return b.score - a.score;
|
|
179
|
-
return a.label.localeCompare(b.label);
|
|
180
|
-
});
|
|
181
|
-
return candidates.slice(0, maxCandidates);
|
|
182
|
-
}
|
|
183
|
-
function joinPathPrefix(prefix, path) {
|
|
184
|
-
if (!prefix) return path;
|
|
185
|
-
const normalized = prefix.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
186
|
-
return normalized ? `${normalized}/${path}` : path;
|
|
187
|
-
}
|
|
188
|
-
function formatNdjson(candidates) {
|
|
189
|
-
return candidates.map((c) => JSON.stringify(c)).join("\n");
|
|
190
|
-
}
|
|
191
|
-
function computeArtifactScore(id, artifact, prefix) {
|
|
192
|
-
let score = 50;
|
|
193
|
-
const props = artifact.properties ?? {};
|
|
194
|
-
if (props.authority === "canonical") score += 20;
|
|
195
|
-
if (props.manual_edit === "allowed") score += 10;
|
|
196
|
-
if (props.type === "source") score += 15;
|
|
197
|
-
if (props.authority === "generated") score -= 20;
|
|
198
|
-
if (props.manual_edit === "forbidden") score -= 10;
|
|
199
|
-
if (prefix && id.toLowerCase().startsWith(prefix.toLowerCase())) {
|
|
200
|
-
score += 20;
|
|
201
|
-
}
|
|
202
|
-
return score;
|
|
203
|
-
}
|
|
204
|
-
function computeFileScore(path, prefix) {
|
|
205
|
-
let score = 40;
|
|
206
|
-
if (prefix && path.toLowerCase().startsWith(prefix.toLowerCase())) {
|
|
207
|
-
score += 30;
|
|
208
|
-
}
|
|
209
|
-
score += Math.max(0, 20 - path.split("/").length * 2);
|
|
210
|
-
return score;
|
|
211
|
-
}
|
|
212
|
-
async function handleFileSuggestion(navigationIndex, stdinData) {
|
|
213
|
-
const prefix = stdinData.trim();
|
|
214
|
-
const candidates = generateCandidates(prefix, { navigationIndex });
|
|
215
|
-
return formatNdjson(candidates);
|
|
216
|
-
}
|
|
217
|
-
async function handleWorkspaceFileSuggestion(cacheDir, members, stdinData, maxCandidates = DEFAULT_MAX_CANDIDATES) {
|
|
218
|
-
const prefix = stdinData.trim();
|
|
219
|
-
const store = createCacheStore({ cacheDir });
|
|
220
|
-
const merged = [];
|
|
221
|
-
for (const member of members) {
|
|
222
|
-
const entry = await store.read(member.cacheKey);
|
|
223
|
-
if (!entry) continue;
|
|
224
|
-
merged.push(
|
|
225
|
-
...generateCandidates(prefix, {
|
|
226
|
-
navigationIndex: entry.data,
|
|
227
|
-
pathPrefix: member.memberPath,
|
|
228
|
-
maxCandidates: Number.POSITIVE_INFINITY
|
|
229
|
-
})
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
merged.sort((a, b) => b.score !== a.score ? b.score - a.score : a.label.localeCompare(b.label));
|
|
233
|
-
return formatNdjson(merged.slice(0, maxCandidates));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
134
|
// src/lib/claude-native/session-start.ts
|
|
237
135
|
function createSessionStartHandler(config) {
|
|
238
136
|
return async function handleSessionStart(_input) {
|
|
@@ -254,71 +152,7 @@ function createSessionStartHandler(config) {
|
|
|
254
152
|
};
|
|
255
153
|
}
|
|
256
154
|
|
|
257
|
-
// src/lib/claude-native/
|
|
258
|
-
function createUserPromptSubmitHandler(config) {
|
|
259
|
-
return async function handleUserPromptSubmit(input) {
|
|
260
|
-
const prompt = input.prompt ?? "";
|
|
261
|
-
const navResult = await ensureNavigationIndex({
|
|
262
|
-
cacheDir: config.cacheDir,
|
|
263
|
-
sourceFiles: config.sourceFiles,
|
|
264
|
-
navigationOptions: config.navigationOptions
|
|
265
|
-
});
|
|
266
|
-
const navigationIndex = navResult.navigationIndex;
|
|
267
|
-
const navigationSummary = renderNavigationIndexPrompt(navigationIndex);
|
|
268
|
-
const sections = [
|
|
269
|
-
// renderNavigationIndexPrompt already emits the "## Project Navigation
|
|
270
|
-
// Index" heading — don't duplicate it here.
|
|
271
|
-
navigationSummary,
|
|
272
|
-
"",
|
|
273
|
-
"> Use `analyzer.getContextMap` with candidate paths/artifacts from the index",
|
|
274
|
-
"> when you need structured dependency and read-target guidance."
|
|
275
|
-
];
|
|
276
|
-
const candidates = renderCandidateArtifacts(prompt, navigationIndex);
|
|
277
|
-
if (candidates) {
|
|
278
|
-
sections.push(candidates);
|
|
279
|
-
}
|
|
280
|
-
const additionalContext = sections.join("\n");
|
|
281
|
-
return buildContextResponse("UserPromptSubmit", additionalContext);
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
function renderCandidateArtifacts(prompt, navigationIndex, heading = "## Candidate Artifacts (from prompt keywords)") {
|
|
285
|
-
const candidates = extractCandidateArtifacts(prompt, navigationIndex);
|
|
286
|
-
if (candidates.length === 0) return void 0;
|
|
287
|
-
const lines = candidates.map((c) => {
|
|
288
|
-
const props = c.artifact.properties ?? {};
|
|
289
|
-
const tags = [props.type, props.authority, props.manual_edit ? `edit:${props.manual_edit}` : ""].filter(Boolean).join(", ");
|
|
290
|
-
return `- ${c.artifactId} [${tags}]`;
|
|
291
|
-
});
|
|
292
|
-
return `${heading}
|
|
293
|
-
${lines.join("\n")}`;
|
|
294
|
-
}
|
|
295
|
-
function extractCandidateArtifacts(prompt, navigationIndex) {
|
|
296
|
-
if (!prompt.trim()) return [];
|
|
297
|
-
const artifacts = listArtifacts(navigationIndex);
|
|
298
|
-
const lowerPrompt = prompt.toLowerCase();
|
|
299
|
-
const matches = [];
|
|
300
|
-
const seen = /* @__PURE__ */ new Set();
|
|
301
|
-
for (const { id, artifact } of artifacts) {
|
|
302
|
-
if (lowerPrompt.includes(id.toLowerCase()) && !seen.has(id)) {
|
|
303
|
-
seen.add(id);
|
|
304
|
-
matches.push({ artifactId: id, artifact });
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
const patterns = artifact.files?.path_patterns ?? [];
|
|
308
|
-
for (const pattern of patterns) {
|
|
309
|
-
if (typeof pattern !== "string") continue;
|
|
310
|
-
const literal = pattern.replace(/[*?]/g, "").replace(/\{.*\}/g, "");
|
|
311
|
-
if (literal.length > 3 && lowerPrompt.includes(literal.toLowerCase()) && !seen.has(id)) {
|
|
312
|
-
seen.add(id);
|
|
313
|
-
matches.push({ artifactId: id, artifact });
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return matches;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// src/lib/claude-native/workspace-members.ts
|
|
155
|
+
// src/lib/claude-native/workspace-session-start.ts
|
|
322
156
|
async function ensureMemberIndices(cacheDir, members) {
|
|
323
157
|
return Promise.all(
|
|
324
158
|
members.map(async (member) => ({
|
|
@@ -332,20 +166,6 @@ async function ensureMemberIndices(cacheDir, members) {
|
|
|
332
166
|
}))
|
|
333
167
|
);
|
|
334
168
|
}
|
|
335
|
-
function renderMemberSection({ member, result }) {
|
|
336
|
-
const summary = renderNavigationIndexPrompt(result.navigationIndex);
|
|
337
|
-
const cacheNote = result.fromCache ? "(loaded from cache)" : "(freshly built)";
|
|
338
|
-
const diagnostics = renderNavigationDiagnostics(
|
|
339
|
-
result.diagnostics,
|
|
340
|
-
`${member.name} navigation-index`
|
|
341
|
-
);
|
|
342
|
-
return `### Member: ${member.name} ${cacheNote}
|
|
343
|
-
${summary}` + (diagnostics ? `
|
|
344
|
-
|
|
345
|
-
${diagnostics}` : "");
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/lib/claude-native/workspace-session-start.ts
|
|
349
169
|
function createWorkspaceSessionStartHandler(config) {
|
|
350
170
|
return async function handleWorkspaceSessionStart(_input) {
|
|
351
171
|
const results = await ensureMemberIndices(config.cacheDir, config.members);
|
|
@@ -357,38 +177,13 @@ function createWorkspaceSessionStartHandler(config) {
|
|
|
357
177
|
return buildContextResponse("SessionStart", additionalContext);
|
|
358
178
|
};
|
|
359
179
|
}
|
|
360
|
-
|
|
361
|
-
// src/lib/claude-native/workspace-user-prompt-submit.ts
|
|
362
|
-
function createWorkspaceUserPromptSubmitHandler(config) {
|
|
363
|
-
return async function handleWorkspaceUserPromptSubmit(input) {
|
|
364
|
-
const prompt = input.prompt ?? "";
|
|
365
|
-
const results = await ensureMemberIndices(config.cacheDir, config.members);
|
|
366
|
-
const sections = [];
|
|
367
|
-
for (const entry of results) {
|
|
368
|
-
sections.push(renderMemberSection(entry));
|
|
369
|
-
const candidates = renderCandidateArtifacts(
|
|
370
|
-
prompt,
|
|
371
|
-
entry.result.navigationIndex,
|
|
372
|
-
`#### Candidate Artifacts in ${entry.member.name} (from prompt keywords)`
|
|
373
|
-
);
|
|
374
|
-
if (candidates) {
|
|
375
|
-
sections.push(candidates);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
const additionalContext = [
|
|
379
|
-
sections.join("\n\n"),
|
|
380
|
-
"",
|
|
381
|
-
"> Use `analyzer.getContextMap` with candidate paths/artifacts from a member's index",
|
|
382
|
-
"> when you need structured dependency and read-target guidance."
|
|
383
|
-
].join("\n");
|
|
384
|
-
return buildContextResponse("UserPromptSubmit", additionalContext);
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
180
|
export {
|
|
181
|
+
DEFAULT_CACHE_KEY,
|
|
388
182
|
TimeoutError,
|
|
389
183
|
buildAllowResponse,
|
|
390
184
|
buildContextResponse,
|
|
391
185
|
buildDenyResponse,
|
|
186
|
+
computeCurrentHash,
|
|
392
187
|
computeSourceHash,
|
|
393
188
|
createCacheStore,
|
|
394
189
|
createExclusiveLock,
|
|
@@ -405,15 +200,19 @@ export {
|
|
|
405
200
|
generateCandidates,
|
|
406
201
|
handleFileSuggestion,
|
|
407
202
|
handleWorkspaceFileSuggestion,
|
|
203
|
+
isCachedRecord,
|
|
408
204
|
isProtectedArtifact,
|
|
409
205
|
listArtifacts,
|
|
410
206
|
parseHookInput,
|
|
207
|
+
readFreshMemberIndices,
|
|
208
|
+
readFreshNavigationBuild,
|
|
411
209
|
readHookInput,
|
|
412
210
|
renderMemberSection,
|
|
413
211
|
renderNavigationDiagnostics,
|
|
414
212
|
resolveNavigationSources,
|
|
415
213
|
resolvePathToArtifacts,
|
|
416
214
|
routePathToMember,
|
|
215
|
+
runEnsureNavigationIndexBin,
|
|
417
216
|
stripMemberPrefix,
|
|
418
217
|
withDegrade,
|
|
419
218
|
withTimeout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/claude-native/navigation-sources.ts","../../../src/lib/claude-native/ensure-navigation-index.ts","../../../src/lib/claude-native/file-suggestion.ts","../../../src/lib/claude-native/session-start.ts","../../../src/lib/claude-native/user-prompt-submit.ts","../../../src/lib/claude-native/workspace-members.ts","../../../src/lib/claude-native/workspace-session-start.ts","../../../src/lib/claude-native/workspace-user-prompt-submit.ts"],"sourcesContent":["/**\n * Navigation sources — resolve the project manifest into the inputs the\n * navigation-index hooks need (which DSL to overlay, which artifact registry to\n * bind, which files invalidate the cache).\n *\n * The generated `.claude/bin/*` nav hooks bake only what cannot be read from\n * disk at hook time: the component's bundled `/$embedded/` DSL. Everything the\n * project manifest declares (`agents:`, `artifacts:`) is resolved HERE, at hook\n * runtime, through the same `loadProjectConfig` loader the CLI uses — so a\n * manifest edit takes effect without re-running `claude sync`, and the hooks\n * cannot drift from the CLI's view of the project\n * (docs/proposal/workspace-subproject-guardrail.md §3.2).\n */\n\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport {\n loadProjectConfig,\n PROJECT_CONFIG_FILENAME,\n} from \"../../generator/config.js\";\nimport type { NavigationContextOptions } from \"../navigation-context.js\";\n\nexport interface ResolveNavigationSourcesOptions {\n /**\n * Root of the project whose navigation-index is being built: the directory\n * that owns `project.yaml` (in workspace mode, the member root).\n */\n projectRoot: string;\n /**\n * The component's bundled `/$embedded/` DSL, baked into the hook bin by\n * `claude sync`. Undefined for `aaac generate` output, where the bin resolves\n * `dslPath` directly.\n */\n embeddedDsl?: Record<string, unknown>;\n /**\n * Project-root-relative agents DSL path used ONLY when `projectRoot` has no\n * `project.yaml` (a bare component checkout). With a manifest present the\n * manifest's `agents:` wins.\n */\n dslPath: string;\n}\n\nexport interface NavigationSources {\n navigationOptions: NavigationContextOptions;\n /** Files whose mtime invalidates the navigation-index cache. */\n sourceFiles: string[];\n}\n\n/**\n * Resolve the navigation-index inputs for one project root.\n *\n * With a `project.yaml` present, the manifest is authoritative:\n * - `agents:` → the DSL overlaid on `embeddedDsl` (omitted = embedded as-is),\n * - `artifacts:` → the artifact-contracts registry bound onto the DSL\n * artifacts, so path_patterns / authority / manual_edit reflect the project\n * rather than the component's built-in defaults,\n * - `bindings.guardrail` + `active_guardrail_policy` → the guardrail checks the\n * PreToolUse hook enforces, resolved by the same code as the CLI (#267).\n * All resolved files feed `sourceFiles`, so editing any of them rebuilds the\n * index on the next hook invocation.\n */\nexport async function resolveNavigationSources(\n options: ResolveNavigationSourcesOptions,\n): Promise<NavigationSources> {\n const manifestPath = resolve(options.projectRoot, PROJECT_CONFIG_FILENAME);\n\n if (!existsSync(manifestPath)) {\n const projectDslPath = resolve(options.projectRoot, options.dslPath);\n return {\n navigationOptions: { projectDslPath, embeddedDsl: options.embeddedDsl },\n sourceFiles: [projectDslPath],\n };\n }\n\n const config = await loadProjectConfig(manifestPath);\n const sourceFiles = [manifestPath];\n\n // An undeclared `agents:` means \"no overlay\" — `config.dslPath` is then just\n // the schema default and pointing the loader at it would be a hard failure.\n const projectDslPath = config.dslDeclared ? config.dslPath : undefined;\n if (projectDslPath) {\n sourceFiles.push(projectDslPath);\n }\n\n if (config.artifactsPath) {\n sourceFiles.push(config.artifactsPath);\n }\n\n // Guardrail bindings feed the PreToolUse Bash guard, and edits to them must\n // rebuild the index (#267).\n sourceFiles.push(...config.bindingPaths);\n\n return {\n navigationOptions: {\n ...(projectDslPath ? { projectDslPath } : {}),\n embeddedDsl: options.embeddedDsl,\n ...(config.artifactsPath\n ? { artifactBinding: { source: config.artifactsPath } }\n : {}),\n bindingPaths: config.bindingPaths,\n ...(config.active_guardrail_policy\n ? { activeGuardrailPolicy: config.active_guardrail_policy }\n : {}),\n },\n sourceFiles,\n };\n}\n","/**\n * Ensure Navigation Index — cache warm / invalidation.\n *\n * Checks cache freshness via source file mtime comparison. If stale,\n * calls buildNavigationContext() and writes to .claude/cache/.\n * If fresh, returns cached data immediately.\n *\n * This is the performance-critical path for SessionStart hooks.\n */\n\nimport { stat } from \"node:fs/promises\";\nimport { buildNavigationContext, type NavigationContextOptions } from \"../navigation-context.js\";\nimport {\n createCacheStore,\n computeSourceHash,\n type CacheStore,\n} from \"./cache-store.js\";\nimport { createExclusiveLock } from \"./latency.js\";\nimport { guardrailCacheKey } from \"./ensure-navigation-index-keys.js\";\n\nexport { GUARDRAIL_CACHE_SUFFIX, guardrailCacheKey } from \"./ensure-navigation-index-keys.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface EnsureNavigationIndexOptions {\n /** Absolute path to .claude/cache/ directory. */\n cacheDir: string;\n /** Paths to source files whose mtime drives cache invalidation. */\n sourceFiles: string[];\n /** Options for buildNavigationContext() when cache is stale. */\n navigationOptions: NavigationContextOptions;\n /**\n * Cache key for the stored JSON file (default: `\"navigation-index\"`).\n *\n * In workspace mode each member uses its own key, e.g.\n * `\"navigation-index.aaac\"`, so their caches remain isolated.\n * Single-component callers omit this field and the default preserves\n * byte-identical behaviour with previous versions.\n */\n cacheKey?: string;\n}\n\nexport interface NavigationIndexResult {\n navigationIndex: Record<string, unknown>;\n /** Whether the result was loaded from cache (true) or freshly built (false). */\n fromCache: boolean;\n /**\n * Diagnostics from the build that produced this index — artifact-binding\n * findings (`unbound-artifact` / `orphan-binding` / `type-mismatch`) and\n * schema validation issues. Present only on a fresh build: they describe the\n * DSL/registry the index was built from, so a caller that hit the cache has\n * already been told once. Callers MUST surface them (a dropped\n * `orphan-binding` is exactly how a project's artifact registry silently\n * fails to reach the hooks — #260).\n */\n diagnostics?: Array<{ path: string; message: string; severity: string }>;\n}\n\n// ---------------------------------------------------------------------------\n// Diagnostics rendering\n// ---------------------------------------------------------------------------\n\n/**\n * How many diagnostics are spelled out before collapsing into a count. Sized to\n * show a whole artifact registry's binding findings (unbound + orphan) for a\n * typical project rather than truncating the picture the reader needs.\n */\nconst MAX_RENDERED_DIAGNOSTICS = 20;\n\n/**\n * Render build diagnostics as hook context lines. Returns undefined when there\n * is nothing to report, so callers can skip the section entirely.\n */\nexport function renderNavigationDiagnostics(\n diagnostics: NavigationIndexResult[\"diagnostics\"],\n label = \"navigation-index\",\n): string | undefined {\n if (!diagnostics || diagnostics.length === 0) return undefined;\n\n const lines = diagnostics\n .slice(0, MAX_RENDERED_DIAGNOSTICS)\n .map((d) => ` - [${d.severity}] ${d.path}: ${d.message}`);\n const hidden = diagnostics.length - lines.length;\n if (hidden > 0) {\n lines.push(` - … ${hidden} more`);\n }\n\n return [`${label} diagnostics (${diagnostics.length}):`, ...lines].join(\"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// Implementation\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_CACHE_KEY = \"navigation-index\";\n\n/**\n * Per-key exclusive locks so concurrent session-start calls for distinct\n * workspace members can build their indices in parallel, while duplicate calls\n * for the same key are deduplicated (share the in-flight promise).\n */\nconst buildLocks = new Map<string, ReturnType<typeof createExclusiveLock<NavigationIndexResult>>>();\n\nfunction getBuildLock(key: string): ReturnType<typeof createExclusiveLock<NavigationIndexResult>> {\n let lock = buildLocks.get(key);\n if (!lock) {\n lock = createExclusiveLock<NavigationIndexResult>();\n buildLocks.set(key, lock);\n }\n return lock;\n}\n\n/**\n * Collect mtimes for source files and produce a cache hash.\n */\nasync function computeCurrentHash(sourceFiles: string[]): Promise<string> {\n const mtimes: Array<string | number> = [];\n for (const file of sourceFiles) {\n try {\n const s = await stat(file);\n mtimes.push(s.mtimeMs);\n } catch {\n // File not found — include a sentinel so hash changes if file appears\n mtimes.push(`missing:${file}`);\n }\n }\n return computeSourceHash(mtimes);\n}\n\n/**\n * Ensure the navigation index is available and fresh. Returns the index\n * data, building + caching if necessary.\n *\n * In workspace mode, pass a unique `cacheKey` per member (e.g.\n * `\"navigation-index.aaac\"`) so each member's index is stored and\n * invalidated independently.\n */\nexport async function ensureNavigationIndex(\n options: EnsureNavigationIndexOptions,\n): Promise<NavigationIndexResult> {\n const cacheKey = options.cacheKey ?? DEFAULT_CACHE_KEY;\n\n return getBuildLock(cacheKey).run(async () => {\n const store: CacheStore = createCacheStore({ cacheDir: options.cacheDir });\n const currentHash = await computeCurrentHash(options.sourceFiles);\n\n // Try cache first\n const cached = await store.readIfFresh<Record<string, unknown>>(\n cacheKey,\n currentHash,\n );\n if (cached) {\n return { navigationIndex: cached, fromCache: true };\n }\n\n // Cache miss or stale — rebuild\n const context = await buildNavigationContext(options.navigationOptions);\n const navigationIndex = context.navigationIndex;\n\n // Write to cache (non-blocking error handling)\n try {\n await store.write(cacheKey, navigationIndex, currentHash);\n } catch {\n // Cache write failure is non-fatal\n }\n\n // Persist the member's DSL guardrail rules in a companion cache entry so\n // the lean PreToolUse hook can wire Bash guardrails without importing the\n // heavy agent-contracts DSL loader (#238 / C5). We always write, even when\n // there are no rules, so a stale non-empty entry cannot survive a DSL edit\n // that removed all guardrails.\n try {\n await store.write(\n guardrailCacheKey(cacheKey),\n context.guardrailRules ?? { commandRules: [], fileRules: [], contentRules: [] },\n currentHash,\n );\n } catch {\n // Cache write failure is non-fatal\n }\n\n return {\n navigationIndex,\n fromCache: false,\n ...(context.diagnostics.length > 0 ? { diagnostics: context.diagnostics } : {}),\n };\n });\n}\n","/**\n * File Suggestion Handler — artifact-aware @ completion for Claude Code.\n *\n * Reads stdin prefix, filters navigation-index artifacts, and emits NDJSON\n * candidates sorted by relevance score.\n */\n\nimport { listArtifacts, type NavigationArtifact } from \"./artifact-resolver.js\";\nimport { createCacheStore } from \"./cache-store.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface FileSuggestionCandidate {\n label: string;\n path: string;\n kind: \"artifact\" | \"file\";\n /** Artifact ID this file/pattern belongs to. */\n artifact?: string;\n /** Authority of the artifact (canonical, generated, etc.). */\n authority?: string;\n /** Manual edit policy for the artifact. */\n manual_edit?: string;\n /** Relevance score (higher = more relevant). */\n score: number;\n}\n\nexport interface FileSuggestionOptions {\n /** The navigation index to search. */\n navigationIndex: Record<string, unknown>;\n /** Maximum number of candidates to return. */\n maxCandidates?: number;\n /**\n * Prefix prepended to every emitted path (#266). Artifact `path_patterns` are\n * project-root relative, so in a workspace — where Claude Code's cwd is the\n * workspace root — a member's candidates must be re-rooted under the member\n * directory. The mirror image of `stripMemberPrefix` on the PreToolUse side.\n */\n pathPrefix?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Implementation\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_MAX_CANDIDATES = 100;\n\n/**\n * Generate file suggestion candidates from the navigation index.\n * Filters by prefix if provided, then returns NDJSON-formatted candidates.\n */\nexport function generateCandidates(\n prefix: string,\n options: FileSuggestionOptions,\n): FileSuggestionCandidate[] {\n const { navigationIndex, maxCandidates = DEFAULT_MAX_CANDIDATES } = options;\n const artifacts = listArtifacts(navigationIndex);\n const candidates: FileSuggestionCandidate[] = [];\n const lowerPrefix = prefix.toLowerCase();\n const rootPath = (path: string) => joinPathPrefix(options.pathPrefix, path);\n\n for (const { id, artifact } of artifacts) {\n const props = artifact.properties ?? {};\n const patterns = artifact.files?.path_patterns ?? [];\n\n // Artifact-level candidate\n if (!prefix || id.toLowerCase().includes(lowerPrefix)) {\n candidates.push({\n label: id,\n path: rootPath(patterns.length > 0 ? String(patterns[0]) : id),\n kind: \"artifact\",\n authority: props.authority as string | undefined,\n manual_edit: props.manual_edit as string | undefined,\n score: computeArtifactScore(id, artifact, prefix),\n });\n }\n\n // File-level candidates from path patterns\n for (const pattern of patterns) {\n if (typeof pattern !== \"string\") continue;\n // Skip pure glob patterns for file-level suggestions (they're covered by artifact-level)\n if (pattern.includes(\"*\") || pattern.includes(\"?\")) continue;\n\n if (!prefix || pattern.toLowerCase().includes(lowerPrefix)) {\n candidates.push({\n label: pattern,\n path: rootPath(pattern),\n kind: \"file\",\n artifact: id,\n authority: props.authority as string | undefined,\n manual_edit: props.manual_edit as string | undefined,\n score: computeFileScore(pattern, prefix),\n });\n }\n }\n }\n\n // Sort by score descending, then by label\n candidates.sort((a, b) => {\n if (b.score !== a.score) return b.score - a.score;\n return a.label.localeCompare(b.label);\n });\n\n return candidates.slice(0, maxCandidates);\n}\n\n/** Join a member path prefix with a project-relative path. */\nfunction joinPathPrefix(prefix: string | undefined, path: string): string {\n if (!prefix) return path;\n const normalized = prefix.replace(/^\\.\\//, \"\").replace(/\\/+$/, \"\");\n return normalized ? `${normalized}/${path}` : path;\n}\n\n/**\n * Format candidates as NDJSON (one JSON object per line).\n */\nexport function formatNdjson(candidates: FileSuggestionCandidate[]): string {\n return candidates.map((c) => JSON.stringify(c)).join(\"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// Scoring helpers\n// ---------------------------------------------------------------------------\n\nfunction computeArtifactScore(\n id: string,\n artifact: NavigationArtifact,\n prefix: string,\n): number {\n let score = 50;\n const props = artifact.properties ?? {};\n\n // Boost canonical, editable artifacts\n if (props.authority === \"canonical\") score += 20;\n if (props.manual_edit === \"allowed\") score += 10;\n\n // Boost source artifacts\n if (props.type === \"source\") score += 15;\n\n // Penalize generated artifacts\n if (props.authority === \"generated\") score -= 20;\n if (props.manual_edit === \"forbidden\") score -= 10;\n\n // Boost exact prefix match\n if (prefix && id.toLowerCase().startsWith(prefix.toLowerCase())) {\n score += 20;\n }\n\n return score;\n}\n\nfunction computeFileScore(path: string, prefix: string): number {\n let score = 40;\n\n // Boost exact prefix match\n if (prefix && path.toLowerCase().startsWith(prefix.toLowerCase())) {\n score += 30;\n }\n\n // Boost shorter paths (more specific)\n score += Math.max(0, 20 - path.split(\"/\").length * 2);\n\n return score;\n}\n\n/**\n * Main handler for file-suggestion bin script.\n * Reads prefix from stdin, returns NDJSON candidates to stdout.\n */\nexport async function handleFileSuggestion(\n navigationIndex: Record<string, unknown>,\n stdinData: string,\n): Promise<string> {\n const prefix = stdinData.trim();\n const candidates = generateCandidates(prefix, { navigationIndex });\n return formatNdjson(candidates);\n}\n\n/** One workspace member's cached index, as the file-suggestion bin knows it. */\nexport interface WorkspaceFileSuggestionMember {\n /** Member name (for diagnostics only). */\n name: string;\n /** Workspace-relative member path — prepended to every candidate path. */\n memberPath: string;\n /** Cache key of this member's navigation-index. */\n cacheKey: string;\n}\n\n/**\n * Workspace variant (#266): merge candidates from every member's own index.\n *\n * The single-component handler reads the lone `navigation-index` cache entry,\n * which workspace mode never writes (each member has its own key) — so `@`\n * completion returned nothing at all. Members whose index has not been built yet\n * are skipped rather than failing the hook: SessionStart warms them.\n */\nexport async function handleWorkspaceFileSuggestion(\n cacheDir: string,\n members: WorkspaceFileSuggestionMember[],\n stdinData: string,\n maxCandidates = DEFAULT_MAX_CANDIDATES,\n): Promise<string> {\n const prefix = stdinData.trim();\n const store = createCacheStore({ cacheDir });\n const merged: FileSuggestionCandidate[] = [];\n\n for (const member of members) {\n const entry = await store.read<Record<string, unknown>>(member.cacheKey);\n if (!entry) continue;\n merged.push(\n ...generateCandidates(prefix, {\n navigationIndex: entry.data,\n pathPrefix: member.memberPath,\n maxCandidates: Number.POSITIVE_INFINITY,\n }),\n );\n }\n\n merged.sort((a, b) => (b.score !== a.score ? b.score - a.score : a.label.localeCompare(b.label)));\n return formatNdjson(merged.slice(0, maxCandidates));\n}\n","/**\n * SessionStart Hook Handler — cache warm + navigation-index summary injection.\n *\n * Executed on session new/resume/clear/compact events. Warms the navigation-index\n * cache and returns a rendered summary as additionalContext.\n *\n * Latency constraint: NO AST analysis or ContextPack generation.\n */\n\nimport { renderNavigationIndexPrompt } from \"../task-runner.js\";\nimport {\n ensureNavigationIndex,\n renderNavigationDiagnostics,\n type EnsureNavigationIndexOptions,\n} from \"./ensure-navigation-index.js\";\nimport {\n buildContextResponse,\n type HookOutput,\n type SessionStartInput,\n} from \"./hook-protocol.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface SessionStartHandlerConfig {\n /** Absolute path to .claude/cache/ directory. */\n cacheDir: string;\n /** Source files for cache invalidation (component.yaml, agent-contracts.yaml, etc.). */\n sourceFiles: string[];\n /** Options for buildNavigationContext(). */\n navigationOptions: EnsureNavigationIndexOptions[\"navigationOptions\"];\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\n/**\n * Create a SessionStart hook handler.\n */\nexport function createSessionStartHandler(config: SessionStartHandlerConfig) {\n return async function handleSessionStart(\n _input: SessionStartInput,\n ): Promise<HookOutput> {\n const result = await ensureNavigationIndex({\n cacheDir: config.cacheDir,\n sourceFiles: config.sourceFiles,\n navigationOptions: config.navigationOptions,\n });\n\n const summary = renderNavigationIndexPrompt(result.navigationIndex);\n const cacheNote = result.fromCache\n ? \"(loaded from cache)\"\n : \"(freshly built)\";\n\n const diagnostics = renderNavigationDiagnostics(result.diagnostics);\n\n const additionalContext = [\n summary,\n \"\",\n `Navigation index ${cacheNote}. Use analyzer MCP tools for deep investigation.`,\n ...(diagnostics ? [\"\", diagnostics] : []),\n ].join(\"\\n\");\n\n return buildContextResponse(\"SessionStart\", additionalContext);\n };\n}\n","/**\n * UserPromptSubmit Hook Handler — navigation-index summary injection.\n *\n * Executed after prompt submission, before Claude processes it. Provides a\n * compact navigation-index summary so the LLM can pick candidates and delegate\n * deep exploration to `analyzer.getContextMap` (Level 2).\n *\n * ContextPack is NOT pre-injected by default (#206 Phase D).\n */\n\nimport { renderNavigationIndexPrompt } from \"../task-runner.js\";\nimport {\n ensureNavigationIndex,\n type EnsureNavigationIndexOptions,\n} from \"./ensure-navigation-index.js\";\nimport {\n listArtifacts,\n} from \"./artifact-resolver.js\";\nimport {\n buildContextResponse,\n type HookOutput,\n type UserPromptSubmitInput,\n} from \"./hook-protocol.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface UserPromptSubmitHandlerConfig {\n /** Absolute path to .claude/cache/ directory. */\n cacheDir: string;\n /** Source files for cache invalidation. */\n sourceFiles: string[];\n /** Options for buildNavigationContext(). */\n navigationOptions: EnsureNavigationIndexOptions[\"navigationOptions\"];\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\n/**\n * Create a UserPromptSubmit hook handler.\n */\nexport function createUserPromptSubmitHandler(\n config: UserPromptSubmitHandlerConfig,\n) {\n return async function handleUserPromptSubmit(\n input: UserPromptSubmitInput,\n ): Promise<HookOutput> {\n const prompt = input.prompt ?? \"\";\n\n const navResult = await ensureNavigationIndex({\n cacheDir: config.cacheDir,\n sourceFiles: config.sourceFiles,\n navigationOptions: config.navigationOptions,\n });\n const navigationIndex = navResult.navigationIndex;\n const navigationSummary = renderNavigationIndexPrompt(navigationIndex);\n\n const sections: string[] = [\n // renderNavigationIndexPrompt already emits the \"## Project Navigation\n // Index\" heading — don't duplicate it here.\n navigationSummary,\n \"\",\n \"> Use `analyzer.getContextMap` with candidate paths/artifacts from the index\",\n \"> when you need structured dependency and read-target guidance.\",\n ];\n\n const candidates = renderCandidateArtifacts(prompt, navigationIndex);\n if (candidates) {\n sections.push(candidates);\n }\n\n const additionalContext = sections.join(\"\\n\");\n return buildContextResponse(\"UserPromptSubmit\", additionalContext);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\ninterface CandidateArtifact {\n artifactId: string;\n artifact: ReturnType<typeof listArtifacts>[number][\"artifact\"];\n}\n\n/**\n * Render the prompt-keyword candidate section, or undefined when nothing matched.\n * Shared with the workspace handler, which renders one section per member.\n */\nexport function renderCandidateArtifacts(\n prompt: string,\n navigationIndex: Record<string, unknown>,\n heading = \"## Candidate Artifacts (from prompt keywords)\",\n): string | undefined {\n const candidates = extractCandidateArtifacts(prompt, navigationIndex);\n if (candidates.length === 0) return undefined;\n\n const lines = candidates.map((c) => {\n const props = c.artifact.properties ?? {};\n const tags = [props.type, props.authority, props.manual_edit ? `edit:${props.manual_edit}` : \"\"]\n .filter(Boolean)\n .join(\", \");\n return `- ${c.artifactId} [${tags}]`;\n });\n return `${heading}\\n${lines.join(\"\\n\")}`;\n}\n\nfunction extractCandidateArtifacts(\n prompt: string,\n navigationIndex: Record<string, unknown>,\n): CandidateArtifact[] {\n if (!prompt.trim()) return [];\n\n const artifacts = listArtifacts(navigationIndex);\n const lowerPrompt = prompt.toLowerCase();\n const matches: CandidateArtifact[] = [];\n const seen = new Set<string>();\n\n for (const { id, artifact } of artifacts) {\n if (lowerPrompt.includes(id.toLowerCase()) && !seen.has(id)) {\n seen.add(id);\n matches.push({ artifactId: id, artifact });\n continue;\n }\n\n const patterns = artifact.files?.path_patterns ?? [];\n for (const pattern of patterns) {\n if (typeof pattern !== \"string\") continue;\n const literal = pattern.replace(/[*?]/g, \"\").replace(/\\{.*\\}/g, \"\");\n if (literal.length > 3 && lowerPrompt.includes(literal.toLowerCase()) && !seen.has(id)) {\n seen.add(id);\n matches.push({ artifactId: id, artifact });\n break;\n }\n }\n }\n\n return matches;\n}\n","/**\n * Workspace member navigation — the shared warm-up + rendering used by every\n * workspace hook that needs per-member navigation indices (SessionStart and\n * UserPromptSubmit). One member = one navigation-index cache entry.\n *\n * Heavy path (pulls ensureNavigationIndex → navigation-context → agent-contracts);\n * never import from the lean `hooks-lite` entry.\n */\n\nimport { renderNavigationIndexPrompt } from \"../task-runner.js\";\nimport {\n ensureNavigationIndex,\n renderNavigationDiagnostics,\n type EnsureNavigationIndexOptions,\n type NavigationIndexResult,\n} from \"./ensure-navigation-index.js\";\n\nexport interface WorkspaceMemberNavConfig {\n /** Human-readable member name (e.g. `\"aaac\"`). */\n name: string;\n /** Absolute path to member root directory. */\n root: string;\n /**\n * Unique cache key for this member's navigation-index JSON.\n * Format: `navigation-index.<name>`.\n */\n cacheKey: string;\n /** Source files for mtime-based cache invalidation. */\n sourceFiles: string[];\n /** Options passed to `buildNavigationContext()` on cache miss. */\n navigationOptions: EnsureNavigationIndexOptions[\"navigationOptions\"];\n}\n\nexport interface WorkspaceMemberNavResult {\n member: WorkspaceMemberNavConfig;\n result: NavigationIndexResult;\n}\n\n/**\n * Build (or validate) every member's navigation-index in **parallel** — each\n * cache key has its own exclusive lock, so concurrent calls for the same member\n * deduplicate rather than queue behind other members.\n */\nexport async function ensureMemberIndices(\n cacheDir: string,\n members: WorkspaceMemberNavConfig[],\n): Promise<WorkspaceMemberNavResult[]> {\n return Promise.all(\n members.map(async (member) => ({\n member,\n result: await ensureNavigationIndex({\n cacheDir,\n sourceFiles: member.sourceFiles,\n navigationOptions: member.navigationOptions,\n cacheKey: member.cacheKey,\n }),\n })),\n );\n}\n\n/** One member's context section: index summary + freshness + build diagnostics. */\nexport function renderMemberSection({ member, result }: WorkspaceMemberNavResult): string {\n const summary = renderNavigationIndexPrompt(result.navigationIndex);\n const cacheNote = result.fromCache ? \"(loaded from cache)\" : \"(freshly built)\";\n const diagnostics = renderNavigationDiagnostics(\n result.diagnostics,\n `${member.name} navigation-index`,\n );\n return (\n `### Member: ${member.name} ${cacheNote}\\n${summary}` +\n (diagnostics ? `\\n\\n${diagnostics}` : \"\")\n );\n}\n","/**\n * Workspace SessionStart Hook Handler — per-member navigation-index warm-up.\n *\n * Builds (or validates) a cached navigation-index for each declared workspace\n * member in parallel, then returns a combined summary as `additionalContext`.\n *\n * This module is in the **heavy** path (imports ensureNavigationIndex →\n * navigation-context → agent-contracts) and is therefore NOT included in the\n * lean hooks-lite entry point. SessionStart fires only once per session, so\n * the higher import cost is acceptable.\n */\n\nimport {\n ensureMemberIndices,\n renderMemberSection,\n type WorkspaceMemberNavConfig,\n} from \"./workspace-members.js\";\nimport {\n buildContextResponse,\n type HookOutput,\n type SessionStartInput,\n} from \"./hook-protocol.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface WorkspaceSessionStartConfig {\n /** Absolute path to the shared `.claude/cache/` directory. */\n cacheDir: string;\n /** Workspace members to build/validate indices for. */\n members: WorkspaceMemberNavConfig[];\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\n/**\n * Create a workspace-aware SessionStart hook handler.\n */\nexport function createWorkspaceSessionStartHandler(\n config: WorkspaceSessionStartConfig,\n) {\n return async function handleWorkspaceSessionStart(\n _input: SessionStartInput,\n ): Promise<HookOutput> {\n const results = await ensureMemberIndices(config.cacheDir, config.members);\n\n const additionalContext = [\n results.map(renderMemberSection).join(\"\\n\\n\"),\n \"\",\n \"Workspace navigation indices ready. Use analyzer MCP tools for deep investigation.\",\n ].join(\"\\n\");\n\n return buildContextResponse(\"SessionStart\", additionalContext);\n };\n}\n","/**\n * Workspace UserPromptSubmit Hook Handler — per-member navigation context.\n *\n * The workspace hook set previously emitted the SINGLE-component ContextPack bin\n * at the workspace root (#263): SessionStart and PreToolUse were member-aware\n * while prompt submission saw only the root manifest, so no member's artifacts\n * reached the prompt. This mirrors the SessionStart handler — one index per\n * member — and adds prompt-keyword candidates per member.\n *\n * Heavy path (ensureNavigationIndex → agent-contracts); not part of hooks-lite.\n */\n\nimport {\n ensureMemberIndices,\n renderMemberSection,\n type WorkspaceMemberNavConfig,\n} from \"./workspace-members.js\";\nimport { renderCandidateArtifacts } from \"./user-prompt-submit.js\";\nimport {\n buildContextResponse,\n type HookOutput,\n type UserPromptSubmitInput,\n} from \"./hook-protocol.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface WorkspaceUserPromptSubmitConfig {\n /** Absolute path to the shared `.claude/cache/` directory. */\n cacheDir: string;\n /** Workspace members whose indices feed the prompt context. */\n members: WorkspaceMemberNavConfig[];\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\nexport function createWorkspaceUserPromptSubmitHandler(\n config: WorkspaceUserPromptSubmitConfig,\n) {\n return async function handleWorkspaceUserPromptSubmit(\n input: UserPromptSubmitInput,\n ): Promise<HookOutput> {\n const prompt = input.prompt ?? \"\";\n const results = await ensureMemberIndices(config.cacheDir, config.members);\n\n const sections: string[] = [];\n for (const entry of results) {\n sections.push(renderMemberSection(entry));\n const candidates = renderCandidateArtifacts(\n prompt,\n entry.result.navigationIndex,\n `#### Candidate Artifacts in ${entry.member.name} (from prompt keywords)`,\n );\n if (candidates) {\n sections.push(candidates);\n }\n }\n\n const additionalContext = [\n sections.join(\"\\n\\n\"),\n \"\",\n \"> Use `analyzer.getContextMap` with candidate paths/artifacts from a member's index\",\n \"> when you need structured dependency and read-target guidance.\",\n ].join(\"\\n\");\n\n return buildContextResponse(\"UserPromptSubmit\", additionalContext);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AA8CxB,eAAsB,yBACpB,SAC4B;AAC5B,QAAM,eAAe,QAAQ,QAAQ,aAAa,uBAAuB;AAEzE,MAAI,CAAC,WAAW,YAAY,GAAG;AAC7B,UAAMA,kBAAiB,QAAQ,QAAQ,aAAa,QAAQ,OAAO;AACnE,WAAO;AAAA,MACL,mBAAmB,EAAE,gBAAAA,iBAAgB,aAAa,QAAQ,YAAY;AAAA,MACtE,aAAa,CAACA,eAAc;AAAA,IAC9B;AAAA,EACF;AAEA,QAAM,SAAS,MAAM,kBAAkB,YAAY;AACnD,QAAM,cAAc,CAAC,YAAY;AAIjC,QAAM,iBAAiB,OAAO,cAAc,OAAO,UAAU;AAC7D,MAAI,gBAAgB;AAClB,gBAAY,KAAK,cAAc;AAAA,EACjC;AAEA,MAAI,OAAO,eAAe;AACxB,gBAAY,KAAK,OAAO,aAAa;AAAA,EACvC;AAIA,cAAY,KAAK,GAAG,OAAO,YAAY;AAEvC,SAAO;AAAA,IACL,mBAAmB;AAAA,MACjB,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,MAC3C,aAAa,QAAQ;AAAA,MACrB,GAAI,OAAO,gBACP,EAAE,iBAAiB,EAAE,QAAQ,OAAO,cAAc,EAAE,IACpD,CAAC;AAAA,MACL,cAAc,OAAO;AAAA,MACrB,GAAI,OAAO,0BACP,EAAE,uBAAuB,OAAO,wBAAwB,IACxD,CAAC;AAAA,IACP;AAAA,IACA;AAAA,EACF;AACF;;;AChGA,SAAS,YAAY;AA2DrB,IAAM,2BAA2B;AAM1B,S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UAAU,4BAA4B,OAAO,eAAe;AAClE,QAAM,YAAY,OAAO,YAAY,wBAAwB;AAC7D,QAAM,cAAc;AAAA,IAClB,OAAO;AAAA,IACP,GAAG,OAAO,IAAI;AAAA,EAChB;AACA,SACE,eAAe,OAAO,IAAI,IAAI,SAAS;AAAA,EAAK,OAAO,MAClD,cAAc;AAAA;AAAA,EAAO,WAAW,KAAK;AAE1C;;;AC/BO,SAAS,mCACd,QACA;AACA,SAAO,eAAe,4BACpB,QACqB;AACrB,UAAM,UAAU,MAAM,oBAAoB,OAAO,UAAU,OAAO,OAAO;AAEzE,UAAM,oBAAoB;AAAA,MACxB,QAAQ,IAAI,mBAAmB,EAAE,KAAK,MAAM;AAAA,MAC5C;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAEX,WAAO,qBAAqB,gBAAgB,iBAAiB;AAAA,EAC/D;AACF;;;AClBO,SAAS,uCACd,QACA;AACA,SAAO,eAAe,gCACpB,OACqB;AACrB,UAAM,SAAS,MAAM,UAAU;AAC/B,UAAM,UAAU,MAAM,oBAAoB,OAAO,UAAU,OAAO,OAAO;AAEzE,UAAM,WAAqB,CAAC;AAC5B,eAAW,SAAS,SAAS;AAC3B,eAAS,KAAK,oBAAoB,KAAK,CAAC;AACxC,YAAM,aAAa;AAAA,QACjB;AAAA,QACA,MAAM,OAAO;AAAA,QACb,+BAA+B,MAAM,OAAO,IAAI;AAAA,MAClD;AACA,UAAI,YAAY;AACd,iBAAS,KAAK,UAAU;AAAA,MAC1B;AAAA,IACF;AAEA,UAAM,oBAAoB;AAAA,MACxB,SAAS,KAAK,MAAM;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAEX,WAAO,qBAAqB,oBAAoB,iBAAiB;AAAA,EACnE;AACF;","names":["projectDslPath"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/claude-native/latency.ts","../../../src/lib/claude-native/ensure-navigation-index.ts","../../../src/lib/claude-native/session-start.ts","../../../src/lib/claude-native/workspace-session-start.ts"],"sourcesContent":["/**\n * Latency utilities — timeout wrapper, graph build exclusion, degrade policy.\n *\n * Mirrors the Promise-sharing pattern from analyzer-bridge.ts for concurrent\n * graph build exclusion.\n */\n\n// ---------------------------------------------------------------------------\n// Timeout wrapper\n// ---------------------------------------------------------------------------\n\nexport class TimeoutError extends Error {\n constructor(ms: number) {\n super(`Operation timed out after ${ms}ms`);\n this.name = \"TimeoutError\";\n }\n}\n\n/**\n * Race a promise against a timeout. Resolves with the promise result or\n * rejects with TimeoutError.\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n): Promise<T> {\n if (timeoutMs <= 0) return promise;\n\n let timer: ReturnType<typeof setTimeout>;\n const timeout = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => reject(new TimeoutError(timeoutMs)), timeoutMs);\n });\n\n try {\n return await Promise.race([promise, timeout]);\n } finally {\n clearTimeout(timer!);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Exclusive lock (Promise sharing)\n// ---------------------------------------------------------------------------\n\n/**\n * Creates an exclusive async lock that ensures only one invocation runs at a\n * time. Subsequent callers await the same Promise (analyzer-bridge pattern).\n */\nexport function createExclusiveLock<T>(): {\n run: (fn: () => Promise<T>) => Promise<T>;\n} {\n let pending: Promise<T> | null = null;\n\n return {\n async run(fn: () => Promise<T>): Promise<T> {\n if (pending) return pending;\n pending = fn().finally(() => {\n pending = null;\n });\n return pending;\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Degrade policy\n// ---------------------------------------------------------------------------\n\nexport interface DegradeResult<T> {\n value: T;\n degraded: boolean;\n reason?: string;\n}\n\n/**\n * Attempt an operation with timeout; if it fails or times out, return the\n * fallback value with `degraded: true`.\n */\nexport async function withDegrade<T>(\n operation: () => Promise<T>,\n fallback: T,\n timeoutMs: number,\n): Promise<DegradeResult<T>> {\n try {\n const value = await withTimeout(operation(), timeoutMs);\n return { value, degraded: false };\n } catch (err) {\n const reason =\n err instanceof TimeoutError\n ? err.message\n : err instanceof Error\n ? err.message\n : String(err);\n return { value: fallback, degraded: true, reason };\n }\n}\n","/**\n * Ensure Navigation Index — cache warm / invalidation.\n *\n * Checks cache freshness via source file mtime comparison. If stale,\n * calls buildNavigationContext() and writes to .claude/cache/.\n * If fresh, returns cached data immediately.\n *\n * This is the performance-critical path for SessionStart hooks.\n */\n\nimport { buildNavigationContext, type NavigationContextOptions } from \"../navigation-context.js\";\nimport { createCacheStore, type CacheStore } from \"./cache-store.js\";\nimport { createExclusiveLock } from \"./latency.js\";\nimport { guardrailCacheKey } from \"./ensure-navigation-index-keys.js\";\nimport type { NavigationDiagnostic } from \"./navigation-cache.js\";\nimport {\n computeCurrentHash,\n readFreshNavigationBuild,\n DEFAULT_CACHE_KEY,\n} from \"./navigation-freshness.js\";\n\nexport { GUARDRAIL_CACHE_SUFFIX, guardrailCacheKey } from \"./ensure-navigation-index-keys.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface EnsureNavigationIndexOptions {\n /** Absolute path to .claude/cache/ directory. */\n cacheDir: string;\n /** Paths to source files whose mtime drives cache invalidation. */\n sourceFiles: string[];\n /** Options for buildNavigationContext() when cache is stale. */\n navigationOptions: NavigationContextOptions;\n /**\n * Cache key for the stored JSON file (default: `\"navigation-index\"`).\n *\n * In workspace mode each member uses its own key, e.g.\n * `\"navigation-index.aaac\"`, so their caches remain isolated.\n * Single-component callers omit this field and the default preserves\n * byte-identical behaviour with previous versions.\n */\n cacheKey?: string;\n}\n\nexport interface NavigationIndexResult {\n navigationIndex: Record<string, unknown>;\n /** Whether the result was loaded from cache (true) or freshly built (false). */\n fromCache: boolean;\n /**\n * Diagnostics from the build that produced this index — artifact-binding\n * findings (`unbound-artifact` / `orphan-binding` / `type-mismatch`) and\n * schema validation issues. Present only on a fresh build: they describe the\n * DSL/registry the index was built from, so a caller that hit the cache has\n * already been told once. Callers MUST surface them (a dropped\n * `orphan-binding` is exactly how a project's artifact registry silently\n * fails to reach the hooks — #260).\n */\n diagnostics?: NavigationDiagnostic[];\n}\n\n// ---------------------------------------------------------------------------\n// Implementation\n// ---------------------------------------------------------------------------\n\n/**\n * Per-key exclusive locks so concurrent session-start calls for distinct\n * workspace members can build their indices in parallel, while duplicate calls\n * for the same key are deduplicated (share the in-flight promise).\n */\nconst buildLocks = new Map<string, ReturnType<typeof createExclusiveLock<NavigationIndexResult>>>();\n\nfunction getBuildLock(key: string): ReturnType<typeof createExclusiveLock<NavigationIndexResult>> {\n let lock = buildLocks.get(key);\n if (!lock) {\n lock = createExclusiveLock<NavigationIndexResult>();\n buildLocks.set(key, lock);\n }\n return lock;\n}\n\n/**\n * Ensure the navigation index is available and fresh. Returns the index\n * data, building + caching if necessary.\n *\n * In workspace mode, pass a unique `cacheKey` per member (e.g.\n * `\"navigation-index.aaac\"`) so each member's index is stored and\n * invalidated independently.\n */\nexport async function ensureNavigationIndex(\n options: EnsureNavigationIndexOptions,\n): Promise<NavigationIndexResult> {\n const cacheKey = options.cacheKey ?? DEFAULT_CACHE_KEY;\n\n return getBuildLock(cacheKey).run(async () => {\n const store: CacheStore = createCacheStore({ cacheDir: options.cacheDir });\n const currentHash = await computeCurrentHash(options.sourceFiles);\n\n // Try cache first — through the SAME predicate the lean hooks read with.\n // If this asked a weaker question (say, hash only), an entry the reader\n // rejects could be one the builder accepts, and the rebuild that was\n // supposed to repair it would return the untouched entry instead. The\n // per-prompt hook would then re-run this on every prompt and still get\n // nothing back.\n const cached = await readFreshNavigationBuild({\n cacheDir: options.cacheDir,\n cacheKey,\n });\n if (cached) {\n return { navigationIndex: cached.navigationIndex, fromCache: true };\n }\n\n // Cache miss or stale — rebuild\n const context = await buildNavigationContext(options.navigationOptions);\n const navigationIndex = context.navigationIndex;\n\n // Write to cache (non-blocking error handling)\n try {\n await store.write(cacheKey, navigationIndex, currentHash, options.sourceFiles);\n } catch {\n // Cache write failure is non-fatal\n }\n\n // Persist the member's DSL guardrail rules in a companion cache entry so\n // the lean PreToolUse hook can wire Bash guardrails without importing the\n // heavy agent-contracts DSL loader (#238 / C5). We always write, even when\n // there are no rules, so a stale non-empty entry cannot survive a DSL edit\n // that removed all guardrails.\n try {\n await store.write(\n guardrailCacheKey(cacheKey),\n context.guardrailRules ?? { commandRules: [], fileRules: [], contentRules: [] },\n currentHash,\n );\n } catch {\n // Cache write failure is non-fatal\n }\n\n return {\n navigationIndex,\n fromCache: false,\n ...(context.diagnostics.length > 0 ? { diagnostics: context.diagnostics } : {}),\n };\n });\n}\n","/**\n * SessionStart Hook Handler — cache warm + navigation-index summary injection.\n *\n * Executed on session new/resume/clear/compact events. Warms the navigation-index\n * cache and returns a rendered summary as additionalContext.\n *\n * Latency constraint: NO AST analysis or ContextPack generation.\n */\n\nimport { renderNavigationIndexPrompt } from \"../navigation-index-prompt.js\";\nimport {\n ensureNavigationIndex,\n type EnsureNavigationIndexOptions,\n} from \"./ensure-navigation-index.js\";\nimport { renderNavigationDiagnostics } from \"./navigation-cache.js\";\nimport {\n buildContextResponse,\n type HookOutput,\n type SessionStartInput,\n} from \"./hook-protocol.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface SessionStartHandlerConfig {\n /** Absolute path to .claude/cache/ directory. */\n cacheDir: string;\n /** Source files for cache invalidation (component.yaml, agent-contracts.yaml, etc.). */\n sourceFiles: string[];\n /** Options for buildNavigationContext(). */\n navigationOptions: EnsureNavigationIndexOptions[\"navigationOptions\"];\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\n/**\n * Create a SessionStart hook handler.\n */\nexport function createSessionStartHandler(config: SessionStartHandlerConfig) {\n return async function handleSessionStart(\n _input: SessionStartInput,\n ): Promise<HookOutput> {\n const result = await ensureNavigationIndex({\n cacheDir: config.cacheDir,\n sourceFiles: config.sourceFiles,\n navigationOptions: config.navigationOptions,\n });\n\n const summary = renderNavigationIndexPrompt(result.navigationIndex);\n const cacheNote = result.fromCache\n ? \"(loaded from cache)\"\n : \"(freshly built)\";\n\n const diagnostics = renderNavigationDiagnostics(result.diagnostics);\n\n const additionalContext = [\n summary,\n \"\",\n `Navigation index ${cacheNote}. Use analyzer MCP tools for deep investigation.`,\n ...(diagnostics ? [\"\", diagnostics] : []),\n ].join(\"\\n\");\n\n return buildContextResponse(\"SessionStart\", additionalContext);\n };\n}\n","/**\n * Workspace SessionStart Hook Handler — per-member navigation-index warm-up.\n *\n * Builds (or validates) a cached navigation-index for each declared workspace\n * member in parallel, then returns a combined summary as `additionalContext`.\n *\n * This module is in the **heavy** path (imports ensureNavigationIndex →\n * navigation-context → agent-contracts) and is therefore NOT included in the\n * lean hooks-lite entry point. SessionStart fires only once per session, so\n * the higher import cost is acceptable.\n */\n\nimport {\n renderMemberSection,\n type WorkspaceMemberNavConfig,\n type WorkspaceMemberNavResult,\n} from \"./workspace-members.js\";\nimport { ensureNavigationIndex } from \"./ensure-navigation-index.js\";\nimport {\n buildContextResponse,\n type HookOutput,\n type SessionStartInput,\n} from \"./hook-protocol.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface WorkspaceSessionStartConfig {\n /** Absolute path to the shared `.claude/cache/` directory. */\n cacheDir: string;\n /** Workspace members to build/validate indices for. */\n members: WorkspaceMemberNavConfig[];\n}\n\n// ---------------------------------------------------------------------------\n// Warm-up\n// ---------------------------------------------------------------------------\n\n/**\n * Build (or validate) every member's navigation-index in **parallel** — each\n * cache key has its own exclusive lock, so concurrent calls for the same member\n * deduplicate rather than queue behind other members.\n *\n * This is the heavy path, and it lives here because SessionStart is the only\n * hook that may pay for it: it fires once per session. The per-interaction hooks\n * read the cache instead and run the `ensure-navigation-index` bin when it is\n * stale, which reaches this same builder in a child process.\n */\nexport async function ensureMemberIndices(\n cacheDir: string,\n members: WorkspaceMemberNavConfig[],\n): Promise<WorkspaceMemberNavResult[]> {\n return Promise.all(\n members.map(async (member) => ({\n member,\n result: await ensureNavigationIndex({\n cacheDir,\n sourceFiles: member.sourceFiles,\n navigationOptions: member.navigationOptions,\n cacheKey: member.cacheKey,\n }),\n })),\n );\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\n/**\n * Create a workspace-aware SessionStart hook handler.\n */\nexport function createWorkspaceSessionStartHandler(\n config: WorkspaceSessionStartConfig,\n) {\n return async function handleWorkspaceSessionStart(\n _input: SessionStartInput,\n ): Promise<HookOutput> {\n const results = await ensureMemberIndices(config.cacheDir, config.members);\n\n const additionalContext = [\n results.map(renderMemberSection).join(\"\\n\\n\"),\n \"\",\n \"Workspace navigation indices ready. Use analyzer MCP tools for deep investigation.\",\n ].join(\"\\n\");\n\n return buildContextResponse(\"SessionStart\", additionalContext);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,IAAY;AACtB,UAAM,6BAA6B,EAAE,IAAI;AACzC,SAAK,OAAO;AAAA,EACd;AACF;AAMA,eAAsB,YACpB,SACA,WACY;AACZ,MAAI,aAAa,EAAG,QAAO;AAE3B,MAAI;AACJ,QAAM,UAAU,IAAI,QAAe,CAAC,UAAU,WAAW;AACvD,YAAQ,WAAW,MAAM,OAAO,IAAI,aAAa,SAAS,CAAC,GAAG,SAAS;AAAA,EACzE,CAAC;AAED,MAAI;AACF,WAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,OAAO,CAAC;AAAA,EAC9C,UAAE;AACA,iBAAa,KAAM;AAAA,EACrB;AACF;AAUO,SAAS,sBAEd;AACA,MAAI,UAA6B;AAEjC,SAAO;AAAA,IACL,MAAM,IAAI,IAAkC;AAC1C,UAAI,QAAS,QAAO;AACpB,gBAAU,GAAG,EAAE,QAAQ,MAAM;AAC3B,kBAAU;AAAA,MACZ,CAAC;AACD,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAgBA,eAAsB,YACp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","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation-index (Level 1) presentation.
|
|
3
|
+
*
|
|
4
|
+
* Pure formatting over an already-built navigation index: no DSL loader, no
|
|
5
|
+
* schema validation, no SDK. It lives in its own module because the interactive
|
|
6
|
+
* hook path needs it while it must NOT pull `task-runner`'s graph (zod, yaml,
|
|
7
|
+
* the plugin registry, the analyzer and observability bridges); the lean
|
|
8
|
+
* `claude-native/hooks-lite` barrel re-exports it from here.
|
|
9
|
+
*/
|
|
10
|
+
/** Minimal duck-typed shape of an artifact node in the navigation index. */
|
|
11
|
+
interface NavigationArtifactNode {
|
|
12
|
+
files?: {
|
|
13
|
+
path_patterns?: string[];
|
|
14
|
+
};
|
|
15
|
+
properties?: {
|
|
16
|
+
type?: string;
|
|
17
|
+
authority?: string;
|
|
18
|
+
manual_edit?: string;
|
|
19
|
+
};
|
|
20
|
+
relations?: {
|
|
21
|
+
source_artifacts?: string[];
|
|
22
|
+
derived_artifacts?: string[];
|
|
23
|
+
};
|
|
24
|
+
agents?: {
|
|
25
|
+
owners?: string[];
|
|
26
|
+
editors?: string[];
|
|
27
|
+
readers?: string[];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Duck-type check: does `value` look like a ProjectNavigationIndex?
|
|
32
|
+
* Requires a `system` object and an `artifacts` record.
|
|
33
|
+
*/
|
|
34
|
+
declare function isNavigationIndex(value: unknown): value is Record<string, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Render the Level 1 navigation index as a compact prompt section — a
|
|
37
|
+
* human-readable SUMMARY of artifacts (type, authority, edit policy, key
|
|
38
|
+
* relations and owning agents), NOT a raw JSON dump. Gives the agent a map of
|
|
39
|
+
* the project's artifacts so it can navigate before acting.
|
|
40
|
+
*/
|
|
41
|
+
declare function renderNavigationIndexPrompt(navigationIndex: Record<string, unknown>): string;
|
|
42
|
+
|
|
43
|
+
export { type NavigationArtifactNode as N, isNavigationIndex as i, renderNavigationIndexPrompt as r };
|