@kawacode/mcp 5.2.2 → 6.0.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.
Files changed (78) hide show
  1. package/CLAUDE.md.example +1 -1
  2. package/README.md +54 -198
  3. package/build/index.js +10 -1
  4. package/build/index.js.map +1 -1
  5. package/build/kawacode-on-pre-edit.d.ts +27 -0
  6. package/build/kawacode-on-pre-edit.js +205 -0
  7. package/build/kawacode-on-pre-edit.js.map +1 -0
  8. package/build/kawacode-on-stop.d.ts +29 -0
  9. package/build/kawacode-on-stop.js +84 -0
  10. package/build/kawacode-on-stop.js.map +1 -0
  11. package/build/prompts/intent-first-workflow.js +2 -2
  12. package/build/tools/_fork-fields.d.ts +84 -0
  13. package/build/tools/_fork-fields.js +65 -0
  14. package/build/tools/_fork-fields.js.map +1 -0
  15. package/build/tools/activate-intent.d.ts +66 -0
  16. package/build/tools/activate-intent.js +59 -3
  17. package/build/tools/activate-intent.js.map +1 -1
  18. package/build/tools/check-active-intent.d.ts +64 -0
  19. package/build/tools/check-active-intent.js +16 -2
  20. package/build/tools/check-active-intent.js.map +1 -1
  21. package/build/tools/complete-intent.d.ts +115 -4
  22. package/build/tools/complete-intent.js +130 -11
  23. package/build/tools/complete-intent.js.map +1 -1
  24. package/build/tools/create-intent.d.ts +73 -1
  25. package/build/tools/create-intent.js +105 -7
  26. package/build/tools/create-intent.js.map +1 -1
  27. package/build/tools/detect-intent-conflicts.d.ts +52 -0
  28. package/build/tools/detect-intent-conflicts.js +14 -10
  29. package/build/tools/detect-intent-conflicts.js.map +1 -1
  30. package/build/tools/edit-session-decision.d.ts +64 -12
  31. package/build/tools/edit-session-decision.js +4 -1
  32. package/build/tools/edit-session-decision.js.map +1 -1
  33. package/build/tools/evolve-decisions.d.ts +52 -0
  34. package/build/tools/evolve-decisions.js +14 -15
  35. package/build/tools/evolve-decisions.js.map +1 -1
  36. package/build/tools/get-intent-changes.d.ts +52 -0
  37. package/build/tools/get-intent-changes.js +4 -1
  38. package/build/tools/get-intent-changes.js.map +1 -1
  39. package/build/tools/get-intents-for-file.d.ts +52 -0
  40. package/build/tools/get-intents-for-file.js +4 -1
  41. package/build/tools/get-intents-for-file.js.map +1 -1
  42. package/build/tools/get-intents-for-lines.d.ts +52 -0
  43. package/build/tools/get-intents-for-lines.js +4 -1
  44. package/build/tools/get-intents-for-lines.js.map +1 -1
  45. package/build/tools/get-project-decisions.d.ts +52 -0
  46. package/build/tools/get-project-decisions.js +4 -1
  47. package/build/tools/get-project-decisions.js.map +1 -1
  48. package/build/tools/get-relevant-context.d.ts +52 -0
  49. package/build/tools/get-relevant-context.js +18 -24
  50. package/build/tools/get-relevant-context.js.map +1 -1
  51. package/build/tools/get-session-decisions.d.ts +52 -0
  52. package/build/tools/get-session-decisions.js +4 -1
  53. package/build/tools/get-session-decisions.js.map +1 -1
  54. package/build/tools/index.d.ts +620 -18
  55. package/build/tools/index.js +12 -3
  56. package/build/tools/index.js.map +1 -1
  57. package/build/tools/infer-history.d.ts +6 -0
  58. package/build/tools/infer-history.js +28 -15
  59. package/build/tools/infer-history.js.map +1 -1
  60. package/build/tools/list-team-intents.d.ts +58 -6
  61. package/build/tools/list-team-intents.js +5 -2
  62. package/build/tools/list-team-intents.js.map +1 -1
  63. package/build/tools/log-work.d.ts +52 -0
  64. package/build/tools/log-work.js +4 -1
  65. package/build/tools/log-work.js.map +1 -1
  66. package/build/tools/pre-edit-acknowledge.d.ts +92 -0
  67. package/build/tools/pre-edit-acknowledge.js +48 -0
  68. package/build/tools/pre-edit-acknowledge.js.map +1 -0
  69. package/build/tools/pre-edit-decision-check.d.ts +141 -0
  70. package/build/tools/pre-edit-decision-check.js +77 -0
  71. package/build/tools/pre-edit-decision-check.js.map +1 -0
  72. package/build/tools/record-decision.d.ts +88 -12
  73. package/build/tools/record-decision.js +15 -1
  74. package/build/tools/record-decision.js.map +1 -1
  75. package/build/tools/update-intent.d.ts +60 -8
  76. package/build/tools/update-intent.js +6 -1
  77. package/build/tools/update-intent.js.map +1 -1
  78. package/package.json +6 -3
@@ -1 +1 @@
1
- {"version":3,"file":"check-active-intent.js","sourceRoot":"","sources":["../../src/tools/check-active-intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6EAA6E,CAAC;IACzH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;CACnE,CAAC,CAAA;AA2BF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAA6B;IACnE,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;IAEpE,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE;QAChD,UAAU,EAAE,YAAY;KACzB,CAAC,CAAA;IAEF,uDAAuD;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;IACzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,CAAA;IACnC,CAAC;IAED,OAAO;QACL,eAAe,EAAE,IAAI;QACrB,MAAM,EAAE;YACN,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,GAAG,CAAC,QAAQ,IAAI,EAAE;YACnC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;YACzB,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;YACrC,YAAY,EAAE,CAAC,MAAM,CAAC,YAAY,IAAI,SAAS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AY;QACxB,GAAG,iBAAiB,CAAC,KAAK,CAAC;KAC5B,CAAC,CAAA;IAEF,uDAAuD;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;IACzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,CAAA;IACnC,CAAC;IAED,OAAO;QACL,eAAe,EAAE,IAAI;QACrB,MAAM,EAAE;YACN,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,GAAG,CAAC,QAAQ,IAAI,EAAE;YACnC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;YACzB,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;YACrC,YAAY,EAAE,CAAC,MAAM,CAAC,YAAY,IAAI,SAAS,CAA2C;YAC1F,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;YACrC,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,QAAQ;YACjC,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,MAAM,EAAE,EAAE,CAAC,wDAAwD;SACpE;KACF,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EAAE;;;;;;;;;;;;;;;;;;iCAkBkB;IAC/B,WAAW,EAAE,uBAAuB;IACpC,OAAO,EAAE,iBAAiB;CAC3B,CAAA"}
@@ -1,5 +1,19 @@
1
1
  import { z } from 'zod';
2
2
  export declare const completeIntentSchema: z.ZodObject<{
3
+ forkAuthor: z.ZodOptional<z.ZodObject<{
4
+ platform: z.ZodEnum<["github", "gitlab"]>;
5
+ user: z.ZodString;
6
+ forkOrigin: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ platform: "github" | "gitlab";
9
+ user: string;
10
+ forkOrigin: string;
11
+ }, {
12
+ platform: "github" | "gitlab";
13
+ user: string;
14
+ forkOrigin: string;
15
+ }>>;
16
+ workspaceId: z.ZodOptional<z.ZodString>;
3
17
  repoOrigin: z.ZodOptional<z.ZodString>;
4
18
  repoPath: z.ZodString;
5
19
  intentId: z.ZodOptional<z.ZodString>;
@@ -7,34 +21,119 @@ export declare const completeIntentSchema: z.ZodObject<{
7
21
  status: z.ZodDefault<z.ZodEnum<["committed", "pushed", "done", "abandoned", "superseded"]>>;
8
22
  supersededBy: z.ZodOptional<z.ZodString>;
9
23
  }, "strip", z.ZodTypeAny, {
10
- repoPath: string;
11
24
  status: "committed" | "pushed" | "done" | "abandoned" | "superseded";
25
+ repoPath: string;
12
26
  repoOrigin?: string | undefined;
27
+ forkAuthor?: {
28
+ platform: "github" | "gitlab";
29
+ user: string;
30
+ forkOrigin: string;
31
+ } | undefined;
32
+ workspaceId?: string | undefined;
13
33
  intentId?: string | undefined;
14
34
  commitSha?: string | undefined;
15
35
  supersededBy?: string | undefined;
16
36
  }, {
17
37
  repoPath: string;
18
- repoOrigin?: string | undefined;
19
38
  status?: "committed" | "pushed" | "done" | "abandoned" | "superseded" | undefined;
39
+ repoOrigin?: string | undefined;
40
+ forkAuthor?: {
41
+ platform: "github" | "gitlab";
42
+ user: string;
43
+ forkOrigin: string;
44
+ } | undefined;
45
+ workspaceId?: string | undefined;
20
46
  intentId?: string | undefined;
21
47
  commitSha?: string | undefined;
22
48
  supersededBy?: string | undefined;
23
49
  }>;
24
50
  export type CompleteIntentInput = z.infer<typeof completeIntentSchema>;
51
+ /**
52
+ * One contradiction between a distilled proposed decision and an existing
53
+ * standard decision in the repo. Surfaced when distillation produces decisions
54
+ * that conflict with previously-recorded ones (PRD §5.2 step 5b / §7.2).
55
+ */
56
+ export interface ConflictMatch {
57
+ proposedDecisionSummary: string;
58
+ proposedDecisionRationale: string;
59
+ conflictsWith: {
60
+ decisionId: string;
61
+ summary: string;
62
+ intentTitle?: string;
63
+ author?: string;
64
+ };
65
+ sharedConcern?: string;
66
+ description?: string;
67
+ }
25
68
  export interface CompleteIntentResponse {
26
69
  success: boolean;
27
70
  intentId: string;
28
71
  previousStatus: string;
72
+ /**
73
+ * The status after this call. Stays "active" when distillation surfaces
74
+ * conflicts (PRD §5.2 step 5b — no decisions written, no transition).
75
+ */
29
76
  newStatus: string;
30
77
  commitSha?: string;
31
78
  message: string;
79
+ /**
80
+ * Number of distilled standard decisions written to the API on a clean
81
+ * completion. Omitted when there were no ephemerals, when the v2 pipeline
82
+ * is disabled, or when conflicts blocked the write.
83
+ *
84
+ * Decision *content* is intentionally not surfaced here — it's already
85
+ * visible via the orchestration panel and via get_intent_decisions /
86
+ * get_relevant_context. Inlining the full list would just duplicate that
87
+ * channel and add noise to the agent's reply.
88
+ */
89
+ committedDecisionCount?: number;
90
+ /**
91
+ * Non-empty when the proposed-decision distillation contradicted existing
92
+ * standard decisions. Each entry pairs the proposed decision with the
93
+ * specific standard decision it contradicts, so the agent can surface the
94
+ * pair to the user. When conflicts is non-empty, success=false and
95
+ * newStatus stays "active" — the user resolves and retries.
96
+ */
97
+ conflicts?: ConflictMatch[];
98
+ /**
99
+ * Set when success=false to discriminate between:
100
+ * - "conflicts" → see `conflicts[]`
101
+ * - "transient-failure" → distiller LLM call or /check-conflicts API errored;
102
+ * `failedStage` and `error` carry diagnostics, the user retries.
103
+ */
104
+ reason?: 'conflicts' | 'transient-failure';
105
+ failedStage?: string;
106
+ error?: string;
107
+ /**
108
+ * Phase 3.5 — true when an API write call (decisions/sync, intents/PATCH)
109
+ * was queued for later replay because the API was unreachable. Work is
110
+ * "done" from the user's perspective; surface a heads-up. `deferredStages`
111
+ * names which write(s) were queued.
112
+ */
113
+ apiSyncDeferred?: boolean;
114
+ deferredStages?: string[];
115
+ deferredDecisionCount?: number;
116
+ deferredError?: string;
32
117
  }
33
118
  export declare function completeIntent(input: CompleteIntentInput): Promise<CompleteIntentResponse>;
34
119
  export declare const completeIntentTool: {
35
120
  name: string;
36
121
  description: string;
37
122
  inputSchema: z.ZodObject<{
123
+ forkAuthor: z.ZodOptional<z.ZodObject<{
124
+ platform: z.ZodEnum<["github", "gitlab"]>;
125
+ user: z.ZodString;
126
+ forkOrigin: z.ZodString;
127
+ }, "strip", z.ZodTypeAny, {
128
+ platform: "github" | "gitlab";
129
+ user: string;
130
+ forkOrigin: string;
131
+ }, {
132
+ platform: "github" | "gitlab";
133
+ user: string;
134
+ forkOrigin: string;
135
+ }>>;
136
+ workspaceId: z.ZodOptional<z.ZodString>;
38
137
  repoOrigin: z.ZodOptional<z.ZodString>;
39
138
  repoPath: z.ZodString;
40
139
  intentId: z.ZodOptional<z.ZodString>;
@@ -42,16 +141,28 @@ export declare const completeIntentTool: {
42
141
  status: z.ZodDefault<z.ZodEnum<["committed", "pushed", "done", "abandoned", "superseded"]>>;
43
142
  supersededBy: z.ZodOptional<z.ZodString>;
44
143
  }, "strip", z.ZodTypeAny, {
45
- repoPath: string;
46
144
  status: "committed" | "pushed" | "done" | "abandoned" | "superseded";
145
+ repoPath: string;
47
146
  repoOrigin?: string | undefined;
147
+ forkAuthor?: {
148
+ platform: "github" | "gitlab";
149
+ user: string;
150
+ forkOrigin: string;
151
+ } | undefined;
152
+ workspaceId?: string | undefined;
48
153
  intentId?: string | undefined;
49
154
  commitSha?: string | undefined;
50
155
  supersededBy?: string | undefined;
51
156
  }, {
52
157
  repoPath: string;
53
- repoOrigin?: string | undefined;
54
158
  status?: "committed" | "pushed" | "done" | "abandoned" | "superseded" | undefined;
159
+ repoOrigin?: string | undefined;
160
+ forkAuthor?: {
161
+ platform: "github" | "gitlab";
162
+ user: string;
163
+ forkOrigin: string;
164
+ } | undefined;
165
+ workspaceId?: string | undefined;
55
166
  intentId?: string | undefined;
56
167
  commitSha?: string | undefined;
57
168
  supersededBy?: string | undefined;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { request } from '../services/muninn-ipc.js';
3
3
  import { resolveOrigin } from './resolve-origin.js';
4
+ import { forkFieldsExtensions, extractForkFields } from './_fork-fields.js';
4
5
  export const completeIntentSchema = z.object({
5
6
  repoOrigin: z.string().optional().describe('Git remote origin URL. Auto-detected from repoPath via git if not provided.'),
6
7
  repoPath: z.string().describe('Local path to the repository root'),
@@ -8,7 +9,8 @@ export const completeIntentSchema = z.object({
8
9
  commitSha: z.string().optional().describe('The git commit SHA to associate with this intent (if already committed)'),
9
10
  status: z.enum(['committed', 'pushed', 'done', 'abandoned', 'superseded']).default('committed')
10
11
  .describe('The new status for the intent. Use "committed" after git commit, "done" when work is complete, "abandoned" to discard, "superseded" when another intent replaces this one.'),
11
- supersededBy: z.string().optional().describe('Intent ID that supersedes this one. Required when status is "superseded".')
12
+ supersededBy: z.string().optional().describe('Intent ID that supersedes this one. Required when status is "superseded".'),
13
+ ...forkFieldsExtensions,
12
14
  });
13
15
  export async function completeIntent(input) {
14
16
  const actualOrigin = resolveOrigin(input.repoOrigin, input.repoPath);
@@ -43,23 +45,102 @@ export async function completeIntent(input) {
43
45
  status: input.status,
44
46
  commitSha: input.commitSha,
45
47
  supersededBy: input.supersededBy,
48
+ ...extractForkFields(input),
46
49
  });
47
50
  const intentId = res.intentId || '';
48
51
  const intentTitle = res.intentTitle || 'Intent';
49
52
  const previousStatus = res.previousStatus || 'active';
50
- const statusMessages = {
51
- committed: `Intent "${intentTitle}" marked as committed`,
52
- pushed: `Intent "${intentTitle}" marked as pushed`,
53
- done: `Intent "${intentTitle}" marked as done`,
54
- abandoned: `Intent "${intentTitle}" abandoned`
55
- };
53
+ const success = res.success !== false;
54
+ const conflicts = Array.isArray(res.conflicts) ? res.conflicts : [];
55
+ const committedDecisionCount = typeof res.committedDecisionCount === 'number' ? res.committedDecisionCount : undefined;
56
+ const reason = res.reason === 'conflicts' || res.reason === 'transient-failure' ? res.reason : undefined;
57
+ const apiSyncDeferred = res.apiSyncDeferred === true;
58
+ // Branch on the four §7.2 / §7.3 outcome shapes — pick the message that
59
+ // tells the agent exactly what to surface to the user.
60
+ let newStatus;
61
+ let message;
62
+ if (!success && reason === 'conflicts') {
63
+ // PRD §5.2 step 5b — distilled decisions contradicted standards. No write,
64
+ // no transition, bucket preserved. The agent's job is to surface each
65
+ // conflict to the user and ask how to resolve.
66
+ newStatus = res.status || 'active';
67
+ const lines = [
68
+ `Cannot complete: ${conflicts.length} conflict(s) between proposed decisions and existing standards.`,
69
+ '',
70
+ 'For each conflict below, surface BOTH sides side-by-side to the user and ask how to resolve.',
71
+ 'Common resolution paths:',
72
+ ' (A) Record a superseding decision: record_decision(type="fork", supersedes=["<existing-decision-id>"], rationale=...). Then retry complete_intent.',
73
+ ' (B) Abandon the intent: complete_intent(status="abandoned"). Decisions are soft-deleted but recoverable via activate_intent.',
74
+ ' (C) Keep the intent active and continue working.',
75
+ '',
76
+ 'DO NOT silently retry — every retry runs the distiller again and produces the same conflicts.',
77
+ '',
78
+ ];
79
+ conflicts.forEach((c, i) => {
80
+ lines.push(`[${i + 1}] Proposed: ${c.proposedDecisionSummary}`);
81
+ const cw = c.conflictsWith || {};
82
+ const author = cw.author ? ` by ${cw.author}` : '';
83
+ const intentPart = cw.intentTitle ? ` (intent: "${cw.intentTitle}")` : '';
84
+ lines.push(` Conflicts with: ${cw.summary || cw.decisionId || '(unknown)'}${intentPart}${author}`);
85
+ if (c.description)
86
+ lines.push(` ${c.description}`);
87
+ lines.push('');
88
+ });
89
+ message = lines.join('\n');
90
+ }
91
+ else if (!success && reason === 'transient-failure') {
92
+ // Distiller LLM error or /check-conflicts API error. Bucket re-populated,
93
+ // intent stays active. User decides whether to wait + retry or abandon.
94
+ newStatus = res.status || 'active';
95
+ const stage = res.failedStage ? ` (${res.failedStage})` : '';
96
+ const errPart = res.error ? `: ${res.error}` : '';
97
+ message =
98
+ `Could not complete intent "${intentTitle}" — transient failure${stage}${errPart}. ` +
99
+ `The ephemerals were preserved. Wait for the underlying issue to clear, then retry complete_intent. ` +
100
+ `If retrying repeatedly fails, the user can abandon the intent (complete_intent(status="abandoned")).`;
101
+ }
102
+ else if (!success) {
103
+ // Catch-all for legacy / unexpected error shapes.
104
+ newStatus = res.newStatus || res.status || input.status;
105
+ message = `Failed to complete intent "${intentTitle}".`;
106
+ }
107
+ else {
108
+ // Clean completion. Note: Phase 3.5 may have queued writes for later
109
+ // replay — the response is success=true but apiSyncDeferred=true.
110
+ newStatus = res.newStatus || input.status;
111
+ const statusMessages = {
112
+ committed: `Intent "${intentTitle}" marked as committed`,
113
+ pushed: `Intent "${intentTitle}" marked as pushed`,
114
+ done: `Intent "${intentTitle}" marked as done`,
115
+ abandoned: `Intent "${intentTitle}" abandoned`,
116
+ superseded: `Intent "${intentTitle}" marked as superseded`,
117
+ };
118
+ const statusMsg = statusMessages[input.status] || `Intent "${intentTitle}" updated`;
119
+ const shaPart = input.commitSha ? ` (commit: ${input.commitSha.substring(0, 7)})` : '';
120
+ const distilledPart = committedDecisionCount && committedDecisionCount > 0
121
+ ? ` — ${committedDecisionCount} distilled decision(s) recorded`
122
+ : '';
123
+ const deferredPart = apiSyncDeferred
124
+ ? ` — API sync deferred (${(res.deferredStages || []).join(', ')}); will retry on the next sync tick`
125
+ : '';
126
+ message = statusMsg + shaPart + distilledPart + deferredPart;
127
+ }
56
128
  return {
57
- success: res.success !== false,
129
+ success,
58
130
  intentId,
59
131
  previousStatus,
60
- newStatus: input.status,
132
+ newStatus,
61
133
  commitSha: input.commitSha,
62
- message: statusMessages[input.status] + (input.commitSha ? ` (commit: ${input.commitSha.substring(0, 7)})` : '')
134
+ message,
135
+ committedDecisionCount,
136
+ conflicts: conflicts.length > 0 ? conflicts : undefined,
137
+ reason,
138
+ failedStage: res.failedStage,
139
+ error: res.error,
140
+ apiSyncDeferred: apiSyncDeferred ? true : undefined,
141
+ deferredStages: Array.isArray(res.deferredStages) ? res.deferredStages : undefined,
142
+ deferredDecisionCount: typeof res.deferredDecisionCount === 'number' ? res.deferredDecisionCount : undefined,
143
+ deferredError: res.deferredError,
63
144
  };
64
145
  }
65
146
  export const completeIntentTool = {
@@ -75,7 +156,45 @@ Status values:
75
156
  - "committed": Code is committed locally (default)
76
157
  - "pushed": Code has been pushed to remote
77
158
  - "done": Work is fully complete
78
- - "abandoned": Work was discarded without committing`,
159
+ - "abandoned": Work was discarded without committing
160
+
161
+ REQUIRED: Inspect the response after calling this tool. Four outcomes:
162
+
163
+ 1. response.success === true:
164
+ The task is complete. Briefly acknowledge the commit and — if
165
+ response.committedDecisionCount > 0 — mention that N distilled architectural
166
+ decisions were recorded for the intent. Do NOT enumerate the decisions
167
+ inline; they're visible via the orchestration panel and via
168
+ get_intent_decisions / get_relevant_context if the user wants details.
169
+ If response.apiSyncDeferred === true, also mention that the API sync was
170
+ deferred; the queued writes will replay on the next sync tick.
171
+
172
+ 2. response.success === false AND response.conflicts is non-empty:
173
+ The distillation produced decisions that contradict existing standards in
174
+ this repo. Status stays "active" and NO decisions were written.
175
+ Surface EACH conflict to the user with the proposed decision and the
176
+ conflicting standard decision side-by-side. Then ask the user how to
177
+ resolve. Common options to suggest:
178
+ (A) Record a superseding decision via record_decision(type="fork",
179
+ supersedes=["<existing-decision-id>"], rationale=...). Then retry
180
+ complete_intent — the distiller may now find the new superseding
181
+ decision in recall and the conflict resolves.
182
+ (B) Abandon the intent: complete_intent(status="abandoned"). Decisions
183
+ are soft-deleted but recoverable via activate_intent if the user
184
+ changes their mind.
185
+ (C) Keep the intent active and continue working.
186
+ DO NOT silently retry — every retry runs the distiller (and the per-pair
187
+ judge) again. Wait for the user's decision.
188
+
189
+ 3. response.success === false AND response.reason === "transient-failure":
190
+ The distiller LLM call or the conflict-check API call errored. The
191
+ ephemerals are preserved (the bucket is intact), and the intent stays
192
+ "active". Tell the user the failure stage (response.failedStage) and the
193
+ underlying error, then suggest retrying once the issue clears, or
194
+ abandoning if the failure persists.
195
+
196
+ 4. In a non-interactive (autonomous) session: log the conflicts at WARN level
197
+ and leave the intent active. A human review path exists via the panel.`,
79
198
  inputSchema: completeIntentSchema,
80
199
  handler: completeIntent
81
200
  };
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WAAW;QAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QACnD,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;QAClF,qBAAqB,EAAE,OAAO,GAAG,CAAC,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS;QAC5G,aAAa,EAAE,GAAG,CAAC,aAAa;KACjC,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EAiD2D;IACxE,WAAW,EAAE,oBAAoB;IACjC,OAAO,EAAE,cAAc;CACxB,CAAA"}
@@ -1,5 +1,19 @@
1
1
  import { z } from 'zod';
2
2
  export declare const createAndActivateIntentSchema: z.ZodObject<{
3
+ forkAuthor: z.ZodOptional<z.ZodObject<{
4
+ platform: z.ZodEnum<["github", "gitlab"]>;
5
+ user: z.ZodString;
6
+ forkOrigin: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ platform: "github" | "gitlab";
9
+ user: string;
10
+ forkOrigin: string;
11
+ }, {
12
+ platform: "github" | "gitlab";
13
+ user: string;
14
+ forkOrigin: string;
15
+ }>>;
16
+ workspaceId: z.ZodOptional<z.ZodString>;
3
17
  repoOrigin: z.ZodOptional<z.ZodString>;
4
18
  repoPath: z.ZodString;
5
19
  title: z.ZodString;
@@ -14,12 +28,24 @@ export declare const createAndActivateIntentSchema: z.ZodObject<{
14
28
  templateType: "feature" | "refactor" | "exploration";
15
29
  force: boolean;
16
30
  repoOrigin?: string | undefined;
31
+ forkAuthor?: {
32
+ platform: "github" | "gitlab";
33
+ user: string;
34
+ forkOrigin: string;
35
+ } | undefined;
36
+ workspaceId?: string | undefined;
17
37
  constraints?: string[] | undefined;
18
38
  }, {
19
39
  repoPath: string;
20
40
  title: string;
21
41
  description: string;
22
42
  repoOrigin?: string | undefined;
43
+ forkAuthor?: {
44
+ platform: "github" | "gitlab";
45
+ user: string;
46
+ forkOrigin: string;
47
+ } | undefined;
48
+ workspaceId?: string | undefined;
23
49
  templateType?: "feature" | "refactor" | "exploration" | undefined;
24
50
  constraints?: string[] | undefined;
25
51
  force?: boolean | undefined;
@@ -39,18 +65,52 @@ interface ConflictInfo {
39
65
  oppositionDetected: boolean;
40
66
  oppositionDetail: string | null;
41
67
  }
68
+ export interface ActiveIntentLockConflict {
69
+ existingIntentId: string;
70
+ title?: string;
71
+ createdBy?: string;
72
+ author?: string;
73
+ }
74
+ /**
75
+ * Soft-lock surfaced when a `pending` intent blocks creating a new one on
76
+ * the same repo. PRD_AGENT_COORDINATION_LAYER_02 §6.3 — the agent must prompt
77
+ * the user to abandon-or-finalize the pending one before proceeding.
78
+ */
79
+ export interface PendingIntentBlocking {
80
+ intentId: string;
81
+ title?: string;
82
+ pendingReason?: string;
83
+ lastActivityAt?: string;
84
+ distilledDecisionCount?: number;
85
+ }
42
86
  export interface CreateIntentResponse {
43
87
  success: boolean;
44
88
  intentId: string;
45
- action: 'created' | 'reactivated' | 'conflict';
89
+ action: 'created' | 'reactivated' | 'conflict' | 'lock_conflict' | 'pending_blocked';
46
90
  message: string;
47
91
  conflicts?: ConflictInfo[];
92
+ lockConflict?: ActiveIntentLockConflict;
93
+ pendingIntent?: PendingIntentBlocking;
48
94
  }
49
95
  export declare function createAndActivateIntent(input: CreateIntentInput): Promise<CreateIntentResponse>;
50
96
  export declare const createAndActivateIntentTool: {
51
97
  name: string;
52
98
  description: string;
53
99
  inputSchema: z.ZodObject<{
100
+ forkAuthor: z.ZodOptional<z.ZodObject<{
101
+ platform: z.ZodEnum<["github", "gitlab"]>;
102
+ user: z.ZodString;
103
+ forkOrigin: z.ZodString;
104
+ }, "strip", z.ZodTypeAny, {
105
+ platform: "github" | "gitlab";
106
+ user: string;
107
+ forkOrigin: string;
108
+ }, {
109
+ platform: "github" | "gitlab";
110
+ user: string;
111
+ forkOrigin: string;
112
+ }>>;
113
+ workspaceId: z.ZodOptional<z.ZodString>;
54
114
  repoOrigin: z.ZodOptional<z.ZodString>;
55
115
  repoPath: z.ZodString;
56
116
  title: z.ZodString;
@@ -65,12 +125,24 @@ export declare const createAndActivateIntentTool: {
65
125
  templateType: "feature" | "refactor" | "exploration";
66
126
  force: boolean;
67
127
  repoOrigin?: string | undefined;
128
+ forkAuthor?: {
129
+ platform: "github" | "gitlab";
130
+ user: string;
131
+ forkOrigin: string;
132
+ } | undefined;
133
+ workspaceId?: string | undefined;
68
134
  constraints?: string[] | undefined;
69
135
  }, {
70
136
  repoPath: string;
71
137
  title: string;
72
138
  description: string;
73
139
  repoOrigin?: string | undefined;
140
+ forkAuthor?: {
141
+ platform: "github" | "gitlab";
142
+ user: string;
143
+ forkOrigin: string;
144
+ } | undefined;
145
+ workspaceId?: string | undefined;
74
146
  templateType?: "feature" | "refactor" | "exploration" | undefined;
75
147
  constraints?: string[] | undefined;
76
148
  force?: boolean | undefined;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { request } from '../services/muninn-ipc.js';
3
3
  import { resolveOrigin } from './resolve-origin.js';
4
+ import { forkFieldsExtensions, extractForkFields } from './_fork-fields.js';
4
5
  export const createAndActivateIntentSchema = z.object({
5
6
  repoOrigin: z.string().optional().describe('Git remote origin URL. Auto-detected from repoPath via git if not provided.'),
6
7
  repoPath: z.string().describe('Local path to the repository root'),
@@ -9,13 +10,12 @@ export const createAndActivateIntentSchema = z.object({
9
10
  templateType: z.enum(['feature', 'refactor', 'exploration']).default('feature').describe('Type of work'),
10
11
  constraints: z.array(z.string()).optional().describe('Requirements or constraints for this work'),
11
12
  force: z.boolean().optional().default(false).describe('Bypass conflict detection. Set to true after the user has reviewed detected conflicts and chosen to proceed anyway.'),
13
+ ...forkFieldsExtensions,
12
14
  });
13
15
  export async function createAndActivateIntent(input) {
14
16
  const actualOrigin = resolveOrigin(input.repoOrigin, input.repoPath);
15
- // Step 1: Create (or find-and-reactivate) the intent.
16
- // The Muninn handler proxies to API POST /intents/find-or-create which
17
- // dedups by embedding similarity (≥ 0.85) and runs automatic conflict
18
- // detection against all other intents for the repo.
17
+ // Step 1: Create the intent. If a sufficiently similar one already exists, the
18
+ // server may reactivate it instead of creating a duplicate.
19
19
  const createRes = await request('intent', 'create', {
20
20
  repoOrigin: actualOrigin,
21
21
  title: input.title,
@@ -24,7 +24,14 @@ export async function createAndActivateIntent(input) {
24
24
  constraints: input.constraints || [],
25
25
  scope: { type: 'repo', paths: [] },
26
26
  force: input.force || false,
27
+ ...extractForkFields(input),
27
28
  });
29
+ // Pending-intent soft lock — surfaced before any API write per PRD §6.3.
30
+ // The agent's job is to ask the user to dispose of the pending one before
31
+ // proceeding. force=true bypasses this for autonomous runs.
32
+ if (createRes.pendingIntentBlocking) {
33
+ return buildPendingBlockedResponse(createRes.pendingIntentBlocking);
34
+ }
28
35
  // Handle conflict detection — API returned 409 with conflict data.
29
36
  // Return the conflicts to the caller (Claude Code) so it can present
30
37
  // them to the user and optionally retry with force=true.
@@ -67,11 +74,38 @@ export async function createAndActivateIntent(input) {
67
74
  throw new Error('Intent creation succeeded but no intent ID was returned');
68
75
  }
69
76
  const action = createRes.action === 'reactivated' ? 'reactivated' : 'created';
70
- // Step 2: Set it as active
71
- await request('intent', 'set-active', {
77
+ // Step 2: Set it as active.
78
+ // The per-repo lock may reject this step even though the intent itself was created —
79
+ // forward force to Muninn and surface the lock conflict separately from the
80
+ // content-similarity conflict that createRes handles above.
81
+ const setRes = await request('intent', 'set-active', {
72
82
  repoOrigin: actualOrigin,
73
83
  intentId,
84
+ force: input.force || false,
85
+ ...extractForkFields(input),
74
86
  });
87
+ // The set-active step has its own pending-intent soft-lock check (the lock
88
+ // holder may have transitioned to pending between steps 1 and 2, or the
89
+ // pre-check on create may have been skipped because the active intent was
90
+ // not the lock holder). Surface the same shaped response.
91
+ if (setRes.pendingIntentBlocking) {
92
+ return buildPendingBlockedResponse(setRes.pendingIntentBlocking, intentId);
93
+ }
94
+ if (setRes.conflict === true && setRes.conflictType === 'active_intent_lock') {
95
+ const lockConflict = await buildLockConflictDetails(actualOrigin, setRes.existingIntentId);
96
+ const idShort = setRes.existingIntentId.substring(0, 8);
97
+ const who = lockConflict.author ? ` by ${lockConflict.author}` : '';
98
+ const titlePart = lockConflict.title ? ` "${lockConflict.title}"` : '';
99
+ return {
100
+ success: false,
101
+ intentId,
102
+ action: 'lock_conflict',
103
+ lockConflict,
104
+ message: `Intent "${input.title}" was ${action} (id: ${intentId.substring(0, 8)}), but could not be activated: ` +
105
+ `repo already owns intent ${idShort}${titlePart}${who}. ` +
106
+ `Retry with force=true to take over, complete_intent on ${idShort} first, or abandon this new intent.`,
107
+ };
108
+ }
75
109
  const message = action === 'reactivated'
76
110
  ? `Reactivated existing similar intent: "${input.title}" — resuming previous work instead of creating a duplicate.`
77
111
  : `Created and activated intent: "${input.title}"`;
@@ -82,6 +116,49 @@ export async function createAndActivateIntent(input) {
82
116
  message,
83
117
  };
84
118
  }
119
+ function buildPendingBlockedResponse(blocker, intentId = '') {
120
+ const pendingIntent = {
121
+ intentId: blocker.intentId || '',
122
+ title: blocker.title || undefined,
123
+ pendingReason: blocker.pendingReason || undefined,
124
+ lastActivityAt: blocker.lastActivityAt || undefined,
125
+ distilledDecisionCount: typeof blocker.distilledDecisionCount === 'number'
126
+ ? blocker.distilledDecisionCount
127
+ : undefined,
128
+ };
129
+ const idShort = pendingIntent.intentId ? pendingIntent.intentId.substring(0, 8) : 'pending';
130
+ const titlePart = pendingIntent.title ? ` "${pendingIntent.title}"` : '';
131
+ const reasonPart = pendingIntent.pendingReason ? ` (reason: ${pendingIntent.pendingReason})` : '';
132
+ return {
133
+ success: false,
134
+ intentId,
135
+ action: 'pending_blocked',
136
+ pendingIntent,
137
+ message: `Pending intent ${idShort}${titlePart}${reasonPart} exists on this repo. ` +
138
+ `Ask the user how to proceed: ` +
139
+ `(A) abandon it via complete_intent(intentId="${pendingIntent.intentId}", status="abandoned"), ` +
140
+ `(C) complete and finalize it via complete_intent(intentId="${pendingIntent.intentId}", status="committed"), ` +
141
+ `then retry. To proceed without prompting, retry with force=true.`,
142
+ };
143
+ }
144
+ async function buildLockConflictDetails(repoOrigin, existingIntentId) {
145
+ try {
146
+ const res = await request('intent', 'get-active', { repoOrigin });
147
+ const intent = res.intent;
148
+ if (intent && intent.id === existingIntentId) {
149
+ return {
150
+ existingIntentId,
151
+ title: intent.title,
152
+ createdBy: intent.createdBy,
153
+ author: intent.authorInfo?.name || intent.author,
154
+ };
155
+ }
156
+ }
157
+ catch {
158
+ // Fall through to ID-only response
159
+ }
160
+ return { existingIntentId };
161
+ }
85
162
  export const createAndActivateIntentTool = {
86
163
  name: 'create_and_activate_intent',
87
164
  description: `Create a new intent from the user's request and mark it as active.
@@ -95,7 +172,28 @@ This ensures all AI-generated code gets properly tracked and attributed.
95
172
 
96
173
  If the tool returns conflicts (action="conflict"), present the conflict
97
174
  details to the user and ask whether to proceed. If yes, retry with
98
- force=true to bypass conflict detection.`,
175
+ force=true to bypass conflict detection.
176
+
177
+ Three distinct block types exist:
178
+
179
+ - action="conflict": content-similarity conflict from intent creation (another
180
+ team member's intent overlaps semantically or in files). Bypassed by
181
+ force=true after the user reviews and chooses to proceed.
182
+
183
+ - action="lock_conflict": per-repo active-intent lock — another session on this
184
+ repo already owns the active intent slot. The new intent was still created
185
+ and can be activated later; or call complete_intent on the existing one first.
186
+ Bypassed by force=true (takes over the active slot).
187
+
188
+ - action="pending_blocked": a "pending" intent exists on this repo (auto-finalized
189
+ by the orphan-recovery sweeper, or blocked by conflicts at completion). Surface
190
+ the pendingIntent details to the user and ask how to dispose of it before
191
+ starting new work:
192
+ (A) Abandon it: call complete_intent(intentId=..., status="abandoned").
193
+ (C) Complete and finalize: call complete_intent(intentId=..., status="committed").
194
+ After the user decides and the pending intent is disposed, retry create_and_activate_intent.
195
+ In autonomous (non-interactive) sessions, retry with force=true to proceed
196
+ without prompting — the pending intent stays pending.`,
99
197
  inputSchema: createAndActivateIntentSchema,
100
198
  handler: createAndActivateIntent
101
199
  };