@kawacode/mcp 6.8.0 → 6.9.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/CLAUDE.md.example +10 -0
- package/README.md +16 -0
- package/build/kawacode-on-pre-edit.js +5 -1
- package/build/kawacode-on-pre-edit.js.map +1 -1
- package/build/kawacode-on-stop.d.ts +9 -5
- package/build/kawacode-on-stop.js +70 -26
- package/build/kawacode-on-stop.js.map +1 -1
- package/build/services/muninn-ipc.d.ts +13 -6
- package/build/services/muninn-ipc.js +35 -14
- package/build/services/muninn-ipc.js.map +1 -1
- package/build/stop/uncompleted-commit.d.ts +47 -12
- package/build/stop/uncompleted-commit.js +113 -75
- package/build/stop/uncompleted-commit.js.map +1 -1
- package/build/stop/uncompleted-commit.test.js +70 -1
- package/build/stop/uncompleted-commit.test.js.map +1 -1
- package/build/telemetry.d.ts +11 -0
- package/build/telemetry.js +15 -0
- package/build/telemetry.js.map +1 -1
- package/build/tools/edit-session-decision.d.ts +10 -0
- package/build/tools/edit-session-decision.js +3 -1
- package/build/tools/edit-session-decision.js.map +1 -1
- package/build/tools/get-decision-detail.d.ts +1 -0
- package/build/tools/get-decision-detail.js +2 -1
- package/build/tools/get-decision-detail.js.map +1 -1
- package/build/tools/index.d.ts +8 -0
- package/build/tools/record-decision.d.ts +6 -0
- package/build/tools/record-decision.js +3 -0
- package/build/tools/record-decision.js.map +1 -1
- package/package.json +1 -1
package/CLAUDE.md.example
CHANGED
|
@@ -31,6 +31,16 @@ Before creating any new component, store, or shared utility:
|
|
|
31
31
|
|
|
32
32
|
Recall is scoped to a sub-task, not blanket coverage for the session. When a request **expands into a new area mid-turn** (e.g. a small fix grows into adding a new helper or UI component), re-run recall for the *new* area before writing — an earlier recall for a different sub-task doesn't cover it. **Self-initiated additions you bundle onto the original ask are where this gets skipped most.**
|
|
33
33
|
|
|
34
|
+
### Migrations & rewrites — recall-transplant from the source repo
|
|
35
|
+
|
|
36
|
+
When porting code from another repository (language port, rewrite, repo split), the source repo's decisions do NOT surface here automatically — recall is per-repo. Before porting each slice:
|
|
37
|
+
|
|
38
|
+
1. `get_relevant_context` against the **source** repo (its `repoPath`), describing the subsystem being ported + its key files.
|
|
39
|
+
2. `get_decision_detail` on the load-bearing hits.
|
|
40
|
+
3. Transplant only **stack-portable** decisions (domain truths, protocol contracts, cost/scale rationale, security discoveries, retired-approach warnings) — not the old stack's tooling/runtime mechanics.
|
|
41
|
+
4. `record_decision` them in **this** repo with provenance: `[transplanted from <source-repo> <decision-id>]`. Merge one-lineage decisions into a single record.
|
|
42
|
+
5. Let transplanted rationale drive the port's tests (a durability guarantee becomes a test; a retired approach must not be reintroduced).
|
|
43
|
+
|
|
34
44
|
---
|
|
35
45
|
|
|
36
46
|
## When to create an intent — vs skip
|
package/README.md
CHANGED
|
@@ -111,6 +111,22 @@ Disable telemetry with `KAWA_PRE_EDIT_TELEMETRY=off`.
|
|
|
111
111
|
- **Zero-knowledge encryption** — code blocks encrypted client-side before sync. The Kawa cloud cannot decrypt your team's code.
|
|
112
112
|
- **Cross-platform** — works with Claude Code, Cursor, and any MCP-compatible AI assistant.
|
|
113
113
|
|
|
114
|
+
## Migrating or rewriting a codebase? Transplant its decisions
|
|
115
|
+
|
|
116
|
+
When you port a codebase to a new language or rebuild it in a fresh repository, the code moves — but the *reasoning* usually doesn't. The source repo's decision history knows why retired approaches were retired, which constraints are load-bearing, and where the security landmines are. With Kawa Code, that history becomes a first-class migration input.
|
|
117
|
+
|
|
118
|
+
Decisions are scoped per repository, so the new repo won't surface the old repo's history automatically. Transplant them slice by slice as you port — this is the **recall-transplant workflow**:
|
|
119
|
+
|
|
120
|
+
1. **Recall before porting each slice.** Call `get_relevant_context` against the *source* repo with a description of the subsystem you're about to port (name its key files). This surfaces the forks, constraints, trade-offs, and discoveries that shaped it.
|
|
121
|
+
2. **Expand what matters.** Recall returns summaries — call `get_decision_detail` on the load-bearing hits for the full rationale and consequences.
|
|
122
|
+
3. **Classify: stack-portable vs stack-bound.** Domain truths port: protocol contracts, cost/scale rationale, security discoveries, "we tried X and retired it" warnings. Mechanics of the old stack don't: build-tooling quirks, runtime workarounds, library-specific fixes. Only the portable ones move.
|
|
123
|
+
4. **Re-record the portable ones in the *target* repo** with `record_decision`, citing provenance in the summary or rationale (e.g. `[transplanted from <source-repo> <decision-id>]`). Merge decisions that form one lineage into a single record.
|
|
124
|
+
5. **Let the transplants shape the port and its tests.** A transplanted durability rationale should become a test that proves the property survived the rewrite; a retired-approach warning should stop the new stack from reintroducing it.
|
|
125
|
+
|
|
126
|
+
The payoff compounds: the port doesn't re-litigate settled arguments or faithfully reproduce old bugs, *negative knowledge* survives even though the code that motivated it was deleted long ago, and at cutover the new repo starts with a curated decision corpus instead of an empty one.
|
|
127
|
+
|
|
128
|
+
The [CLAUDE.md template](./CLAUDE.md.example) ships a compact version of this workflow, so agents set up through the Kawa Code welcome flow follow it automatically.
|
|
129
|
+
|
|
114
130
|
## Development
|
|
115
131
|
|
|
116
132
|
```bash
|
|
@@ -30,10 +30,14 @@
|
|
|
30
30
|
* Opt out with KAWA_PRE_EDIT_CHECK=off.
|
|
31
31
|
*/
|
|
32
32
|
import { readFileSync } from 'node:fs';
|
|
33
|
-
import { connectToMuninn, request, disconnect } from './services/muninn-ipc.js';
|
|
33
|
+
import { connectToMuninn, request, disconnect, setQuiet } from './services/muninn-ipc.js';
|
|
34
34
|
import { resolveOrigin } from './tools/resolve-origin.js';
|
|
35
35
|
import { resolvePaths } from './pre-edit/path-resolve.js';
|
|
36
36
|
import { emitInjection, emitActedOn, estimateTokens } from './telemetry.js';
|
|
37
|
+
// Hook stderr is surfaced to the agent/user on exit-2 blocks — suppress the
|
|
38
|
+
// IPC lifecycle chatter so only the decision-check message comes through.
|
|
39
|
+
// KAWA_DEBUG=1 restores full logging for troubleshooting.
|
|
40
|
+
setQuiet(!process.env.KAWA_DEBUG);
|
|
37
41
|
function readStdin() {
|
|
38
42
|
try {
|
|
39
43
|
return readFileSync(0, 'utf8');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kawacode-on-pre-edit.js","sourceRoot":"","sources":["../src/kawacode-on-pre-edit.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"kawacode-on-pre-edit.js","sourceRoot":"","sources":["../src/kawacode-on-pre-edit.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE3E,4EAA4E;AAC5E,0EAA0E;AAC1E,0DAA0D;AAC1D,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;AAyCjC,SAAS,SAAS;IAChB,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,QAAgB,EAAE,MAAc;IACvD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI,GAAG,GAAG,C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AAQ,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAChD,MAAM,GAAG,GAAG;YACV,kBAAkB,EAAE;gBAClB,aAAa,EAAE,YAAY;gBAC3B,iBAAiB,EAAE,QAAQ;aAC5B;SACF,CAAA;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QAChD,yEAAyE;QACzE,IAAI,CAAC;YACH,MAAM,aAAa,CAAC;gBAClB,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,cAAc,CAAC,QAAQ,CAAC;gBACnC,SAAS,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM;gBACvC,UAAU;aACX,CAAC,CAAA;QACJ,CAAC;QAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC,CAAC;QACjC,UAAU,EAAE,CAAA;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,oBAAoB;IACpB,UAAU,EAAE,CAAA;IACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -42,11 +42,15 @@
|
|
|
42
42
|
* not misread as a commit. Gate only when a commit lands AFTER the most
|
|
43
43
|
* recent complete_intent call (or with none after it) — a failed/attempted
|
|
44
44
|
* complete_intent still counts as "tried", so conflict-resolution turns
|
|
45
|
-
* are not nagged.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
45
|
+
* are not nagged. The gate attributes the commit to ITS OWN repo (parsed
|
|
46
|
+
* from `git -C`/`cd` in the command, falling back to cwd), confirms via
|
|
47
|
+
* intent:get-active that THIS session has an open current intent THERE,
|
|
48
|
+
* skips entirely when a prior nag for this commit already sits in the
|
|
49
|
+
* transcript (once per commit — never loop), and skips when the repo HEAD
|
|
50
|
+
* is already claimed by a completed intent (intent:claimed-by-commit).
|
|
51
|
+
* Output mirrors job 2: { decision:"block", reason } guarded by
|
|
52
|
+
* !stop_hook_active; once a block has fired it degrades to
|
|
53
|
+
* additionalContext. Takes precedence over the collision report on the
|
|
50
54
|
* turn it fires (finalizing the intent matters more; collisions re-surface
|
|
51
55
|
* next turn).
|
|
52
56
|
*
|
|
@@ -42,11 +42,15 @@
|
|
|
42
42
|
* not misread as a commit. Gate only when a commit lands AFTER the most
|
|
43
43
|
* recent complete_intent call (or with none after it) — a failed/attempted
|
|
44
44
|
* complete_intent still counts as "tried", so conflict-resolution turns
|
|
45
|
-
* are not nagged.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
45
|
+
* are not nagged. The gate attributes the commit to ITS OWN repo (parsed
|
|
46
|
+
* from `git -C`/`cd` in the command, falling back to cwd), confirms via
|
|
47
|
+
* intent:get-active that THIS session has an open current intent THERE,
|
|
48
|
+
* skips entirely when a prior nag for this commit already sits in the
|
|
49
|
+
* transcript (once per commit — never loop), and skips when the repo HEAD
|
|
50
|
+
* is already claimed by a completed intent (intent:claimed-by-commit).
|
|
51
|
+
* Output mirrors job 2: { decision:"block", reason } guarded by
|
|
52
|
+
* !stop_hook_active; once a block has fired it degrades to
|
|
53
|
+
* additionalContext. Takes precedence over the collision report on the
|
|
50
54
|
* turn it fires (finalizing the intent matters more; collisions re-surface
|
|
51
55
|
* next turn).
|
|
52
56
|
*
|
|
@@ -58,10 +62,14 @@
|
|
|
58
62
|
*/
|
|
59
63
|
import { readFileSync } from 'node:fs';
|
|
60
64
|
import { execSync } from 'node:child_process';
|
|
61
|
-
import {
|
|
65
|
+
import { resolve as resolvePath } from 'node:path';
|
|
66
|
+
import { connectToMuninn, request, disconnect, setQuiet } from './services/muninn-ipc.js';
|
|
62
67
|
import { resolveOrigin } from './tools/resolve-origin.js';
|
|
63
|
-
import {
|
|
64
|
-
import { emitInjection, emitActedOn, estimateTokens } from './telemetry.js';
|
|
68
|
+
import { lastUnfinalizedCommit, nagAlreadyInTranscript, extractCommitPath, detectGateSave } from './stop/uncompleted-commit.js';
|
|
69
|
+
import { emitInjection, emitActedOn, emitTurnEnd, estimateTokens } from './telemetry.js';
|
|
70
|
+
// Same rationale as kawacode-on-pre-edit: hook stderr can surface to the
|
|
71
|
+
// agent/user — suppress IPC lifecycle chatter. KAWA_DEBUG=1 restores it.
|
|
72
|
+
setQuiet(!process.env.KAWA_DEBUG);
|
|
65
73
|
function readStdin() {
|
|
66
74
|
try {
|
|
67
75
|
return readFileSync(0, 'utf8');
|
|
@@ -146,21 +154,10 @@ async function runCollisionCheck(payload) {
|
|
|
146
154
|
});
|
|
147
155
|
}
|
|
148
156
|
// ===== Job 3: complete_intent hard gate =====
|
|
149
|
-
/**
|
|
150
|
-
function
|
|
151
|
-
let raw;
|
|
152
|
-
try {
|
|
153
|
-
raw = readFileSync(transcriptPath, 'utf8');
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
return detectUncompletedCommit(raw);
|
|
159
|
-
}
|
|
160
|
-
/** Current HEAD sha for `cwd`, or null if unavailable. */
|
|
161
|
-
function gitHeadSha(cwd) {
|
|
157
|
+
/** Current HEAD sha for `dir`, or null if unavailable. */
|
|
158
|
+
function gitHeadSha(dir) {
|
|
162
159
|
try {
|
|
163
|
-
return execSync('git rev-parse HEAD', { cwd, encoding: 'utf8', timeout: 5000, windowsHide: true }).trim();
|
|
160
|
+
return execSync('git rev-parse HEAD', { cwd: dir, encoding: 'utf8', timeout: 5000, windowsHide: true }).trim();
|
|
164
161
|
}
|
|
165
162
|
catch {
|
|
166
163
|
return null;
|
|
@@ -170,6 +167,17 @@ function gitHeadSha(cwd) {
|
|
|
170
167
|
* The complete_intent hard gate. Returns the hook-protocol JSON to print
|
|
171
168
|
* (a block, or a degraded advisory), or null when there's nothing to gate /
|
|
172
169
|
* on any failure (fail-soft). Mirrors runCollisionCheck's output protocol.
|
|
170
|
+
*
|
|
171
|
+
* Loop-fix (2026-07-03) — three suppressions before any nag:
|
|
172
|
+
* 1. Repo-correct attribution: the gate targets the repo the COMMIT ran in
|
|
173
|
+
* (parsed from `git -C` / `cd` in the command), not the payload cwd. A
|
|
174
|
+
* commit in an intent-less repo (e.g. docs-only) silences naturally via
|
|
175
|
+
* no-active-intent; a cross-repo commit gates against the right intent.
|
|
176
|
+
* 2. Once per commit: a prior nag after the commit in the transcript means
|
|
177
|
+
* we already asked — block once, then silence, never loop.
|
|
178
|
+
* 3. Already claimed: when the target repo's HEAD is claimed by a
|
|
179
|
+
* completed/pushed/done intent (any session), the commit IS finalized —
|
|
180
|
+
* nothing to nag.
|
|
173
181
|
*/
|
|
174
182
|
async function runCompleteGate(payload) {
|
|
175
183
|
if (process.env.KAWA_COMPLETE_GATE === 'off')
|
|
@@ -179,16 +187,32 @@ async function runCompleteGate(payload) {
|
|
|
179
187
|
if (!cwd || !transcriptPath)
|
|
180
188
|
return null;
|
|
181
189
|
// Cheap, IPC-free evidence first: did the agent commit without completing?
|
|
182
|
-
|
|
190
|
+
let transcript;
|
|
191
|
+
try {
|
|
192
|
+
transcript = readFileSync(transcriptPath, 'utf8');
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const commit = lastUnfinalizedCommit(transcript);
|
|
198
|
+
if (!commit)
|
|
183
199
|
return null;
|
|
200
|
+
// Suppression 2: we already nagged about this commit — block once, then silence.
|
|
201
|
+
if (nagAlreadyInTranscript(transcript, commit.lineIdx))
|
|
202
|
+
return null;
|
|
203
|
+
// Suppression 1: attribute the commit to ITS repo. Fall back to cwd when the
|
|
204
|
+
// command doesn't state a path (the commit ran in the Bash session's cwd).
|
|
205
|
+
const cmdPath = extractCommitPath(commit.cmd);
|
|
206
|
+
const gateDir = cmdPath ? resolvePath(cwd, cmdPath) : cwd;
|
|
184
207
|
let repoOrigin;
|
|
185
208
|
try {
|
|
186
|
-
repoOrigin = resolveOrigin(undefined,
|
|
209
|
+
repoOrigin = resolveOrigin(undefined, gateDir);
|
|
187
210
|
}
|
|
188
211
|
catch {
|
|
189
212
|
return null; // not a git repo / git unavailable — skip
|
|
190
213
|
}
|
|
191
|
-
// Confirm THIS session still has an open current intent
|
|
214
|
+
// Confirm THIS session still has an open current intent IN THE COMMIT'S REPO
|
|
215
|
+
// (supplies its id/title). Intent-less repos (docs) end here.
|
|
192
216
|
let res;
|
|
193
217
|
try {
|
|
194
218
|
res = await request('intent', 'get-active', { repoOrigin });
|
|
@@ -201,9 +225,23 @@ async function runCompleteGate(payload) {
|
|
|
201
225
|
return null; // already finalized (completion clears current) or no intent in play
|
|
202
226
|
if ((intent.status || 'active') !== 'active')
|
|
203
227
|
return null;
|
|
204
|
-
const headSha = gitHeadSha(
|
|
228
|
+
const headSha = gitHeadSha(gateDir);
|
|
229
|
+
// Suppression 3: HEAD already claimed by a completed intent (any session).
|
|
230
|
+
// Failure discipline matches the rest of the gate: any error → no gate.
|
|
231
|
+
if (headSha) {
|
|
232
|
+
try {
|
|
233
|
+
const claim = await request('intent', 'claimed-by-commit', { repoOrigin, sha: headSha });
|
|
234
|
+
if (claim?.claimed === true)
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
205
241
|
const shaShort = headSha ? ` (${headSha.slice(0, 8)})` : '';
|
|
206
242
|
const title = intent.title ? `"${intent.title}"` : 'the active intent';
|
|
243
|
+
// NOTE: this string carries the NAG_MARKER ('Run complete_intent(intentId=')
|
|
244
|
+
// that nagAlreadyInTranscript keys on — keep them in sync.
|
|
207
245
|
const call = `complete_intent(intentId="${intent.id}", status="committed"${headSha ? `, commitSha="${headSha}"` : ''})`;
|
|
208
246
|
const reason = `You committed${shaShort} under ${title} but didn't finalize it. Run ${call} so its ` +
|
|
209
247
|
`decisions distill and code blocks are captured. If this commit isn't meant to finalize the ` +
|
|
@@ -329,6 +367,12 @@ async function main() {
|
|
|
329
367
|
}
|
|
330
368
|
if (captureTasks.length > 0)
|
|
331
369
|
await Promise.allSettled(captureTasks);
|
|
370
|
+
// Close the telemetry turn (VALUE_METRICS Phase 2). Sent LAST — after this
|
|
371
|
+
// turn's stop_gate/stop_collision injections above have flushed (each awaited)
|
|
372
|
+
// — so they attribute to the closing turn and the next turn's first injection
|
|
373
|
+
// opens a fresh turnId. Muninn owns turnSeq; this is a thin fire-and-forget
|
|
374
|
+
// signal. Skipped when telemetry is off; harmless if no turn was ever opened.
|
|
375
|
+
await emitTurnEnd();
|
|
332
376
|
disconnect();
|
|
333
377
|
if (output)
|
|
334
378
|
process.stdout.write(output + '\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kawacode-on-stop.js","sourceRoot":"","sources":["../src/kawacode-on-stop.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"kawacode-on-stop.js","sourceRoot":"","sources":["../src/kawacode-on-stop.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,8BAA8B,C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AE,SAAS;YACrB,GAAG,EAAE,GAAG,IAAI,EAAE;SACf,CAAC,CACH,CAAA;IACH,CAAC;IAED,2EAA2E;IAC3E,yEAAyE;IACzE,6EAA6E;IAC7E,6EAA6E;IAC7E,sCAAsC;IACtC,IAAI,MAAM,GAAkB,IAAI,CAAA;IAChC,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,IAAI,CAAA,CAAC,gCAAgC;IAChD,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,IAAI,CAAA;QACf,CAAC;IACH,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;IAEnE,2EAA2E;IAC3E,+EAA+E;IAC/E,8EAA8E;IAC9E,4EAA4E;IAC5E,8EAA8E;IAC9E,MAAM,WAAW,EAAE,CAAA;IAEnB,UAAU,EAAE,CAAA;IACZ,IAAI,MAAM;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* lifts it into `IpcMessage.aid` and keys the per-session current pointer on it.
|
|
30
30
|
*/
|
|
31
31
|
export declare const SESSION_ID: string;
|
|
32
|
+
export declare function setQuiet(value: boolean): void;
|
|
32
33
|
/**
|
|
33
34
|
* Connect to Muninn's Huginn IPC socket.
|
|
34
35
|
*
|
|
@@ -51,13 +52,19 @@ export declare function connectToMuninn(socketPath?: string): Promise<void>;
|
|
|
51
52
|
*/
|
|
52
53
|
export declare function request(domain: string, action: string, data?: any, timeoutMs?: number): Promise<any>;
|
|
53
54
|
/**
|
|
54
|
-
* Ensure a repository path is registered
|
|
55
|
+
* Ensure a repository path is registered as a project.
|
|
55
56
|
*
|
|
56
|
-
* Sends `code:add` with the folder path so
|
|
57
|
-
* sets up git state, and pulls intents/decisions from the API.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
57
|
+
* Sends `code:add` with the folder path so the app activates the project,
|
|
58
|
+
* sets up git state, and pulls intents/decisions from the API. The handler
|
|
59
|
+
* is idempotent and returns the existing project if already added.
|
|
60
|
+
*
|
|
61
|
+
* A `code:add` failure arrives here as a rejected promise — `routeResponse`
|
|
62
|
+
* already rejects with the handler's real error on `success: false`. We must
|
|
63
|
+
* NOT swallow it: registration is a precondition for every repo-targeting
|
|
64
|
+
* tool, so a hidden failure lets the tool proceed and fail downstream with a
|
|
65
|
+
* misleading message (e.g. "No project open for this repo origin"). Re-throw
|
|
66
|
+
* with repo-path context; the dispatcher (index.ts) surfaces it to the caller
|
|
67
|
+
* as structured tool output so the real reason is visible.
|
|
61
68
|
*/
|
|
62
69
|
export declare function ensureRepo(repoPath: string): Promise<void>;
|
|
63
70
|
/**
|
|
@@ -48,6 +48,21 @@ let connected = false;
|
|
|
48
48
|
let cawId = '';
|
|
49
49
|
let connectionPromise = null;
|
|
50
50
|
const pendingRequests = new Map();
|
|
51
|
+
/**
|
|
52
|
+
* Quiet mode: suppresses connection-lifecycle info logging (connect,
|
|
53
|
+
* handshake, close). Hook dispatchers enable it because Claude Code surfaces
|
|
54
|
+
* hook stderr to the agent/user on exit-2 blocks — the handshake chatter
|
|
55
|
+
* pollutes the actual message. Genuine error logs are never suppressed.
|
|
56
|
+
* The stdio MCP server leaves this off; its stderr feeds the MCP log view.
|
|
57
|
+
*/
|
|
58
|
+
let quiet = false;
|
|
59
|
+
export function setQuiet(value) {
|
|
60
|
+
quiet = value;
|
|
61
|
+
}
|
|
62
|
+
function logInfo(message) {
|
|
63
|
+
if (!quiet)
|
|
64
|
+
console.error(message);
|
|
65
|
+
}
|
|
51
66
|
/**
|
|
52
67
|
* Get the default Muninn socket path for the current platform.
|
|
53
68
|
*/
|
|
@@ -83,7 +98,7 @@ export function connectToMuninn(socketPath) {
|
|
|
83
98
|
function _connectToMuninn(socketPath) {
|
|
84
99
|
const targetPath = socketPath || process.env.MUNINN_SOCKET || getDefaultMuninnSocketPath();
|
|
85
100
|
return new Promise((resolve, reject) => {
|
|
86
|
-
|
|
101
|
+
logInfo(`[MuninnIPC] Connecting to Muninn catalog at ${targetPath}...`);
|
|
87
102
|
const catalogSock = net.createConnection(targetPath, () => {
|
|
88
103
|
// Send extension handshake
|
|
89
104
|
const handshake = JSON.stringify({
|
|
@@ -117,7 +132,7 @@ function _connectToMuninn(socketPath) {
|
|
|
117
132
|
// Windows two-pipe protocol: catalog pipe only handles registration.
|
|
118
133
|
// Muninn sends back a dedicated client pipe path; connect to it for I/O.
|
|
119
134
|
switchedToClientPipe = true;
|
|
120
|
-
|
|
135
|
+
logInfo(`[MuninnIPC] Handshake complete (caw=${cawId}), connecting to ${pipePath}`);
|
|
121
136
|
catalogSock.destroy();
|
|
122
137
|
// Small delay so Muninn's thread has time to start the client pipe server
|
|
123
138
|
setTimeout(() => connectClientPipe(pipePath, resolve, reject), 50);
|
|
@@ -126,7 +141,7 @@ function _connectToMuninn(socketPath) {
|
|
|
126
141
|
// Unix: single persistent connection, keep using catalogSock
|
|
127
142
|
socket = catalogSock;
|
|
128
143
|
connected = true;
|
|
129
|
-
|
|
144
|
+
logInfo(`[MuninnIPC] Handshake complete (caw=${cawId})`);
|
|
130
145
|
resolve();
|
|
131
146
|
}
|
|
132
147
|
continue;
|
|
@@ -152,7 +167,7 @@ function _connectToMuninn(socketPath) {
|
|
|
152
167
|
// On Windows the catalog pipe closes after handshake — expected, skip cleanup.
|
|
153
168
|
// On Unix the catalog socket IS the main socket, so closing means disconnected.
|
|
154
169
|
if (!switchedToClientPipe) {
|
|
155
|
-
|
|
170
|
+
logInfo('[MuninnIPC] Socket closed');
|
|
156
171
|
cleanup();
|
|
157
172
|
}
|
|
158
173
|
});
|
|
@@ -171,11 +186,11 @@ function _connectToMuninn(socketPath) {
|
|
|
171
186
|
* for bidirectional communication after the catalog registration.
|
|
172
187
|
*/
|
|
173
188
|
function connectClientPipe(pipePath, resolve, reject) {
|
|
174
|
-
|
|
189
|
+
logInfo(`[MuninnIPC] Connecting to client pipe: ${pipePath}`);
|
|
175
190
|
const clientSock = net.createConnection(pipePath, () => {
|
|
176
191
|
socket = clientSock;
|
|
177
192
|
connected = true;
|
|
178
|
-
|
|
193
|
+
logInfo('[MuninnIPC] Client pipe connected');
|
|
179
194
|
resolve();
|
|
180
195
|
});
|
|
181
196
|
let buffer = '';
|
|
@@ -200,7 +215,7 @@ function connectClientPipe(pipePath, resolve, reject) {
|
|
|
200
215
|
cleanup();
|
|
201
216
|
});
|
|
202
217
|
clientSock.on('close', () => {
|
|
203
|
-
|
|
218
|
+
logInfo('[MuninnIPC] Client pipe closed');
|
|
204
219
|
cleanup();
|
|
205
220
|
});
|
|
206
221
|
}
|
|
@@ -291,20 +306,26 @@ export async function request(domain, action, data = {}, timeoutMs = DEFAULT_REQ
|
|
|
291
306
|
});
|
|
292
307
|
}
|
|
293
308
|
/**
|
|
294
|
-
* Ensure a repository path is registered
|
|
309
|
+
* Ensure a repository path is registered as a project.
|
|
310
|
+
*
|
|
311
|
+
* Sends `code:add` with the folder path so the app activates the project,
|
|
312
|
+
* sets up git state, and pulls intents/decisions from the API. The handler
|
|
313
|
+
* is idempotent and returns the existing project if already added.
|
|
295
314
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
315
|
+
* A `code:add` failure arrives here as a rejected promise — `routeResponse`
|
|
316
|
+
* already rejects with the handler's real error on `success: false`. We must
|
|
317
|
+
* NOT swallow it: registration is a precondition for every repo-targeting
|
|
318
|
+
* tool, so a hidden failure lets the tool proceed and fail downstream with a
|
|
319
|
+
* misleading message (e.g. "No project open for this repo origin"). Re-throw
|
|
320
|
+
* with repo-path context; the dispatcher (index.ts) surfaces it to the caller
|
|
321
|
+
* as structured tool output so the real reason is visible.
|
|
301
322
|
*/
|
|
302
323
|
export async function ensureRepo(repoPath) {
|
|
303
324
|
try {
|
|
304
325
|
await request('code', 'add', { folder: repoPath });
|
|
305
326
|
}
|
|
306
327
|
catch (err) {
|
|
307
|
-
|
|
328
|
+
throw new Error(`Could not register repository "${repoPath}" with Kawa Code: ${err.message}`);
|
|
308
329
|
}
|
|
309
330
|
}
|
|
310
331
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muninn-ipc.js","sourceRoot":"","sources":["../../src/services/muninn-ipc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,MAAM,YAAY,GAAG,KAAK,CAAA;AAC1B,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;AAEpG;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;AAC9G,MAAM,0BAA0B,GAAG,MAAM,CAA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K,CAAA;IACjB,MAAM,GAAG,IAAI,CAAA;IACb,iBAAiB,GAAG,IAAI,CAAA;IAExB,8BAA8B;IAC9B,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,eAAe,EAAE,CAAC;QAC5C,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAA;IACvD,CAAC;IACD,eAAe,CAAC,KAAK,EAAE,CAAA;AACzB,CAAC"}
|
|
@@ -7,7 +7,17 @@
|
|
|
7
7
|
* with complete_intent. We read Claude Code's own transcript (harness
|
|
8
8
|
* introspection — not Muninn's concern) and compare the position of the last
|
|
9
9
|
* SUCCESSFUL commit against the last complete_intent call.
|
|
10
|
+
*
|
|
11
|
+
* The gate consumes three additional pure signals (loop-fix, 2026-07-03):
|
|
12
|
+
* - `lastUnfinalizedCommit` — the commit's command + short sha, so the gate can
|
|
13
|
+
* attribute the commit to ITS OWN repo (`extractCommitPath`) instead of cwd's.
|
|
14
|
+
* - `nagAlreadyInTranscript` — once-per-commit nag dedup, stateless: a prior
|
|
15
|
+
* gate message after the commit means we already nagged (block once, then
|
|
16
|
+
* silence — never loop).
|
|
10
17
|
*/
|
|
18
|
+
/** Marker present in every gate nag (see kawacode-on-stop.ts buildGateReason).
|
|
19
|
+
* Matching on it is backwards-compatible: historical nags contain it too. */
|
|
20
|
+
export declare const NAG_MARKER = "Run complete_intent(intentId=";
|
|
11
21
|
/** Flatten a tool_result `content` (string | array of {type,text}) to plain text. */
|
|
12
22
|
export declare function toolResultText(content: unknown): string;
|
|
13
23
|
/** A Bash command that *invokes* `git commit` (incl. `git -C <path> commit`),
|
|
@@ -28,21 +38,51 @@ export declare function isGitCommitCommand(name: string, cmd: string): boolean;
|
|
|
28
38
|
* is far less disruptive than a false block (the printf-in-transcript bug).
|
|
29
39
|
*/
|
|
30
40
|
export declare function looksLikeCommitOutput(text: string): boolean;
|
|
41
|
+
/** A confirmed commit found in the transcript. */
|
|
42
|
+
export interface ConfirmedCommit {
|
|
43
|
+
/** Transcript line index of the commit tool_use. */
|
|
44
|
+
lineIdx: number;
|
|
45
|
+
/** The Bash command that produced the commit. */
|
|
46
|
+
cmd: string;
|
|
47
|
+
/** Short sha extracted from git's `[<ref> <shorthash>]` success line ('' if unparseable). */
|
|
48
|
+
shortSha: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The most recent CONFIRMED commit that is NOT followed by a complete_intent
|
|
52
|
+
* call — i.e. the commit the gate would nag about — or null when every commit
|
|
53
|
+
* is finalized (or there are no commits).
|
|
54
|
+
*/
|
|
55
|
+
export declare function lastUnfinalizedCommit(transcriptText: string): ConfirmedCommit | null;
|
|
31
56
|
/**
|
|
32
57
|
* True when the transcript shows a SUCCESSFUL `git commit` tool_use that lands
|
|
33
58
|
* after the most recent complete_intent tool_use (or with no complete_intent
|
|
34
59
|
* after it) — i.e. the agent committed without finalizing.
|
|
35
60
|
*
|
|
36
|
-
* A commit counts only when BOTH hold: the command invokes git commit AND its
|
|
37
|
-
* tool_result carries the commit-success signature (not is_error). Requiring
|
|
38
|
-
* the result signature is what stops a command that merely *mentions* "git
|
|
39
|
-
* commit" (e.g. a printf crafting a fixture) from being read as a real commit.
|
|
40
|
-
* A complete_intent call counts even if it later failed (conflicts): the agent
|
|
41
|
-
* tried, so we don't nag.
|
|
42
|
-
*
|
|
43
61
|
* @param transcriptText raw JSONL contents of the Claude Code transcript
|
|
44
62
|
*/
|
|
45
63
|
export declare function detectUncompletedCommit(transcriptText: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Repo attribution for a commit command (loop-fix): the directory the commit
|
|
66
|
+
* actually ran in, when the command states it.
|
|
67
|
+
*
|
|
68
|
+
* 1. `git -C <path> commit …` — the path is on the commit invocation itself
|
|
69
|
+
* (highest precedence).
|
|
70
|
+
* 2. `cd <path> && … git commit …` — the LAST `cd` before the git commit
|
|
71
|
+
* segment. Handles `;` and `&&` chains.
|
|
72
|
+
*
|
|
73
|
+
* Returns null when the command carries no path (the commit ran in the Bash
|
|
74
|
+
* session's cwd — the caller falls back to the hook payload cwd). Quoted paths
|
|
75
|
+
* are unwrapped; relative paths are returned as-is (caller resolves).
|
|
76
|
+
*/
|
|
77
|
+
export declare function extractCommitPath(cmd: string): string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Once-per-commit nag dedup (stateless): true when a prior gate nag already
|
|
80
|
+
* appears in the transcript AFTER the commit — Claude Code records both the
|
|
81
|
+
* block feedback and the degraded advisory as transcript content, so the
|
|
82
|
+
* transcript itself is the memory. Raw line matching (not JSON parsing) keeps
|
|
83
|
+
* this robust to how the harness encodes hook output.
|
|
84
|
+
*/
|
|
85
|
+
export declare function nagAlreadyInTranscript(transcriptText: string, commitLineIdx: number): boolean;
|
|
46
86
|
/**
|
|
47
87
|
* Gate-SAVE detection (VALUE_METRICS.md V8): the inverse of an uncompleted
|
|
48
88
|
* commit — a CONFIRMED `git commit` exists AND a complete_intent call lands at
|
|
@@ -52,11 +92,6 @@ export declare function detectUncompletedCommit(transcriptText: string): boolean
|
|
|
52
92
|
* preceded a completion that would otherwise have skipped distillation +
|
|
53
93
|
* block auto-capture.
|
|
54
94
|
*
|
|
55
|
-
* Mirrors detectUncompletedCommit's parsing exactly (a commit counts only when
|
|
56
|
-
* its tool_result carries the commit-success signature, per decision 64b340d8 —
|
|
57
|
-
* a command merely MENTIONING "git commit" does not count) and flips the final
|
|
58
|
-
* position comparison.
|
|
59
|
-
*
|
|
60
95
|
* Correlation, not causation: this says "a completion followed a confirmed
|
|
61
96
|
* commit while the turn was held open", not "the gate caused the completion".
|
|
62
97
|
*/
|