@bartolli/kmd 0.10.0 → 0.11.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/dist/kmd.mjs +54 -4
- package/dist/kmd.mjs.map +3 -3
- package/package.json +1 -1
package/dist/kmd.mjs
CHANGED
|
@@ -248,6 +248,12 @@ var init_vault_config = __esm({
|
|
|
248
248
|
}).optional(),
|
|
249
249
|
"handoff-gate": z.strictObject({
|
|
250
250
|
reason: z.string().min(1).optional().describe("Stop-block preamble; the engine appends the error lines.")
|
|
251
|
+
}).optional(),
|
|
252
|
+
orient: z.strictObject({
|
|
253
|
+
text: z.string().min(1).optional().describe("Session-start prime instruction; the engine prepends the resolved scope.")
|
|
254
|
+
}).optional(),
|
|
255
|
+
reorient: z.strictObject({
|
|
256
|
+
text: z.string().min(1).optional().describe("Post-compaction re-orientation; the engine prepends the resolved scope.")
|
|
251
257
|
}).optional()
|
|
252
258
|
});
|
|
253
259
|
VaultConfigSchema = z.strictObject({
|
|
@@ -269,7 +275,7 @@ var init_vault_config = __esm({
|
|
|
269
275
|
'Full-replace of the trigger base per scope \u2014 escape hatch. "_all" is reserved for triggers_extra.'
|
|
270
276
|
),
|
|
271
277
|
builtin_hooks: BuiltinHooksSchema.optional().describe(
|
|
272
|
-
"Message overrides for the fixed-function hooks (resync, handoff-gate) by public id."
|
|
278
|
+
"Message overrides for the fixed-function hooks (resync, handoff-gate, orient, reorient) by public id."
|
|
273
279
|
),
|
|
274
280
|
triggers_extra: TriggersSchema.optional().describe(
|
|
275
281
|
'Appended per scope after the engine defaults; the reserved "_all" key fires in every session.'
|
|
@@ -2366,15 +2372,18 @@ __export(hook_exports, {
|
|
|
2366
2372
|
matchPromptTriggers: () => matchPromptTriggers,
|
|
2367
2373
|
parsePretoolEvent: () => parsePretoolEvent,
|
|
2368
2374
|
parsePromptEvent: () => parsePromptEvent,
|
|
2375
|
+
parseSessionStartEvent: () => parseSessionStartEvent,
|
|
2369
2376
|
parseStopEvent: () => parseStopEvent,
|
|
2370
2377
|
renderPosttool: () => renderPosttool,
|
|
2371
2378
|
renderPretool: () => renderPretool,
|
|
2372
2379
|
renderPrompt: () => renderPrompt,
|
|
2380
|
+
renderSessionStart: () => renderSessionStart,
|
|
2373
2381
|
renderStop: () => renderStop,
|
|
2374
2382
|
resolveScope: () => resolveScope,
|
|
2375
2383
|
runHookPosttool: () => runHookPosttool,
|
|
2376
2384
|
runHookPretool: () => runHookPretool,
|
|
2377
2385
|
runHookPrompt: () => runHookPrompt,
|
|
2386
|
+
runHookSessionStart: () => runHookSessionStart,
|
|
2378
2387
|
runHookStop: () => runHookStop,
|
|
2379
2388
|
vaultPathTouched: () => vaultPathTouched
|
|
2380
2389
|
});
|
|
@@ -3118,6 +3127,42 @@ async function runHookStop() {
|
|
|
3118
3127
|
diag2(err instanceof Error ? err.message : String(err));
|
|
3119
3128
|
}
|
|
3120
3129
|
}
|
|
3130
|
+
function parseSessionStartEvent(raw) {
|
|
3131
|
+
const fields = eventFields(raw);
|
|
3132
|
+
if (fields === null) return null;
|
|
3133
|
+
const { session_id, cwd, source } = fields;
|
|
3134
|
+
if (typeof session_id !== "string") return null;
|
|
3135
|
+
return {
|
|
3136
|
+
session_id,
|
|
3137
|
+
...typeof cwd === "string" && { cwd },
|
|
3138
|
+
...typeof source === "string" && { source }
|
|
3139
|
+
};
|
|
3140
|
+
}
|
|
3141
|
+
function renderSessionStart(scope, source, messages = {}) {
|
|
3142
|
+
const text = source === "compact" ? messages.reorient?.text ?? REORIENT_TEXT : messages.orient?.text ?? ORIENT_TEXT;
|
|
3143
|
+
return `Wiki scope "${scope}": ${text}`;
|
|
3144
|
+
}
|
|
3145
|
+
async function runHookSessionStart() {
|
|
3146
|
+
try {
|
|
3147
|
+
const invocation = hookInvocation();
|
|
3148
|
+
if (invocation === null) return;
|
|
3149
|
+
if (invocation.dryRun) {
|
|
3150
|
+
diag2("--dry-run/--explain support prompt and pretool events only");
|
|
3151
|
+
return;
|
|
3152
|
+
}
|
|
3153
|
+
const event = parseSessionStartEvent(await readStdin());
|
|
3154
|
+
if (event === null) {
|
|
3155
|
+
diag2("stdin is not a session-start event ({session_id})");
|
|
3156
|
+
return;
|
|
3157
|
+
}
|
|
3158
|
+
const config = await loadVaultConfig(invocation.vaultRoot);
|
|
3159
|
+
const scope = invocation.scope ?? resolveScope(config, event.cwd);
|
|
3160
|
+
if (scope === void 0) return;
|
|
3161
|
+
console.log(renderSessionStart(scope, event.source, config.builtin_hooks ?? {}));
|
|
3162
|
+
} catch (err) {
|
|
3163
|
+
diag2(err instanceof Error ? err.message : String(err));
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3121
3166
|
async function readStdin() {
|
|
3122
3167
|
process.stdin.setEncoding("utf8");
|
|
3123
3168
|
let input = "";
|
|
@@ -3129,7 +3174,7 @@ async function readStdin() {
|
|
|
3129
3174
|
function diag2(message) {
|
|
3130
3175
|
console.error(`kmd hook: ${message}`);
|
|
3131
3176
|
}
|
|
3132
|
-
var DEFAULT_TRIGGERS, SESSION_STATE_MAX_AGE_MS, KIRO_IDE_BUCKET_MS, ALL_SCOPES_KEY, PATCH_FILE_RE, COMMAND_TOKEN_RE, PATHISH_RE, RESYNC_REASON, RESYNC_TEXT, HANDOFF_GATE_REASON;
|
|
3177
|
+
var DEFAULT_TRIGGERS, SESSION_STATE_MAX_AGE_MS, KIRO_IDE_BUCKET_MS, ALL_SCOPES_KEY, PATCH_FILE_RE, COMMAND_TOKEN_RE, PATHISH_RE, RESYNC_REASON, RESYNC_TEXT, HANDOFF_GATE_REASON, ORIENT_TEXT, REORIENT_TEXT;
|
|
3133
3178
|
var init_hook = __esm({
|
|
3134
3179
|
"../cli/src/hook.ts"() {
|
|
3135
3180
|
"use strict";
|
|
@@ -3148,6 +3193,8 @@ var init_hook = __esm({
|
|
|
3148
3193
|
RESYNC_REASON = "Edit landed; the index sync is held until these validate errors are fixed";
|
|
3149
3194
|
RESYNC_TEXT = "kmd sync failed \u2014 index not updated; see hook stderr";
|
|
3150
3195
|
HANDOFF_GATE_REASON = "Validate errors are outstanding and the index sync is held \u2014 fix them, let the resync run, then finish";
|
|
3196
|
+
ORIENT_TEXT = "prime via the wiki MCP prime tool before substantive work \u2014 the primer carries current focus, book of work, and invariants.";
|
|
3197
|
+
REORIENT_TEXT = "context was compacted and transcript detail is lost \u2014 re-read the primer via the wiki MCP prime tool and route uncaptured findings into the wiki before continuing.";
|
|
3151
3198
|
}
|
|
3152
3199
|
});
|
|
3153
3200
|
|
|
@@ -3168,7 +3215,7 @@ commands:
|
|
|
3168
3215
|
mcp [<vault-root>] start the stdio MCP server (default: $WIKI_VAULT)
|
|
3169
3216
|
config [<vault-root>] print vault + index resolution; with no vault, list known vaults
|
|
3170
3217
|
db reset [<vault-root>] delete the vault's index (default: $WIKI_VAULT)
|
|
3171
|
-
hook <prompt|pretool|posttool|stop> [<vault-root>] [--scope <s>] [--harness <claude|kiro-ide>] [--triggers <file>]
|
|
3218
|
+
hook <prompt|pretool|posttool|stop|session-start> [<vault-root>] [--scope <s>] [--harness <claude|kiro-ide>] [--triggers <file>]
|
|
3172
3219
|
harness gate engine: JSON event on stdin, decision/context on stdout;
|
|
3173
3220
|
posttool auto-runs validate + sync after a vault write;
|
|
3174
3221
|
stop blocks the handoff once while validate errors hold the sync
|
|
@@ -3249,11 +3296,14 @@ async function run() {
|
|
|
3249
3296
|
} else if (sub === "stop") {
|
|
3250
3297
|
const { runHookStop: runHookStop2 } = await Promise.resolve().then(() => (init_hook(), hook_exports));
|
|
3251
3298
|
await runHookStop2();
|
|
3299
|
+
} else if (sub === "session-start") {
|
|
3300
|
+
const { runHookSessionStart: runHookSessionStart2 } = await Promise.resolve().then(() => (init_hook(), hook_exports));
|
|
3301
|
+
await runHookSessionStart2();
|
|
3252
3302
|
} else if (sub) {
|
|
3253
3303
|
console.error(`kmd hook: unknown event: ${sub}`);
|
|
3254
3304
|
} else {
|
|
3255
3305
|
console.error(
|
|
3256
|
-
"usage: kmd hook <prompt|pretool|posttool|stop> [<vault-root>] [--scope <scope>] [--harness <claude|kiro-ide>]"
|
|
3306
|
+
"usage: kmd hook <prompt|pretool|posttool|stop|session-start> [<vault-root>] [--scope <scope>] [--harness <claude|kiro-ide>]"
|
|
3257
3307
|
);
|
|
3258
3308
|
process.exit(2);
|
|
3259
3309
|
}
|