wendkeep 0.80.2 → 0.85.1

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 (75) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.en.md +28 -11
  3. package/README.md +28 -11
  4. package/docs/en/commands/capabilities.md +82 -0
  5. package/docs/en/commands/getting-started.md +3 -1
  6. package/docs/en/commands/mcp.md +99 -0
  7. package/docs/en/commands/portable.md +88 -0
  8. package/docs/en/commands/sync-protocol.md +58 -0
  9. package/docs/en/commands/tdd.md +96 -0
  10. package/docs/en/commands/verify.md +5 -0
  11. package/docs/pt-BR/commands/capabilities.md +82 -0
  12. package/docs/pt-BR/commands/getting-started.md +3 -2
  13. package/docs/pt-BR/commands/mcp.md +99 -0
  14. package/docs/pt-BR/commands/portable.md +87 -0
  15. package/docs/pt-BR/commands/sync-protocol.md +58 -0
  16. package/docs/pt-BR/commands/tdd.md +96 -0
  17. package/docs/pt-BR/commands/verify.md +5 -0
  18. package/hooks/active-context-store.mjs +2 -0
  19. package/hooks/change-core.mjs +5 -0
  20. package/hooks/project-scope.mjs +2 -1
  21. package/hooks/session-ensure.mjs +23 -7
  22. package/hooks/session-start.mjs +20 -5
  23. package/package.json +3 -3
  24. package/packages/cli/src/index.mjs +42 -2
  25. package/packages/harness/src/sensors-core.mjs +16 -3
  26. package/packages/integrations/src/capabilities.mjs +220 -0
  27. package/packages/integrations/src/index.mjs +1 -0
  28. package/packages/mcp/src/audit.mjs +49 -0
  29. package/packages/mcp/src/cli.mjs +78 -0
  30. package/packages/mcp/src/config.mjs +22 -1
  31. package/packages/mcp/src/effects.mjs +115 -0
  32. package/packages/mcp/src/executor.mjs +354 -0
  33. package/packages/mcp/src/index.mjs +7 -0
  34. package/packages/mcp/src/server.mjs +342 -0
  35. package/packages/mcp/src/stdio.mjs +38 -0
  36. package/packages/mcp/src/sync.mjs +56 -0
  37. package/packages/pi/package.json +2 -1
  38. package/packages/pi/src/index.mjs +29 -0
  39. package/schema/handoff-contract-v1.schema.json +4 -0
  40. package/schema/host-capability-manifest-v1.schema.json +46 -0
  41. package/schema/host-coverage-v1.schema.json +55 -0
  42. package/schema/mcp-effect-manifest-v1.schema.json +36 -0
  43. package/schema/mcp-tool-input-v1.schema.json +32 -0
  44. package/schema/mcp-tool-result-v1.schema.json +22 -0
  45. package/schema/portable-active-work-v1.schema.json +38 -0
  46. package/schema/portable-state-v1.schema.json +36 -0
  47. package/schema/sync-event-v1.schema.json +25 -0
  48. package/schema/sync-private-envelope-v1.schema.json +16 -0
  49. package/schema/sync-state-v1.schema.json +18 -0
  50. package/schema/task-contract-v1.schema.json +2 -0
  51. package/schema/tdd-attestation-v1.schema.json +39 -0
  52. package/schema/wendkeep.evidence-envelope-v2.schema.json +17 -0
  53. package/schema/wendkeep.sensors.schema.json +19 -0
  54. package/src/active-context-runtime.mjs +1 -0
  55. package/src/capabilities.mjs +50 -0
  56. package/src/doctor.mjs +28 -0
  57. package/src/evidence-envelope.mjs +12 -6
  58. package/src/host-capabilities.mjs +34 -0
  59. package/src/init.mjs +3 -3
  60. package/src/mcp.mjs +7 -0
  61. package/src/observer-snapshot.mjs +25 -0
  62. package/src/portable.mjs +558 -0
  63. package/src/skills-seed.mjs +26 -0
  64. package/src/sync-adapters.mjs +188 -0
  65. package/src/sync-outbox.mjs +155 -0
  66. package/src/sync-protocol-cli.mjs +277 -0
  67. package/src/sync-protocol.mjs +368 -0
  68. package/src/sync.mjs +8 -0
  69. package/src/task-contracts.mjs +67 -2
  70. package/src/task.mjs +5 -1
  71. package/src/tdd-attestation-store.mjs +98 -0
  72. package/src/tdd-attestation.mjs +254 -0
  73. package/src/tdd.mjs +198 -0
  74. package/src/vault-readme.mjs +4 -4
  75. package/src/verify.mjs +24 -0
@@ -0,0 +1,342 @@
1
+ import { MCP_EFFECT_MANIFEST, resolveMcpToolEffect } from './effects.mjs';
2
+
3
+ const DEFAULT_PAGE_SIZE = 50;
4
+ const MAX_PAGE_SIZE = 100;
5
+ const DEFAULT_TIMEOUT_MS = 10_000;
6
+
7
+ function boundedInteger(value, fallback, maximum = MAX_PAGE_SIZE) {
8
+ const parsed = Number.parseInt(value, 10);
9
+ if (!Number.isInteger(parsed) || parsed < 1) return fallback;
10
+ return Math.min(parsed, maximum);
11
+ }
12
+
13
+ function cursorFor(offset) {
14
+ return Buffer.from(JSON.stringify({ v: 1, offset }), 'utf8').toString('base64url');
15
+ }
16
+
17
+ function cursorOffset(value) {
18
+ if (!value) return 0;
19
+ try {
20
+ const parsed = JSON.parse(Buffer.from(String(value), 'base64url').toString('utf8'));
21
+ return parsed?.v === 1 && Number.isInteger(parsed.offset) && parsed.offset >= 0
22
+ ? parsed.offset
23
+ : 0;
24
+ } catch { return 0; }
25
+ }
26
+
27
+ function supportsObserverSql(nodeVersion) {
28
+ const [major = 0, minor = 0] = String(nodeVersion || '').split('.').map(Number);
29
+ return major > 22 || (major === 22 && minor >= 13);
30
+ }
31
+
32
+ function availability(tool, nodeVersion) {
33
+ if (tool.name !== 'wendkeep_observer_query' || supportsObserverSql(nodeVersion)) {
34
+ return { available: true };
35
+ }
36
+ return {
37
+ available: false,
38
+ code: 'MCP_RUNTIME_UNSUPPORTED',
39
+ requires: 'node>=22.13.0',
40
+ };
41
+ }
42
+
43
+ const TOOL_REQUIRED_ARGUMENTS = Object.freeze({
44
+ wendkeep_context_status: ['session_id'],
45
+ wendkeep_change_show: ['change'],
46
+ wendkeep_change_status: ['change'],
47
+ wendkeep_task_show: ['session_id', 'task'],
48
+ wendkeep_task_evaluate: ['session_id', 'task'],
49
+ wendkeep_handoff_current: ['session_id'],
50
+ wendkeep_evidence_latest: ['change'],
51
+ wendkeep_memory_assert: ['payload'],
52
+ wendkeep_context_select: ['payload'],
53
+ wendkeep_task_claim: ['task'],
54
+ wendkeep_task_complete: ['task'],
55
+ wendkeep_handoff_publish: ['payload'],
56
+ });
57
+
58
+ function inputSchema(tool) {
59
+ const required = ['project_root'];
60
+ required.push(...(TOOL_REQUIRED_ARGUMENTS[tool.name] || []));
61
+ if (tool.effect === 'write') {
62
+ required.push('session_id', 'active_context_id', 'actor', 'reason', 'capabilities', 'lease');
63
+ }
64
+ return {
65
+ type: 'object',
66
+ additionalProperties: false,
67
+ required,
68
+ properties: {
69
+ project_root: { type: 'string', minLength: 1 },
70
+ worktree_root: { type: 'string', minLength: 1 },
71
+ session_id: { type: 'string', minLength: 1 },
72
+ active_context_id: { type: 'string', minLength: 1 },
73
+ actor: { type: 'string', minLength: 1 },
74
+ reason: { type: 'string', minLength: 1, maxLength: 500 },
75
+ capabilities: { type: 'array', items: { type: 'string' }, uniqueItems: true },
76
+ lease: {
77
+ type: 'object',
78
+ additionalProperties: false,
79
+ required: ['id', 'expires_at'],
80
+ properties: {
81
+ id: { type: 'string', minLength: 1 },
82
+ expires_at: { type: 'string', format: 'date-time' },
83
+ },
84
+ },
85
+ change: { type: 'string' },
86
+ task: { type: 'string' },
87
+ query: { type: 'string' },
88
+ cursor: { type: 'string' },
89
+ limit: { type: 'integer', minimum: 1, maximum: MAX_PAGE_SIZE },
90
+ payload: { type: 'object' },
91
+ },
92
+ };
93
+ }
94
+
95
+ function toolDescriptor(tool, nodeVersion) {
96
+ return {
97
+ name: tool.name,
98
+ description: `${tool.capability} (${tool.effect}, effect v${tool.effect_version})`,
99
+ inputSchema: inputSchema(tool),
100
+ outputSchema: {
101
+ type: 'object',
102
+ required: ['schema_version'],
103
+ properties: { schema_version: { const: 1 } },
104
+ },
105
+ annotations: {
106
+ readOnlyHint: tool.effect === 'read',
107
+ destructiveHint: tool.effect === 'destructive',
108
+ idempotentHint: tool.effect === 'read',
109
+ openWorldHint: false,
110
+ },
111
+ _meta: {
112
+ 'wendkeep/effect': {
113
+ catalog_version: MCP_EFFECT_MANIFEST.catalog_version,
114
+ effect: tool.effect,
115
+ effect_version: tool.effect_version,
116
+ capability: tool.capability,
117
+ input_schema: tool.input_schema,
118
+ output_schema: tool.output_schema,
119
+ manifest_integrity: MCP_EFFECT_MANIFEST.integrity,
120
+ },
121
+ availability: availability(tool, nodeVersion),
122
+ },
123
+ };
124
+ }
125
+
126
+ function sanitizeMessage(value) {
127
+ return String(value || 'MCP tool failed')
128
+ .replace(/\bgh[pousr]_[A-Za-z0-9_]{12,}\b/g, '[REDACTED_SECRET]')
129
+ .replace(/\b[A-Za-z]:\\[^\s)'"\r\n]+/g, '[LOCAL_PATH]')
130
+ .replace(/\/[Uu]sers\/[^/\s]+\/[^\s)'"\r\n]+/g, '[LOCAL_PATH]')
131
+ .replace(/\s+/g, ' ')
132
+ .trim()
133
+ .slice(0, 500);
134
+ }
135
+
136
+ function toolError(code, message, { retryable = false } = {}) {
137
+ const structuredContent = {
138
+ schema_version: 1,
139
+ error: { code, message: sanitizeMessage(message), retryable },
140
+ };
141
+ return {
142
+ isError: true,
143
+ content: [{ type: 'text', text: JSON.stringify(structuredContent) }],
144
+ structuredContent,
145
+ };
146
+ }
147
+
148
+ function toolSuccess(value, {
149
+ cursor = '', limit = DEFAULT_PAGE_SIZE, maxResponseBytes = 1_048_576,
150
+ } = {}) {
151
+ let structuredContent = value;
152
+ if (Array.isArray(value)) {
153
+ const offset = cursorOffset(cursor);
154
+ const pageSize = boundedInteger(limit, DEFAULT_PAGE_SIZE);
155
+ const items = value.slice(offset, offset + pageSize);
156
+ do {
157
+ structuredContent = {
158
+ schema_version: 1,
159
+ items,
160
+ ...(offset + items.length < value.length ? { next_cursor: cursorFor(offset + items.length) } : {}),
161
+ };
162
+ if (Buffer.byteLength(JSON.stringify(structuredContent), 'utf8') <= maxResponseBytes) break;
163
+ items.pop();
164
+ } while (items.length);
165
+ if (!items.length && offset < value.length) {
166
+ return toolError('MCP_RESPONSE_TOO_LARGE', 'one result item exceeds the configured byte budget');
167
+ }
168
+ } else {
169
+ structuredContent = value && typeof value === 'object'
170
+ ? { ...value, schema_version: 1 }
171
+ : { schema_version: 1, value };
172
+ if (Buffer.byteLength(JSON.stringify(structuredContent), 'utf8') > maxResponseBytes) {
173
+ return toolError('MCP_RESPONSE_TOO_LARGE', 'tool result exceeds the configured byte budget');
174
+ }
175
+ }
176
+ return {
177
+ isError: false,
178
+ content: [{ type: 'text', text: JSON.stringify(structuredContent) }],
179
+ structuredContent,
180
+ };
181
+ }
182
+
183
+ function validateArguments(tool, args, now = Date.now()) {
184
+ if (!args || typeof args !== 'object' || Array.isArray(args)) return 'MCP_ARGUMENTS_INVALID';
185
+ if (!String(args.project_root || '').trim()) return 'MCP_PROJECT_REQUIRED';
186
+ for (const field of TOOL_REQUIRED_ARGUMENTS[tool.name] || []) {
187
+ if (!String(args[field] || '').trim()) return 'MCP_ARGUMENT_REQUIRED';
188
+ }
189
+ if (tool.effect !== 'write') return '';
190
+ if (!Array.isArray(args.capabilities) || !args.capabilities.includes(tool.capability)) {
191
+ return 'MCP_CAPABILITY_REQUIRED';
192
+ }
193
+ if (!String(args.session_id || '').trim()
194
+ || !String(args.active_context_id || '').trim()
195
+ || !String(args.actor || '').trim()
196
+ || !String(args.reason || '').trim()
197
+ || !String(args.lease?.id || '').trim()
198
+ || !String(args.lease?.expires_at || '').trim()) return 'MCP_WRITE_CONTEXT_REQUIRED';
199
+ const expiresAt = Date.parse(args.lease.expires_at);
200
+ if (!Number.isFinite(expiresAt)) return 'MCP_LEASE_INVALID';
201
+ if (expiresAt <= now) return 'MCP_LEASE_EXPIRED';
202
+ return '';
203
+ }
204
+
205
+ function withControl(operation, timeoutMs, controller) {
206
+ let timer;
207
+ let onAbort;
208
+ const { signal } = controller;
209
+ timer = setTimeout(() => controller.abort(Object.assign(new Error('tool call timed out'), {
210
+ code: 'MCP_TOOL_TIMEOUT',
211
+ })), timeoutMs);
212
+ return Promise.race([
213
+ operation,
214
+ new Promise((_, reject) => {
215
+ onAbort = () => {
216
+ const reason = signal.reason;
217
+ reject(typeof reason?.code === 'string' && reason.code.startsWith('MCP_')
218
+ ? reason
219
+ : Object.assign(new Error('tool call cancelled'), {
220
+ code: 'MCP_TOOL_CANCELLED',
221
+ }));
222
+ };
223
+ signal.addEventListener('abort', onAbort, { once: true });
224
+ }),
225
+ ]).finally(() => {
226
+ clearTimeout(timer);
227
+ signal.removeEventListener('abort', onAbort);
228
+ });
229
+ }
230
+
231
+ export function createNativeMcpServer({
232
+ executeTool = async () => ({}),
233
+ nodeVersion = process.versions.node,
234
+ defaultPageSize = DEFAULT_PAGE_SIZE,
235
+ timeoutMs = DEFAULT_TIMEOUT_MS,
236
+ serverVersion = '1',
237
+ manifest = MCP_EFFECT_MANIFEST,
238
+ maxRequestBytes = 1_048_576,
239
+ maxResponseBytes = 1_048_576,
240
+ now = () => Date.now(),
241
+ auditToolCall = async () => {},
242
+ } = {}) {
243
+ const pending = new Map();
244
+
245
+ async function callTool(params = {}, requestId = null) {
246
+ const startedAt = performance.now();
247
+ const effect = resolveMcpToolEffect(params.name, { manifest });
248
+ const finish = async (result, tool = null) => {
249
+ const errorCode = result?.structuredContent?.error?.code || '';
250
+ try {
251
+ await auditToolCall({
252
+ tool: tool?.name || String(params.name || '').slice(0, 120),
253
+ effect: tool?.effect || effect.effect,
254
+ capability: tool?.capability || effect.capability,
255
+ outcome: result?.isError ? 'error' : 'success',
256
+ error_code: errorCode,
257
+ duration_ms: Math.max(0, Math.round(performance.now() - startedAt)),
258
+ }, { projectRoot: String(params.arguments?.project_root || '') });
259
+ } catch { /* audit failures must not corrupt protocol responses */ }
260
+ return result;
261
+ };
262
+ if (!effect.known) {
263
+ return finish(toolError('MCP_TOOL_UNKNOWN', 'tool is absent from the verified effect catalog'));
264
+ }
265
+ const tool = manifest.tools.find((candidate) => candidate.name === effect.name);
266
+ const available = availability(tool, nodeVersion);
267
+ if (!available.available) {
268
+ return finish(toolError(available.code, `${tool.name} requires ${available.requires}`), tool);
269
+ }
270
+ const args = params.arguments || {};
271
+ if (Buffer.byteLength(JSON.stringify({ name: params.name, arguments: args }), 'utf8') > maxRequestBytes) {
272
+ return finish(toolError('MCP_REQUEST_TOO_LARGE', 'tool request exceeds the configured byte budget'), tool);
273
+ }
274
+ const validationCode = validateArguments(tool, args, now());
275
+ if (validationCode) return finish(toolError(validationCode, `invalid arguments for ${tool.name}`), tool);
276
+ const controller = new AbortController();
277
+ if (requestId !== null && requestId !== undefined) pending.set(requestId, controller);
278
+ try {
279
+ const value = await withControl(
280
+ Promise.resolve(executeTool(tool, args, { signal: controller.signal })),
281
+ boundedInteger(timeoutMs, DEFAULT_TIMEOUT_MS, 120_000),
282
+ controller,
283
+ );
284
+ return finish(toolSuccess(value, {
285
+ cursor: args.cursor,
286
+ limit: boundedInteger(args.limit, defaultPageSize),
287
+ maxResponseBytes,
288
+ }), tool);
289
+ } catch (error) {
290
+ return finish(toolError(error?.code || 'MCP_TOOL_FAILED', error?.message || error, {
291
+ retryable: error?.code === 'MCP_TOOL_TIMEOUT',
292
+ }), tool);
293
+ } finally {
294
+ if (requestId !== null && requestId !== undefined) pending.delete(requestId);
295
+ }
296
+ }
297
+
298
+ return {
299
+ async handle(message = {}) {
300
+ const id = message.id;
301
+ if (message.jsonrpc !== '2.0') {
302
+ return { jsonrpc: '2.0', id: id ?? null, error: { code: -32600, message: 'Invalid Request' } };
303
+ }
304
+ if (message.method === 'initialize') {
305
+ return {
306
+ jsonrpc: '2.0', id,
307
+ result: {
308
+ protocolVersion: message.params?.protocolVersion || '2025-06-18',
309
+ capabilities: { tools: { listChanged: false } },
310
+ serverInfo: { name: 'wendkeep-native', version: serverVersion },
311
+ },
312
+ };
313
+ }
314
+ if (message.method === 'notifications/initialized') {
315
+ return null;
316
+ }
317
+ if (message.method === 'notifications/cancelled') {
318
+ pending.get(message.params?.requestId)?.abort();
319
+ return null;
320
+ }
321
+ if (message.method === 'tools/list') {
322
+ const offset = cursorOffset(message.params?.cursor);
323
+ const pageSize = boundedInteger(message.params?.limit, defaultPageSize);
324
+ const descriptors = manifest.tools.map((tool) => toolDescriptor(tool, nodeVersion));
325
+ const tools = descriptors.slice(offset, offset + pageSize);
326
+ return {
327
+ jsonrpc: '2.0', id,
328
+ result: {
329
+ tools,
330
+ ...(offset + tools.length < descriptors.length ? { nextCursor: cursorFor(offset + tools.length) } : {}),
331
+ },
332
+ };
333
+ }
334
+ if (message.method === 'tools/call') {
335
+ return { jsonrpc: '2.0', id, result: await callTool(message.params, id) };
336
+ }
337
+ return { jsonrpc: '2.0', id: id ?? null, error: { code: -32601, message: 'Method not found' } };
338
+ },
339
+ };
340
+ }
341
+
342
+ export { supportsObserverSql };
@@ -0,0 +1,38 @@
1
+ import { createInterface } from 'node:readline';
2
+
3
+ export async function runNativeMcpStdio({
4
+ input = process.stdin,
5
+ output = process.stdout,
6
+ server,
7
+ } = {}) {
8
+ if (!server || typeof server.handle !== 'function') {
9
+ throw new TypeError('runNativeMcpStdio requires a server');
10
+ }
11
+ const pending = new Set();
12
+ const lines = createInterface({ input, crlfDelay: Infinity, terminal: false });
13
+ for await (const line of lines) {
14
+ if (!line.trim()) continue;
15
+ let message;
16
+ try { message = JSON.parse(line); }
17
+ catch {
18
+ output.write(`${JSON.stringify({
19
+ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' },
20
+ })}\n`);
21
+ continue;
22
+ }
23
+ const operation = Promise.resolve(server.handle(message))
24
+ .then((response) => {
25
+ if (response) output.write(`${JSON.stringify(response)}\n`);
26
+ })
27
+ .catch(() => {
28
+ if (message.id !== undefined) {
29
+ output.write(`${JSON.stringify({
30
+ jsonrpc: '2.0', id: message.id, error: { code: -32603, message: 'Internal error' },
31
+ })}\n`);
32
+ }
33
+ })
34
+ .finally(() => pending.delete(operation));
35
+ pending.add(operation);
36
+ }
37
+ await Promise.all(pending);
38
+ }
@@ -0,0 +1,56 @@
1
+ export const SYNC_MCP_TOOL_DEFINITIONS = [
2
+ {
3
+ name: 'wendkeep_sync_status',
4
+ description: 'Read local-first sync health, pending count, and explicit conflict count.',
5
+ effect: 'read',
6
+ },
7
+ {
8
+ name: 'wendkeep_sync_conflicts',
9
+ description: 'List explicit sync conflict candidates without returning authored payloads.',
10
+ effect: 'read',
11
+ },
12
+ ];
13
+
14
+ function publicCandidate(candidate) {
15
+ return {
16
+ event_id: String(candidate?.event_id || ''),
17
+ revision: Number(candidate?.revision || 0),
18
+ content_hash: String(candidate?.content_hash || ''),
19
+ actor_id: String(candidate?.actor_id || ''),
20
+ device_id: String(candidate?.device_id || ''),
21
+ observed_at: String(candidate?.observed_at || ''),
22
+ operation: String(candidate?.operation || ''),
23
+ privacy: String(candidate?.privacy || ''),
24
+ };
25
+ }
26
+
27
+ export function inspectSyncForMcp({ outbox, state = null } = {}) {
28
+ const safeOutbox = outbox && typeof outbox === 'object'
29
+ ? {
30
+ status: String(outbox.status || 'corrupt'),
31
+ events: Number(outbox.events || 0),
32
+ pending: Number(outbox.pending || 0),
33
+ acknowledged: Number(outbox.acknowledged || 0),
34
+ ...(outbox.code ? { code: String(outbox.code) } : {}),
35
+ }
36
+ : { status: 'corrupt', events: 0, pending: 0, acknowledged: 0, code: 'WENDKEEP_SYNC_STATE_UNAVAILABLE' };
37
+ if (safeOutbox.status === 'disabled') return { enabled: false, outbox: safeOutbox, conflicts: 0 };
38
+ if (!state || typeof state !== 'object') return {
39
+ enabled: true,
40
+ outbox: { ...safeOutbox, status: 'corrupt', code: 'WENDKEEP_SYNC_STATE_UNAVAILABLE' },
41
+ conflicts: 0,
42
+ };
43
+ const conflicts = Object.values(state.conflicts || {}).filter((item) => item?.status === 'open').length;
44
+ return { enabled: true, outbox: safeOutbox, conflicts };
45
+ }
46
+
47
+ export function listSyncConflictsForMcp({ state } = {}) {
48
+ return Object.entries(state?.conflicts || {})
49
+ .filter(([, item]) => item?.status === 'open')
50
+ .map(([recordKey, item]) => ({
51
+ record_key: recordKey,
52
+ status: 'open',
53
+ candidates: (item.candidates || []).map(publicCandidate),
54
+ }))
55
+ .sort((left, right) => left.record_key.localeCompare(right.record_key));
56
+ }
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@wendkeep/pi",
3
3
  "private": true,
4
- "type": "module"
4
+ "type": "module",
5
+ "exports": "./src/index.mjs"
5
6
  }
@@ -0,0 +1,29 @@
1
+ const EVENT_CAPABILITIES = {
2
+ session_start: 'session.start',
3
+ session_resume: 'session.resume',
4
+ session_stop: 'session.stop',
5
+ prompt_submit: 'prompt.submit',
6
+ tool_pre: 'tool.pre',
7
+ };
8
+
9
+ export function piAdapterDescriptor() {
10
+ return {
11
+ schema_version: 1,
12
+ host_id: 'pi',
13
+ adapter_version: 1,
14
+ transport: 'extension',
15
+ envelope_version: 1,
16
+ };
17
+ }
18
+
19
+ export function normalizePiLifecycleEvent(input = {}) {
20
+ const capability = EVENT_CAPABILITIES[String(input.type || '')];
21
+ if (!capability) return { ok: false, code: 'PI_ENVELOPE_UNKNOWN' };
22
+ return {
23
+ schema_version: 1,
24
+ host_id: 'pi',
25
+ capability,
26
+ session_id: String(input.sessionId || input.session_id || ''),
27
+ authority: 'adapted',
28
+ };
29
+ }
@@ -22,9 +22,13 @@
22
22
  "decisions": { "$ref": "#/$defs/stringArray" },
23
23
  "next_actions": { "$ref": "#/$defs/stringArray" },
24
24
  "blockers": { "$ref": "#/$defs/stringArray" },
25
+ "tdd_attestation_ids": { "$ref": "#/$defs/stringArray" },
25
26
  "head_sha": { "type": "string", "minLength": 1 },
26
27
  "tasks_sha256": { "type": "string", "minLength": 1 },
27
28
  "spec_sha256": { "type": "string", "minLength": 1 },
29
+ "host_coverage": { "$ref": "host-coverage-v1.schema.json" },
30
+ "coverage_findings": { "type": "array", "items": { "type": "object" } },
31
+ "coverage_waivers": { "type": "array", "items": { "type": "object" } },
28
32
  "authority": { "enum": ["verified", "reported"] }
29
33
  },
30
34
  "$defs": {
@@ -0,0 +1,46 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://wendkeep.dev/schema/host-capability-manifest-v1.schema.json",
4
+ "title": "WendKeep host capability manifest v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schema_version", "manifest_version", "host_id", "label", "supported_major_versions", "envelope_versions", "capabilities"],
8
+ "properties": {
9
+ "schema_version": { "const": 1 },
10
+ "manifest_version": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
11
+ "host_id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
12
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
13
+ "supported_major_versions": { "type": "array", "minItems": 1, "items": { "type": ["integer", "string"] } },
14
+ "envelope_versions": { "type": "array", "minItems": 1, "items": { "type": "integer", "minimum": 1 } },
15
+ "capabilities": {
16
+ "type": "object",
17
+ "additionalProperties": false,
18
+ "required": ["session.start", "session.resume", "session.stop", "prompt.submit", "tool.pre", "tool.post", "tool.effect.read", "tool.effect.write", "tool.effect.destructive", "edit.attribution", "plan.approved", "decision.capture", "task.completed", "subagent.start", "subagent.stop", "transcript.read", "usage.read"],
19
+ "properties": {
20
+ "session.start": { "$ref": "#/$defs/state" },
21
+ "session.resume": { "$ref": "#/$defs/state" },
22
+ "session.stop": { "$ref": "#/$defs/state" },
23
+ "prompt.submit": { "$ref": "#/$defs/state" },
24
+ "tool.pre": { "$ref": "#/$defs/state" },
25
+ "tool.post": { "$ref": "#/$defs/state" },
26
+ "tool.effect.read": { "$ref": "#/$defs/state" },
27
+ "tool.effect.write": { "$ref": "#/$defs/state" },
28
+ "tool.effect.destructive": { "$ref": "#/$defs/state" },
29
+ "edit.attribution": { "$ref": "#/$defs/state" },
30
+ "plan.approved": { "$ref": "#/$defs/state" },
31
+ "decision.capture": { "$ref": "#/$defs/state" },
32
+ "task.completed": { "$ref": "#/$defs/state" },
33
+ "subagent.start": { "$ref": "#/$defs/state" },
34
+ "subagent.stop": { "$ref": "#/$defs/state" },
35
+ "transcript.read": { "$ref": "#/$defs/state" },
36
+ "usage.read": { "$ref": "#/$defs/state" }
37
+ }
38
+ }
39
+ },
40
+ "$defs": {
41
+ "state": { "enum": ["native", "adapted", "polled", "manual", "unavailable"] },
42
+ "capabilityName": {
43
+ "enum": ["session.start", "session.resume", "session.stop", "prompt.submit", "tool.pre", "tool.post", "tool.effect.read", "tool.effect.write", "tool.effect.destructive", "edit.attribution", "plan.approved", "decision.capture", "task.completed", "subagent.start", "subagent.stop", "transcript.read", "usage.read"]
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://wendkeep.dev/schema/host-coverage-v1.schema.json",
4
+ "title": "WendKeep host coverage v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schema_version", "manifest_version", "host_id", "requested_host_id", "host_version", "version_supported", "observed_at", "degraded", "capabilities", "degradations", "tool_effects"],
8
+ "properties": {
9
+ "schema_version": { "const": 1 },
10
+ "manifest_version": { "type": "string" },
11
+ "host_id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
12
+ "requested_host_id": { "type": "string", "minLength": 1, "maxLength": 80 },
13
+ "host_version": { "type": "string", "maxLength": 80 },
14
+ "version_supported": { "type": "boolean" },
15
+ "observed_at": { "type": "string", "format": "date-time" },
16
+ "degraded": { "type": "boolean" },
17
+ "capabilities": { "type": "array", "minItems": 17, "maxItems": 17, "items": { "$ref": "#/$defs/capability" } },
18
+ "degradations": { "type": "array", "items": { "$ref": "#/$defs/degradation" } },
19
+ "tool_effects": { "$ref": "#/$defs/toolEffects" }
20
+ },
21
+ "$defs": {
22
+ "state": { "enum": ["native", "adapted", "polled", "manual", "unavailable"] },
23
+ "capability": {
24
+ "type": "object", "additionalProperties": false,
25
+ "required": ["capability", "state", "authority"],
26
+ "properties": {
27
+ "capability": { "type": "string" },
28
+ "state": { "$ref": "#/$defs/state" },
29
+ "authority": { "enum": ["verified", "reported", "unavailable"] }
30
+ }
31
+ },
32
+ "degradation": {
33
+ "type": "object", "additionalProperties": false,
34
+ "required": ["capability", "state", "code", "blocking"],
35
+ "properties": {
36
+ "capability": { "type": "string" },
37
+ "state": { "$ref": "#/$defs/state" },
38
+ "code": { "type": "string", "pattern": "^HOST_[A-Z0-9_]+$" },
39
+ "blocking": { "type": "boolean" }
40
+ }
41
+ },
42
+ "toolEffects": {
43
+ "type": "object", "additionalProperties": false,
44
+ "required": ["manifest_valid", "catalog_version", "read", "write", "destructive", "unknown"],
45
+ "properties": {
46
+ "manifest_valid": { "type": "boolean" },
47
+ "catalog_version": { "type": "string" },
48
+ "read": { "type": "boolean" },
49
+ "write": { "type": "boolean" },
50
+ "destructive": { "type": "boolean" },
51
+ "unknown": { "const": "fail-closed" }
52
+ }
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "wendkeep://schema/mcp-effect-manifest-v1",
4
+ "title": "WendKeep MCP effect manifest v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schema_version", "catalog_version", "server_aliases", "tools", "integrity"],
8
+ "properties": {
9
+ "schema_version": { "const": 1 },
10
+ "catalog_version": { "type": "string", "format": "date" },
11
+ "server_aliases": {
12
+ "type": "array",
13
+ "minItems": 1,
14
+ "uniqueItems": true,
15
+ "items": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" }
16
+ },
17
+ "tools": {
18
+ "type": "array",
19
+ "minItems": 1,
20
+ "items": {
21
+ "type": "object",
22
+ "additionalProperties": false,
23
+ "required": ["name", "effect", "capability", "effect_version", "input_schema", "output_schema"],
24
+ "properties": {
25
+ "name": { "type": "string", "pattern": "^wendkeep_[a-z0-9_]+$" },
26
+ "effect": { "enum": ["read", "write", "destructive"] },
27
+ "capability": { "type": "string", "pattern": "^[a-z]+:[a-z]+$" },
28
+ "effect_version": { "const": 1 },
29
+ "input_schema": { "const": "wendkeep://schema/mcp-tool-input-v1" },
30
+ "output_schema": { "const": "wendkeep://schema/mcp-tool-result-v1" }
31
+ }
32
+ }
33
+ },
34
+ "integrity": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
35
+ }
36
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "wendkeep://schema/mcp-tool-input-v1",
4
+ "title": "WendKeep MCP tool input v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["project_root"],
8
+ "properties": {
9
+ "project_root": { "type": "string", "minLength": 1 },
10
+ "worktree_root": { "type": "string", "minLength": 1 },
11
+ "session_id": { "type": "string", "minLength": 1 },
12
+ "active_context_id": { "type": "string", "minLength": 1 },
13
+ "actor": { "type": "string", "minLength": 1 },
14
+ "reason": { "type": "string", "minLength": 1, "maxLength": 500 },
15
+ "capabilities": { "type": "array", "uniqueItems": true, "items": { "type": "string" } },
16
+ "lease": {
17
+ "type": "object",
18
+ "additionalProperties": false,
19
+ "required": ["id", "expires_at"],
20
+ "properties": {
21
+ "id": { "type": "string", "minLength": 1 },
22
+ "expires_at": { "type": "string", "format": "date-time" }
23
+ }
24
+ },
25
+ "change": { "type": "string" },
26
+ "task": { "type": "string" },
27
+ "query": { "type": "string" },
28
+ "cursor": { "type": "string" },
29
+ "limit": { "type": "integer", "minimum": 1, "maximum": 100 },
30
+ "payload": { "type": "object" }
31
+ }
32
+ }