@astrosheep/keiyaku 4.6.33 → 4.6.34
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 +10 -1
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/pi/keiyaku.ts +1 -135
- package/build/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/src/akuma/akuma-observe.d.ts +8 -0
- package/build/src/akuma/akuma-observe.js +8 -0
- package/build/src/akuma/akuma-owner.d.ts +1 -0
- package/build/src/akuma/akuma-owner.js +3 -5
- package/build/src/akuma/akuma-wait.d.ts +117 -2
- package/build/src/akuma/akuma-wait.js +53 -22
- package/build/src/akuma/akuma.d.ts +6 -1
- package/build/src/akuma/akuma.js +37 -18
- package/build/src/akuma/heart/facts.d.ts +1 -0
- package/build/src/akuma/heart/facts.js +14 -0
- package/build/src/akuma/heart/index.d.ts +6 -0
- package/build/src/akuma/heart/index.js +27 -9
- package/build/src/akuma/heart/rows.d.ts +1 -0
- package/build/src/akuma/heart/rows.js +4 -0
- package/build/src/akuma/lineage-cache.d.ts +7 -2
- package/build/src/akuma/lineage-cache.js +48 -24
- package/build/src/akuma/projection-read.js +4 -9
- package/build/src/akuma/selection-observation.d.ts +622 -0
- package/build/src/akuma/selection-observation.js +7 -3
- package/build/src/bounded-list.d.ts +8 -0
- package/build/src/bounded-list.js +10 -0
- package/build/src/cli/commands/akuma-grammar.d.ts +2 -3
- package/build/src/cli/commands/akuma-grammar.js +32 -39
- package/build/src/cli/commands/akuma.js +6 -3
- package/build/src/cli/commands/contract-grammar.js +32 -31
- package/build/src/cli/commands/contract-help.d.ts +3 -3
- package/build/src/cli/commands/contract-help.js +10 -8
- package/build/src/cli/commands/contract.d.ts +3 -3
- package/build/src/cli/commands/contract.js +11 -10
- package/build/src/cli/parse.d.ts +4 -10
- package/build/src/cli/parse.js +1 -1
- package/build/src/cli/render/akuma-activity.d.ts +9 -19
- package/build/src/cli/render/akuma-activity.js +83 -110
- package/build/src/cli/render/catalog.js +3 -2
- package/build/src/cli/render/contract-history.d.ts +1 -3
- package/build/src/cli/render/contract-history.js +68 -49
- package/build/src/cli/render/contract-wait.js +9 -1
- package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
- package/build/src/cli/render/kanshi-akuma.js +26 -21
- package/build/src/cli/render/kanshi.js +34 -43
- package/build/src/cli/render/verbs.js +20 -17
- package/build/src/cli/runtime.js +9 -23
- package/build/src/debt/board.d.ts +2 -1
- package/build/src/debt/board.js +3 -3
- package/build/src/debt/catalog.js +2 -1
- package/build/src/debt/document.d.ts +1 -0
- package/build/src/debt/document.js +3 -0
- package/build/src/debt/index.d.ts +2 -1
- package/build/src/debt/index.js +3 -3
- package/build/src/debt/operations.d.ts +2 -1
- package/build/src/git/observe.d.ts +4 -3
- package/build/src/git/observe.js +8 -7
- package/build/src/history.d.ts +26 -0
- package/build/src/history.js +43 -0
- package/build/src/index.d.ts +4 -3
- package/build/src/kanshi/counts.d.ts +15 -1
- package/build/src/kanshi/counts.js +14 -3
- package/build/src/kanshi/index.d.ts +3 -3
- package/build/src/kanshi/index.js +2 -2
- package/build/src/kanshi/read.js +5 -2
- package/build/src/library/akumas.d.ts +5 -1
- package/build/src/library/akumas.js +11 -5
- package/build/src/library/contract-composition.js +10 -10
- package/build/src/library/contract-creation.js +2 -2
- package/build/src/library/contract-types.d.ts +215 -25
- package/build/src/library/contract-types.js +31 -13
- package/build/src/library/contract-wait.d.ts +205 -0
- package/build/src/library/contract-wait.js +15 -3
- package/build/src/library/input.d.ts +3 -3
- package/build/src/library/input.js +5 -5
- package/build/src/library/kei.js +134 -76
- package/build/src/library/keiyaku-attribution.d.ts +1 -1
- package/build/src/library/keiyaku-attribution.js +3 -1
- package/build/src/library/keiyaku-classify.js +5 -1
- package/build/src/library/keiyaku-debt.d.ts +8 -7
- package/build/src/library/keiyaku-identity.d.ts +4 -3
- package/build/src/library/keiyaku-identity.js +30 -7
- package/build/src/library/keiyaku-verbs.d.ts +515 -44
- package/build/src/library/keiyaku-verbs.js +84 -79
- package/build/src/library/keiyaku-wait.d.ts +570 -0
- package/build/src/library/keiyaku-wait.js +25 -8
- package/build/src/library/keiyaku.d.ts +3110 -31
- package/build/src/library/keiyaku.js +335 -407
- package/build/src/library/model-tools.d.ts +268 -70
- package/build/src/library/model-tools.js +110 -95
- package/build/src/library/selection.d.ts +6 -5
- package/build/src/library/selection.js +10 -3
- package/build/src/mcp/adapter.js +1 -1
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +4 -3
- package/build/src/pi/index.d.ts +2 -0
- package/build/src/pi/index.js +23 -7
- package/build/src/pi/status.d.ts +12 -0
- package/build/src/pi/status.js +140 -0
- package/build/src/protocol/operations.d.ts +2 -0
- package/build/src/protocol/operations.js +1 -1
- package/build/src/protocol/read/status.d.ts +12 -4
- package/build/src/protocol/read/status.js +19 -12
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/package.json +1 -1
- package/plugins/paseo/plugin/index.server.ts +6 -2
- package/plugins/paseo/plugin/server/attach.ts +68 -48
- package/plugins/paseo/plugin/server/directory.ts +259 -0
- package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
- package/plugins/paseo/plugin/server/reopen.ts +52 -38
- package/plugins/pi/keiyaku.ts +1 -135
- package/skills/keiyaku-akuma/SKILL.md +5 -2
- package/skills/keiyaku-debt/SKILL.md +2 -1
|
@@ -2,16 +2,49 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { verbs } from "./keiyaku-verbs.js";
|
|
4
4
|
import { snapshotChangeSchema } from "../protocol/result-leaves.js";
|
|
5
|
+
import { akumaCatalogueSchema, akumaCatalogueRowSchema, akumaObservationSchema, observedAkumaWaitItemSchema, dispatchAssociationSchema, currentWorkSchema, contractCatalogueSchema, contractSummarySchema, contractNormalStatusSchema, akumaNameCatalogSchema, debtListSchema, contractIdSchema, akumaIdSchema, } from "./keiyaku-verbs.js";
|
|
5
6
|
const bind = verbs.bind.normal.unwrap();
|
|
6
7
|
const verify = verbs.verify.normal.unwrap();
|
|
7
|
-
const contract =
|
|
8
|
-
const akuma =
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const contract = contractNormalStatusSchema.unwrap();
|
|
9
|
+
const akuma = akumaObservationSchema.unwrap();
|
|
10
|
+
const associated = dispatchAssociationSchema.options[1].unwrap().omit({ kind: true });
|
|
11
|
+
const association = z.union([
|
|
12
|
+
associated,
|
|
13
|
+
dispatchAssociationSchema.options[2],
|
|
14
|
+
z.strictObject({ kind: z.literal("unavailable") }),
|
|
15
|
+
]);
|
|
16
|
+
const work = currentWorkSchema.unwrap().omit({ turn: true, activeTools: true, latestActivity: true });
|
|
17
|
+
const contractStatus = contract.omit({ kind: true, targetObservation: true }).meta({ id: "ContractStatus" });
|
|
18
|
+
const akumaStatus = akuma
|
|
19
|
+
.omit({ kind: true, contract: true, work: true })
|
|
20
|
+
.extend({
|
|
21
|
+
contract: association.exactOptional(),
|
|
22
|
+
work,
|
|
23
|
+
})
|
|
24
|
+
.meta({ id: "AkumaStatus" });
|
|
25
|
+
const akumaListRow = akumaCatalogueRowSchema
|
|
26
|
+
.unwrap()
|
|
27
|
+
.extend({ contract: association.exactOptional() })
|
|
28
|
+
.meta({ id: "AkumaRow" });
|
|
29
|
+
const contractWaitRow = contractSummarySchema
|
|
30
|
+
.unwrap()
|
|
31
|
+
.omit({ attention: true })
|
|
32
|
+
.extend({
|
|
33
|
+
changed: z.literal(true).exactOptional(),
|
|
34
|
+
terminal: z.enum(["claimed", "abandoned"]).exactOptional(),
|
|
35
|
+
})
|
|
36
|
+
.meta({ id: "ContractWaitRow" });
|
|
37
|
+
const akumaWaitRow = observedAkumaWaitItemSchema
|
|
38
|
+
.unwrap()
|
|
39
|
+
.omit({ kind: true, outcome: true })
|
|
40
|
+
.extend({
|
|
41
|
+
verdict: z.enum(["answered", "failed", "canceled"]).exactOptional(),
|
|
42
|
+
turn: z.string().exactOptional(),
|
|
43
|
+
answer: z.string().exactOptional(),
|
|
44
|
+
diagnostic: z.string().exactOptional(),
|
|
45
|
+
})
|
|
46
|
+
.meta({ id: "AkumaWaitRow" });
|
|
47
|
+
const unknownWaitRow = z.strictObject({ id: z.union([contractIdSchema, akumaIdSchema]), unknown: z.literal(true) });
|
|
15
48
|
const spawn = verbs.spawn.normal.unwrap();
|
|
16
49
|
const gateProblem = z.strictObject({
|
|
17
50
|
gate: z.string(),
|
|
@@ -73,28 +106,19 @@ export const modelOutputSchemas = {
|
|
|
73
106
|
verbs.ask.normal.options[1].unwrap().omit({ interrupt: true, wake: true }),
|
|
74
107
|
verbs.ask.normal.options[2].unwrap().omit({ interrupt: true, wake: true }),
|
|
75
108
|
]),
|
|
76
|
-
wait:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}),
|
|
82
|
-
akuma.omit({ changes: true, moreChanges: true, outsideChanges: true, contract: true, work: true }).extend({
|
|
83
|
-
contract: associated.exactOptional(),
|
|
84
|
-
work,
|
|
85
|
-
}),
|
|
86
|
-
]),
|
|
109
|
+
wait: z.strictObject({
|
|
110
|
+
reason: verbs.wait.normal.unwrap().shape.reason,
|
|
111
|
+
members: z.array(z.union([contractWaitRow, akumaWaitRow, unknownWaitRow])).nonempty(),
|
|
112
|
+
}),
|
|
113
|
+
status: z.union([contractStatus, akumaStatus]),
|
|
87
114
|
ls: z.union([
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}),
|
|
96
|
-
verbs.ls.normal.options[2],
|
|
97
|
-
verbs.ls.normal.options[3],
|
|
115
|
+
contractCatalogueSchema.unwrap().omit({ kind: true }),
|
|
116
|
+
akumaCatalogueSchema
|
|
117
|
+
.unwrap()
|
|
118
|
+
.omit({ kind: true, rows: true })
|
|
119
|
+
.extend({ rows: z.array(akumaListRow).exactOptional() }),
|
|
120
|
+
akumaNameCatalogSchema.unwrap().omit({ kind: true }),
|
|
121
|
+
debtListSchema.unwrap().omit({ kind: true }),
|
|
98
122
|
]),
|
|
99
123
|
"debt.add": verbs["debt.add"].normal,
|
|
100
124
|
};
|
|
@@ -117,36 +141,51 @@ function projectPlacement(value) {
|
|
|
117
141
|
}
|
|
118
142
|
function projectStatus(value) {
|
|
119
143
|
if (value.kind === "contract") {
|
|
120
|
-
const {
|
|
121
|
-
return
|
|
122
|
-
...routing,
|
|
123
|
-
holder: typeof holder === "string" ? holder : undefined,
|
|
124
|
-
roster: Array.isArray(roster) ? roster.map(({ id, aliases }) => ({ id, aliases })) : undefined,
|
|
125
|
-
};
|
|
144
|
+
const { kind: _kind, targetObservation: _target, ...routing } = value;
|
|
145
|
+
return routing;
|
|
126
146
|
}
|
|
127
|
-
const {
|
|
147
|
+
const { kind: _kind, contract: association, work: frontier, ...routing } = value;
|
|
128
148
|
const { turn: _turn, activeTools: _tools, latestActivity: _latest, ...work } = frontier;
|
|
129
|
-
return { ...routing, contract: association
|
|
149
|
+
return { ...routing, contract: projectAssociation(association), work };
|
|
150
|
+
}
|
|
151
|
+
function projectAssociation(value) {
|
|
152
|
+
if (value?.kind !== "associated")
|
|
153
|
+
return value;
|
|
154
|
+
const { kind: _kind, ...association } = value;
|
|
155
|
+
return association;
|
|
156
|
+
}
|
|
157
|
+
function projectWait(value) {
|
|
158
|
+
return {
|
|
159
|
+
reason: value.reason,
|
|
160
|
+
members: value.members.map((member) => {
|
|
161
|
+
if (member.kind === "contract") {
|
|
162
|
+
const { presence, summary, ...row } = member.observation;
|
|
163
|
+
return presence === "unknown" ? { id: row.id, unknown: true } : { ...summary, ...row };
|
|
164
|
+
}
|
|
165
|
+
const observation = member.observation;
|
|
166
|
+
if (observation.kind === "unknown")
|
|
167
|
+
return { id: observation.id, unknown: true };
|
|
168
|
+
const { kind: _kind, outcome, ...row } = observation;
|
|
169
|
+
if (outcome === undefined)
|
|
170
|
+
return row;
|
|
171
|
+
const { kind: verdict, historyId: turn, ...answer } = outcome;
|
|
172
|
+
return { ...row, verdict, turn, ...answer };
|
|
173
|
+
}),
|
|
174
|
+
};
|
|
130
175
|
}
|
|
131
176
|
function projectList(value) {
|
|
132
|
-
if (value.kind === "contract-catalogue") {
|
|
133
|
-
const { rows, ...catalogue } = value;
|
|
134
|
-
return {
|
|
135
|
-
...catalogue,
|
|
136
|
-
rows: rows?.map(({ attention, ...row }) => ({ ...row, hasAttention: attention?.length ? true : undefined })),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
177
|
if (value.kind === "akuma-catalogue") {
|
|
140
|
-
const {
|
|
178
|
+
const { kind: _kind, rows, ...catalogue } = value;
|
|
141
179
|
return {
|
|
142
180
|
...catalogue,
|
|
143
181
|
rows: rows?.map(({ contract, ...row }) => ({
|
|
144
182
|
...row,
|
|
145
|
-
contract: contract
|
|
183
|
+
contract: projectAssociation(contract),
|
|
146
184
|
})),
|
|
147
185
|
};
|
|
148
186
|
}
|
|
149
|
-
|
|
187
|
+
const { kind: _kind, ...catalogue } = value;
|
|
188
|
+
return catalogue;
|
|
150
189
|
}
|
|
151
190
|
const projections = {
|
|
152
191
|
bind(value) {
|
|
@@ -185,7 +224,7 @@ const projections = {
|
|
|
185
224
|
const { completedAt: _completedAt, ...settled } = routing;
|
|
186
225
|
return settled;
|
|
187
226
|
},
|
|
188
|
-
wait:
|
|
227
|
+
wait: projectWait,
|
|
189
228
|
status: projectStatus,
|
|
190
229
|
ls: projectList,
|
|
191
230
|
"debt.add": (value) => value,
|
|
@@ -205,7 +244,7 @@ const coordinates = {
|
|
|
205
244
|
.string()
|
|
206
245
|
.regex(/\S/u)
|
|
207
246
|
.exactOptional()
|
|
208
|
-
.describe("
|
|
247
|
+
.describe("Directory to use for this call; relative paths are relative to your current directory. Selects the World."),
|
|
209
248
|
repo: z
|
|
210
249
|
.string()
|
|
211
250
|
.regex(/\S/u)
|
|
@@ -229,46 +268,23 @@ export function modelInputSchema(input, worldOnly = false) {
|
|
|
229
268
|
}
|
|
230
269
|
return input.safeExtend(worldOnly ? { cwd: coordinates.cwd } : coordinates);
|
|
231
270
|
}
|
|
232
|
-
/**
|
|
233
|
-
function
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
typeof
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
"additionalProperties",
|
|
250
|
-
"unevaluatedProperties",
|
|
251
|
-
"not",
|
|
252
|
-
"if",
|
|
253
|
-
"then",
|
|
254
|
-
"else",
|
|
255
|
-
"contains",
|
|
256
|
-
"propertyNames",
|
|
257
|
-
].includes(key) &&
|
|
258
|
-
typeof value === "object" &&
|
|
259
|
-
value !== null) {
|
|
260
|
-
cleaned[key] = cleanSchema(value);
|
|
261
|
-
}
|
|
262
|
-
else
|
|
263
|
-
cleaned[key] = value;
|
|
264
|
-
}
|
|
265
|
-
if (cleaned.anyOf?.every((branch) => typeof branch === "object" && branch.type === "string") &&
|
|
266
|
-
cleaned.anyOf.some((branch) => typeof branch === "object" && Object.keys(branch).length === 1) &&
|
|
267
|
-
(cleaned.type === undefined || cleaned.type === "string")) {
|
|
268
|
-
delete cleaned.anyOf;
|
|
269
|
-
cleaned.type = "string";
|
|
270
|
-
}
|
|
271
|
-
return cleaned;
|
|
271
|
+
/** Zod visits schema positions; authored const/default JSON is not traversed. */
|
|
272
|
+
export function modelJsonSchema(schema) {
|
|
273
|
+
const { $schema: _dialect, ...json } = z.toJSONSchema(schema, {
|
|
274
|
+
io: "input",
|
|
275
|
+
override: ({ jsonSchema }) => {
|
|
276
|
+
delete jsonSchema.$schema;
|
|
277
|
+
if (typeof jsonSchema.readOnly === "boolean")
|
|
278
|
+
delete jsonSchema.readOnly;
|
|
279
|
+
if (jsonSchema.anyOf?.every((branch) => typeof branch === "object" && branch.type === "string") &&
|
|
280
|
+
jsonSchema.anyOf.some((branch) => typeof branch === "object" && Object.keys(branch).length === 1) &&
|
|
281
|
+
(jsonSchema.type === undefined || jsonSchema.type === "string")) {
|
|
282
|
+
delete jsonSchema.anyOf;
|
|
283
|
+
jsonSchema.type = "string";
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
return json;
|
|
272
288
|
}
|
|
273
289
|
function sharedSchema(alternatives) {
|
|
274
290
|
const first = alternatives[0];
|
|
@@ -307,10 +323,9 @@ function sharedSchema(alternatives) {
|
|
|
307
323
|
}
|
|
308
324
|
/** Advertise shared structure; native verb validation owns cross-field admission. */
|
|
309
325
|
export function normalizeModelSchema(schema, input = false) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const { anyOf: branches, ...root } = cleaned;
|
|
326
|
+
if (!input || schema.anyOf === undefined)
|
|
327
|
+
return schema;
|
|
328
|
+
const { anyOf: branches, ...root } = schema;
|
|
314
329
|
if (!branches.every((branch) => typeof branch === "object" && branch.type === "object" && branch.additionalProperties === false))
|
|
315
330
|
throw new Error("MCP input alternatives must be strict objects");
|
|
316
331
|
const objects = branches;
|
|
@@ -331,9 +346,9 @@ export function normalizeModelSchema(schema, input = false) {
|
|
|
331
346
|
export function describeModelTools() {
|
|
332
347
|
const entries = Object.entries(verbs).filter(([name]) => !excluded.has(name));
|
|
333
348
|
return entries.map(([name, entry]) => {
|
|
334
|
-
const schema = normalizeModelSchema(
|
|
349
|
+
const schema = normalizeModelSchema(modelJsonSchema(modelInputSchema(entry.input, NO_REPO_TOOLS.has(name))), true);
|
|
335
350
|
const outputSchema = hasOutputSchema(name)
|
|
336
|
-
? normalizeModelSchema(
|
|
351
|
+
? normalizeModelSchema(modelJsonSchema(modelOutputSchemas[name]))
|
|
337
352
|
: undefined;
|
|
338
353
|
return {
|
|
339
354
|
verb: name,
|
|
@@ -38,15 +38,15 @@ export type AkumaHistoryInput = AkumaAddressInput & Readonly<{
|
|
|
38
38
|
last?: boolean;
|
|
39
39
|
}>;
|
|
40
40
|
export declare const historySelectionSchemas: readonly [...(z.ZodObject<{
|
|
41
|
-
|
|
41
|
+
since: z.ZodNumber;
|
|
42
42
|
limit: z.ZodExactOptional<z.ZodNumber>;
|
|
43
43
|
last: z.ZodExactOptional<z.ZodLiteral<false>>;
|
|
44
44
|
}, z.core.$strict> | z.ZodObject<{
|
|
45
|
-
|
|
45
|
+
before: z.ZodExactOptional<z.ZodNumber>;
|
|
46
|
+
limit: z.ZodExactOptional<z.ZodNumber>;
|
|
46
47
|
last: z.ZodExactOptional<z.ZodLiteral<false>>;
|
|
47
48
|
}, z.core.$strict> | z.ZodObject<{
|
|
48
|
-
|
|
49
|
-
limit: z.ZodExactOptional<z.ZodNumber>;
|
|
49
|
+
id: z.ZodString;
|
|
50
50
|
last: z.ZodExactOptional<z.ZodLiteral<false>>;
|
|
51
51
|
}, z.core.$strict>)[], z.ZodObject<{
|
|
52
52
|
last: z.ZodLiteral<true>;
|
|
@@ -233,9 +233,10 @@ export declare const akumaHistoryResultSchema: z.ZodUnion<readonly [z.ZodReadonl
|
|
|
233
233
|
akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../akuma/identity.js").AkumaId, string>>;
|
|
234
234
|
kind: z.ZodLiteral<"akuma-unknown-history">;
|
|
235
235
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
236
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
236
237
|
answer: z.ZodString;
|
|
237
238
|
akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../akuma/identity.js").AkumaId, string>>;
|
|
238
|
-
kind: z.ZodLiteral<"akuma-
|
|
239
|
+
kind: z.ZodLiteral<"akuma-answer">;
|
|
239
240
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
240
241
|
akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../akuma/identity.js").AkumaId, string>>;
|
|
241
242
|
kind: z.ZodLiteral<"akuma-no-answer">;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @architectureCompositionRoot */
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { akumaIdSchema } from "../akuma/identity.js";
|
|
3
|
+
import { akumaIdSchema, turnHistoryIdSchema } from "../akuma/identity.js";
|
|
4
4
|
import { activityRowSchema, outcomeRowSchema, reportRowSchema } from "../akuma/projection.js";
|
|
5
5
|
import { projectCurrentWork } from "../akuma/status-projection.js";
|
|
6
6
|
import { withoutReportedChanges } from "../akuma/projection.js";
|
|
@@ -45,7 +45,14 @@ export const akumaHistoryResultSchema = z.union([
|
|
|
45
45
|
.extend({ kind: z.literal("akuma-report"), ...historyCommon })
|
|
46
46
|
.readonly(),
|
|
47
47
|
z.strictObject({ kind: z.literal("akuma-unknown-history"), ...historyCommon }).readonly(),
|
|
48
|
-
z
|
|
48
|
+
z
|
|
49
|
+
.strictObject({
|
|
50
|
+
kind: z.literal("akuma-answer"),
|
|
51
|
+
...historyCommon,
|
|
52
|
+
historyId: turnHistoryIdSchema,
|
|
53
|
+
answer: z.string(),
|
|
54
|
+
})
|
|
55
|
+
.readonly(),
|
|
49
56
|
z.strictObject({ kind: z.literal("akuma-no-answer"), ...historyCommon }).readonly(),
|
|
50
57
|
]);
|
|
51
58
|
function observationError(id, error) {
|
|
@@ -301,7 +308,7 @@ export async function historyAkuma(input, reportDiagnostic = stderrPluginDiagnos
|
|
|
301
308
|
if (last === true) {
|
|
302
309
|
const answer = await handle.lastAnswer();
|
|
303
310
|
return answer.kind === "answer"
|
|
304
|
-
? { kind: "akuma-
|
|
311
|
+
? { kind: "akuma-answer", ...subject, answer: answer.answer, historyId: answer.historyId }
|
|
305
312
|
: { kind: "akuma-no-answer", ...subject };
|
|
306
313
|
}
|
|
307
314
|
const history = await handle.history(options);
|
package/build/src/mcp/adapter.js
CHANGED
|
@@ -42,7 +42,7 @@ export function createKeiyakuMcpServer(input) {
|
|
|
42
42
|
});
|
|
43
43
|
if (!parsed.success)
|
|
44
44
|
throw new KeiyakuUsageError(parsed.error.message);
|
|
45
|
-
const facet = Keiyaku.
|
|
45
|
+
const facet = Keiyaku.for({
|
|
46
46
|
cwd: resolve(cwd, parsed.data.cwd ?? "."),
|
|
47
47
|
environment,
|
|
48
48
|
...(!("repo" in parsed.data) || parsed.data.repo === undefined ? {} : { repo: parsed.data.repo }),
|
package/build/src/mcp/help.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MCP_HELP = "keiyaku-mcp \u2014 standalone Keiyaku MCP server over stdio\n\nusage keiyaku-mcp [--help]\n\nEach tool accepts coordinates and business fields as one object. World-only\nDebt mutations and report accept cwd; other tools accept cwd and repo.\nKanshi has no business fields; status requires
|
|
1
|
+
export declare const MCP_HELP = "keiyaku-mcp \u2014 standalone Keiyaku MCP server over stdio\n\nusage keiyaku-mcp [--help]\n\nEach tool accepts coordinates and business fields as one object. World-only\nDebt mutations and report accept cwd; other tools accept cwd and repo.\nKanshi has no business fields; status requires selector (a complete Contract or\nAkuma identity or @name). Unknown fields and incompatible options are usage errors.\nRelative cwd is resolved from the server startup directory; repo independently\nselects the Contract repository. Tool results share\nKeiyaku's CLI text. Nine routing tools publish compact JSON decision facts;\nother tools return text only. Show returns complete unclipped guidance or Debt\ndetail. Native calls and CLI --json retain complete owner answers. Errors return text led by their\nclassification. An unsatisfied verification verdict is a normal answer.\nAdministration and raw import stay on the CLI.\n\nPi uses the shipped Keiyaku extension's native keiyaku_* tools through codemode,\nnot this server. The extension activates codemode when loaded; SDK hosts must\nload codemode themselves. No Keiyaku MCP configuration is needed in Pi.\n\nOther MCP clients can launch the standalone server over stdio, for example:\n\n{\n \"mcpServers\": {\n \"keiyaku\": {\n \"command\": \"keiyaku-mcp\",\n \"exposure\": \"direct\",\n \"timeout\": 600\n }\n }\n}\n\nExposure applies to the whole server where supported by the client. The client timeout is independent of Keiyaku timeout; ask, wait, or verify may need longer.\n";
|
package/build/src/mcp/help.js
CHANGED
|
@@ -4,9 +4,10 @@ usage keiyaku-mcp [--help]
|
|
|
4
4
|
|
|
5
5
|
Each tool accepts coordinates and business fields as one object. World-only
|
|
6
6
|
Debt mutations and report accept cwd; other tools accept cwd and repo.
|
|
7
|
-
Kanshi has no business fields; status requires
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
Kanshi has no business fields; status requires selector (a complete Contract or
|
|
8
|
+
Akuma identity or @name). Unknown fields and incompatible options are usage errors.
|
|
9
|
+
Relative cwd is resolved from the server startup directory; repo independently
|
|
10
|
+
selects the Contract repository. Tool results share
|
|
10
11
|
Keiyaku's CLI text. Nine routing tools publish compact JSON decision facts;
|
|
11
12
|
other tools return text only. Show returns complete unclipped guidance or Debt
|
|
12
13
|
detail. Native calls and CLI --json retain complete owner answers. Errors return text led by their
|
package/build/src/pi/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
/** Register the shipped presentation and native tools without exposing execution internals. */
|
|
3
|
+
export declare function registerKeiyakuExtension(pi: ExtensionAPI): void;
|
|
2
4
|
/** Register the native codemode integration; execution remains on the invocation facet. */
|
|
3
5
|
export declare function registerKeiyakuTools(pi: ExtensionAPI): void;
|
package/build/src/pi/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
+
import { harnessOwner } from "@astrosheep/square";
|
|
3
|
+
import { registerKeiyakuStatus } from "./status.js";
|
|
2
4
|
import { Keiyaku, KeiyakuUsageError } from "../library/keiyaku.js";
|
|
3
5
|
import { classifyVerb, } from "../library/keiyaku-verbs.js";
|
|
4
6
|
import { describeModelTools, hasOutputSchema, modelCoordinates, projectModelOutput } from "../library/model-tools.js";
|
|
@@ -6,6 +8,21 @@ import { projectFailure } from "../library/outcome.js";
|
|
|
6
8
|
import { renderVerb } from "../cli/render/verbs.js";
|
|
7
9
|
import { DEFAULT_CLI_COLUMNS } from "../cli/render/terminal.js";
|
|
8
10
|
import { SERVER_DESCRIPTION } from "../mcp/description.js";
|
|
11
|
+
function invocationContext(ctx) {
|
|
12
|
+
const environment = Object.freeze({ ...process.env });
|
|
13
|
+
const home = environment.KEIYAKU_HOME?.trim() || undefined;
|
|
14
|
+
return {
|
|
15
|
+
cwd: ctx.cwd,
|
|
16
|
+
environment,
|
|
17
|
+
identity: { owner: harnessOwner({ channel: "pi", session: ctx.sessionManager.getSessionId() }) },
|
|
18
|
+
...(home === undefined ? {} : { home }),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Register the shipped presentation and native tools without exposing execution internals. */
|
|
22
|
+
export function registerKeiyakuExtension(pi) {
|
|
23
|
+
registerKeiyakuTools(pi);
|
|
24
|
+
registerKeiyakuStatus(pi, invocationContext);
|
|
25
|
+
}
|
|
9
26
|
/** Register the native codemode integration; execution remains on the invocation facet. */
|
|
10
27
|
export function registerKeiyakuTools(pi) {
|
|
11
28
|
const namespace = { name: "keiyaku", description: SERVER_DESCRIPTION, instructions: SERVER_DESCRIPTION };
|
|
@@ -23,8 +40,7 @@ export function registerKeiyakuTools(pi) {
|
|
|
23
40
|
async execute(_id, args, signal, _onUpdate, ctx) {
|
|
24
41
|
const { cwd, repo, ...business } = args;
|
|
25
42
|
const value = business;
|
|
26
|
-
|
|
27
|
-
const home = environment.KEIYAKU_HOME?.trim() || undefined;
|
|
43
|
+
let environment = {};
|
|
28
44
|
let completion;
|
|
29
45
|
try {
|
|
30
46
|
const parsed = modelCoordinates(name).safeParse({
|
|
@@ -33,12 +49,12 @@ export function registerKeiyakuTools(pi) {
|
|
|
33
49
|
});
|
|
34
50
|
if (!parsed.success)
|
|
35
51
|
throw new KeiyakuUsageError(parsed.error.message);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
const invocation = invocationContext(ctx);
|
|
53
|
+
environment = invocation.environment;
|
|
54
|
+
const facet = Keiyaku.for({
|
|
55
|
+
...invocation,
|
|
56
|
+
cwd: resolve(invocation.cwd, parsed.data.cwd ?? "."),
|
|
40
57
|
...(!("repo" in parsed.data) || parsed.data.repo === undefined ? {} : { repo: parsed.data.repo }),
|
|
41
|
-
...(home === undefined ? {} : { home }),
|
|
42
58
|
});
|
|
43
59
|
completion = {
|
|
44
60
|
kind: "returned",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Kanshi } from "../kanshi/index.js";
|
|
3
|
+
import { Repo } from "../library/repo.js";
|
|
4
|
+
import { World } from "../world.js";
|
|
5
|
+
import type { KeiyakuFor } from "../library/keiyaku.js";
|
|
6
|
+
type StatusReaders = {
|
|
7
|
+
repo: typeof Repo.at;
|
|
8
|
+
world: typeof World.resolve;
|
|
9
|
+
counts: (scope: Parameters<typeof Kanshi.of>[0], options: Parameters<Kanshi["counts"]>[0]) => ReturnType<Kanshi["counts"]>;
|
|
10
|
+
};
|
|
11
|
+
export declare function registerKeiyakuStatus(pi: ExtensionAPI, capture: (ctx: ExtensionContext) => KeiyakuFor, readers?: StatusReaders): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Kanshi } from "../kanshi/index.js";
|
|
2
|
+
import { NoGitWorldError, Repo } from "../library/repo.js";
|
|
3
|
+
import { World } from "../world.js";
|
|
4
|
+
import { akumaCallerFromEnvironment } from "../library/keiyaku-identity.js";
|
|
5
|
+
function lineForWidth(value, width) {
|
|
6
|
+
const clean = value.replaceAll(/[\u0000-\u001f\u007f]/gu, " ");
|
|
7
|
+
return clean.length <= width ? clean : `${clean.slice(0, Math.max(0, width - 1))}…`;
|
|
8
|
+
}
|
|
9
|
+
function overlay(lines, theme, done) {
|
|
10
|
+
return {
|
|
11
|
+
invalidate() { },
|
|
12
|
+
handleInput(data) {
|
|
13
|
+
if (data === "\u001b" || data === "q" || data === "Q" || data === "\r")
|
|
14
|
+
done();
|
|
15
|
+
},
|
|
16
|
+
render(width) {
|
|
17
|
+
const inner = Math.max(1, Math.min(100, width - 2));
|
|
18
|
+
const border = theme.fg("border", "+");
|
|
19
|
+
const rule = theme.fg("border", "-".repeat(inner));
|
|
20
|
+
return [
|
|
21
|
+
`${border}${rule}${border}`,
|
|
22
|
+
`${theme.fg("border", "|")}${lineForWidth("Keiyaku", inner).padEnd(inner)}${theme.fg("border", "|")}`,
|
|
23
|
+
`${theme.fg("border", "|")}${" ".repeat(inner)}${theme.fg("border", "|")}`,
|
|
24
|
+
...lines.map((line) => `${theme.fg("border", "|")}${lineForWidth(line, inner).padEnd(inner)}${theme.fg("border", "|")}`),
|
|
25
|
+
`${theme.fg("border", "|")}${" ".repeat(inner)}${theme.fg("border", "|")}`,
|
|
26
|
+
`${theme.fg("border", "|")}${lineForWidth("esc/q/enter close", inner).padEnd(inner)}${theme.fg("border", "|")}`,
|
|
27
|
+
`${border}${rule}${border}`,
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const countValue = (section) => section.kind === "present" ? String(section.value) : section.kind === "absent" ? "-" : "?";
|
|
33
|
+
const defaultReaders = {
|
|
34
|
+
repo: Repo.at,
|
|
35
|
+
world: World.resolve,
|
|
36
|
+
counts: (scope, options) => Kanshi.of(scope).counts(options),
|
|
37
|
+
};
|
|
38
|
+
export function registerKeiyakuStatus(pi, capture, readers = defaultReaders) {
|
|
39
|
+
let close;
|
|
40
|
+
let refresh;
|
|
41
|
+
pi.on("session_start", (_event, ctx) => {
|
|
42
|
+
close?.();
|
|
43
|
+
close = undefined;
|
|
44
|
+
refresh = undefined;
|
|
45
|
+
if (ctx.mode !== "tui")
|
|
46
|
+
return;
|
|
47
|
+
const cwd = ctx.cwd;
|
|
48
|
+
const caller = (async () => {
|
|
49
|
+
const context = capture(ctx);
|
|
50
|
+
return akumaCallerFromEnvironment(context.environment, context.identity?.owner);
|
|
51
|
+
})().catch(() => null);
|
|
52
|
+
const ui = ctx.ui;
|
|
53
|
+
let live = true;
|
|
54
|
+
let reading = false;
|
|
55
|
+
let pending = false;
|
|
56
|
+
let timer;
|
|
57
|
+
const unknown = "aku ? · kei ? · debt ?";
|
|
58
|
+
const show = (text) => ui.setStatus("keiyaku", text);
|
|
59
|
+
const sample = async () => {
|
|
60
|
+
let repo;
|
|
61
|
+
try {
|
|
62
|
+
repo = await readers.repo({ path: cwd });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (!(error instanceof NoGitWorldError))
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
const world = await readers.world(repo === undefined ? { cwd } : { cwd, repositoryRoot: repo.root });
|
|
69
|
+
const report = await readers.counts({ world: world.root, ...(repo === undefined ? {} : { repo }) }, { akumaCaller: (await caller) ?? null });
|
|
70
|
+
return `aku ${countValue(report.akuma)} · kei ${countValue(report.contracts)} · debt ${countValue(report.debts)}`;
|
|
71
|
+
};
|
|
72
|
+
const request = () => {
|
|
73
|
+
if (!live)
|
|
74
|
+
return;
|
|
75
|
+
if (timer !== undefined)
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
timer = undefined;
|
|
78
|
+
if (reading) {
|
|
79
|
+
pending = true;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
reading = true;
|
|
83
|
+
void sample()
|
|
84
|
+
.catch(() => unknown)
|
|
85
|
+
.then((text) => {
|
|
86
|
+
if (!live)
|
|
87
|
+
return;
|
|
88
|
+
show(text);
|
|
89
|
+
reading = false;
|
|
90
|
+
if (pending) {
|
|
91
|
+
pending = false;
|
|
92
|
+
request();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
timer = setTimeout(request, 5_000);
|
|
96
|
+
timer.unref();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
close = () => {
|
|
101
|
+
if (!live)
|
|
102
|
+
return;
|
|
103
|
+
live = false;
|
|
104
|
+
if (timer !== undefined)
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
show(undefined);
|
|
107
|
+
};
|
|
108
|
+
refresh = request;
|
|
109
|
+
show(unknown);
|
|
110
|
+
request();
|
|
111
|
+
});
|
|
112
|
+
pi.on("agent_settled", () => refresh?.());
|
|
113
|
+
pi.on("session_shutdown", () => {
|
|
114
|
+
close?.();
|
|
115
|
+
close = undefined;
|
|
116
|
+
refresh = undefined;
|
|
117
|
+
});
|
|
118
|
+
registerBoardCommand(pi);
|
|
119
|
+
}
|
|
120
|
+
function registerBoardCommand(pi) {
|
|
121
|
+
pi.registerCommand("keiyaku", {
|
|
122
|
+
description: "Open the Kanshi world status",
|
|
123
|
+
handler: async (_args, ctx) => {
|
|
124
|
+
if (!ctx.hasUI)
|
|
125
|
+
return;
|
|
126
|
+
let body;
|
|
127
|
+
try {
|
|
128
|
+
const result = await pi.exec("keiyaku", ["kanshi"]);
|
|
129
|
+
body = result.code === 0 ? result.stdout.trimEnd().split("\n") : [result.stderr.trim() || "status unavailable"];
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
body = ["status unavailable"];
|
|
133
|
+
}
|
|
134
|
+
await ctx.ui.custom((_tui, theme, _keybindings, done) => overlay(body, theme, done), {
|
|
135
|
+
overlay: true,
|
|
136
|
+
overlayOptions: { anchor: "center", width: 100, maxHeight: 40 },
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type LifecycleSelection } from "../bounded-list.js";
|
|
2
3
|
import type { DecideInput, OfferDecision } from "../core/decide.js";
|
|
3
4
|
import type { ContractId, ContractState, DeliverData, DocumentKey } from "../core/facts/types.js";
|
|
4
5
|
export { deliverDataSchema, gateSchema, verdictSchema, candidateContentChangeSchema, gateCurrentSchema, requirementIdSchema, requirementReportSchema, gateReportSchema, } from "./result-leaves.js";
|
|
@@ -674,6 +675,7 @@ export declare function contractsOperation(input: Readonly<{
|
|
|
674
675
|
export declare function contractCatalogueOperation(input: Readonly<{
|
|
675
676
|
scope: RepositoryScope;
|
|
676
677
|
channel: GitDecodeChannel;
|
|
678
|
+
selection?: LifecycleSelection;
|
|
677
679
|
limit?: number;
|
|
678
680
|
}>): Promise<ContractCatalogue>;
|
|
679
681
|
export declare function contractObservationOperation(input: Readonly<{
|
|
@@ -234,7 +234,7 @@ export async function contractsOperation(input) {
|
|
|
234
234
|
}
|
|
235
235
|
export async function contractCatalogueOperation(input) {
|
|
236
236
|
const limit = input.limit === undefined ? undefined : boundedListLimit(input.limit);
|
|
237
|
-
return withGitReadObservation(input.scope, input.channel, (observation) => readContractCatalogue(observation, limit));
|
|
237
|
+
return withGitReadObservation(input.scope, input.channel, (observation) => readContractCatalogue(observation, limit, input.selection));
|
|
238
238
|
}
|
|
239
239
|
export async function contractObservationOperation(input) {
|
|
240
240
|
return await readContractObservationAt(input.scope, input.channel, input.contractId);
|