@adhdev/mesh-shared 1.0.82-rc.13 → 1.0.82-rc.131

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 (60) hide show
  1. package/dist/assistant-protocol.d.ts +158 -6
  2. package/dist/decision-push-relay.d.ts +20 -0
  3. package/dist/index.d.ts +10 -0
  4. package/dist/index.js +1524 -110
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1391 -110
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/launch-defaults.d.ts +196 -0
  9. package/dist/light-task.d.ts +96 -0
  10. package/dist/mesh-tool-names.d.ts +2 -2
  11. package/dist/mesh-vocabulary.d.ts +6 -4
  12. package/dist/mission-git-state.d.ts +83 -0
  13. package/dist/mission-items.d.ts +202 -0
  14. package/dist/node-facts.d.ts +35 -1
  15. package/dist/outbound-message.d.ts +9 -2
  16. package/dist/protocol/daemon-server.d.ts +42 -2
  17. package/dist/protocol/dashboard-daemon-p2p.d.ts +1 -1
  18. package/dist/protocol/dashboard-server.d.ts +20 -2
  19. package/dist/quota-freshness.d.ts +4 -4
  20. package/dist/relay-reprobe.d.ts +52 -0
  21. package/dist/release.d.ts +90 -0
  22. package/dist/role-launch.d.ts +11 -0
  23. package/dist/session-launch.d.ts +10 -22
  24. package/dist/slot-proposal.d.ts +14 -0
  25. package/dist/task-source-phase.d.ts +83 -0
  26. package/dist/task-stages.d.ts +210 -0
  27. package/dist/turn-evidence.d.ts +26 -8
  28. package/dist/turn-ipc-mission.d.ts +72 -1
  29. package/dist/turn-ipc-queue.d.ts +30 -0
  30. package/dist/turn-ipc.d.ts +2 -2
  31. package/dist/worker-protocol.d.ts +41 -1
  32. package/package.json +1 -1
  33. package/src/assistant-protocol.ts +294 -6
  34. package/src/daemon-normalize.ts +7 -5
  35. package/src/decision-push-relay.ts +23 -0
  36. package/src/index.ts +11 -0
  37. package/src/launch-defaults.ts +170 -0
  38. package/src/light-task.ts +116 -0
  39. package/src/mesh-tool-names.ts +22 -0
  40. package/src/mesh-vocabulary.ts +4 -2
  41. package/src/mission-git-state.ts +112 -0
  42. package/src/mission-items.ts +421 -0
  43. package/src/node-facts.ts +35 -1
  44. package/src/outbound-message.ts +19 -0
  45. package/src/protocol/daemon-server.ts +37 -2
  46. package/src/protocol/dashboard-server.ts +13 -2
  47. package/src/quota-freshness.ts +22 -11
  48. package/src/relay-reprobe.ts +117 -0
  49. package/src/release.ts +121 -0
  50. package/src/role-launch.ts +51 -0
  51. package/src/session-launch.ts +17 -1
  52. package/src/slot-proposal.ts +61 -2
  53. package/src/task-source-phase.ts +70 -0
  54. package/src/task-stages.ts +459 -0
  55. package/src/turn-evidence.ts +42 -4
  56. package/src/turn-ipc-mission.ts +127 -11
  57. package/src/turn-ipc-queue.ts +45 -2
  58. package/src/turn-ipc-turn.ts +1 -1
  59. package/src/turn-ipc.ts +1 -0
  60. package/src/worker-protocol.ts +94 -0
@@ -11,9 +11,8 @@
11
11
  * - the daemon-only verbs (launch / MCP-only pull / owner actions) that have
12
12
  * no tool.
13
13
  *
14
- * Assistant tools are a separate set from the mesh tools: none of these names
15
- * belongs in `CANONICAL_MESH_TOOL_NAMES`, and the coordinator/worker MCP modes
16
- * never publish them.
14
+ * Assistant-specific tools remain separate from mesh tools. Driver discovery
15
+ * (list/describe) is shared across all three modes; invoke remains Worker-only.
17
16
  */
18
17
 
19
18
  export const ASSISTANT_TOOLS = [
@@ -25,11 +24,23 @@ export const ASSISTANT_TOOLS = [
25
24
  'project_send',
26
25
  'project_read',
27
26
  'project_add',
27
+ 'project_attach_remote',
28
28
  'discover_repos',
29
29
  'memory',
30
+ 'memory_search',
30
31
  'skill_view',
31
32
  'skill_manage',
32
33
  'project_note',
34
+ 'launch_defaults',
35
+ 'launch_defaults_set',
36
+ 'driver_list',
37
+ 'driver_describe',
38
+ 'artifact_list',
39
+ 'artifact_read',
40
+ 'decision_answer',
41
+ 'decision_request',
42
+ 'session_control',
43
+ 'file_transfer',
33
44
  ] as const
34
45
 
35
46
  export type AssistantTool = typeof ASSISTANT_TOOLS[number]
@@ -43,6 +54,8 @@ export function isAssistantTool(value: unknown): value is AssistantTool {
43
54
  /** Daemon verb names (§4.4 table + the five verbs below it). */
44
55
  export const ASSISTANT_VERB = {
45
56
  // tool verbs
57
+ driverList: 'driver_list',
58
+ driverDescribe: 'driver_describe',
46
59
  projects: 'assistant_projects',
47
60
  environment: 'assistant_environment',
48
61
  action: 'assistant_action',
@@ -53,11 +66,26 @@ export const ASSISTANT_VERB = {
53
66
  projectSend: 'assistant_project_send',
54
67
  projectRead: 'assistant_project_read',
55
68
  projectAdd: 'assistant_project_add',
69
+ projectAttachRemote: 'assistant_project_attach_remote',
56
70
  discoverRepos: 'assistant_discover_repos',
57
71
  memory: 'assistant_memory',
72
+ /** Pull-only FTS search over the archive tier (memory design 2026-11-01 §3.4). */
73
+ memorySearch: 'assistant_memory_search',
58
74
  skillView: 'assistant_skill_view',
59
75
  skillManage: 'assistant_skill_manage',
60
76
  projectNote: 'assistant_project_note',
77
+ launchDefaults: 'assistant_launch_defaults',
78
+ launchDefaultsSet: 'assistant_launch_defaults_set',
79
+ artifactList: 'assistant_artifact_list',
80
+ artifactRead: 'assistant_artifact_read',
81
+ /** Owner-decision inbox (structured-missions design 2026-10-28 §6.3): the owner's words recorded as answers. */
82
+ decisionAnswer: 'assistant_decision_answer',
83
+ /** Register a plain-text question a coordinator put to the owner as a decision item (§5.2). */
84
+ decisionRequest: 'assistant_decision_request',
85
+ /** Stop / restart / switch the provider of a coordinator, worker or the assistant session (handoff design 2026-11-01 §4). */
86
+ sessionControl: 'assistant_session_control',
87
+ /** Request / status / cancel the assistant's own project file transfers (owner approves in the dashboard; file-transfer design section 6). */
88
+ fileTransfer: 'assistant_file_transfer',
61
89
  // assistant-side daemon verbs without a tool of the same name
62
90
  launch: 'launch_assistant',
63
91
  pendingRelays: 'assistant_pending_relays',
@@ -65,12 +93,23 @@ export const ASSISTANT_VERB = {
65
93
  stagedResolve: 'assistant_staged_resolve',
66
94
  storeAdmin: 'assistant_store_admin',
67
95
  importSkills: 'assistant_import_skills',
96
+ /** Owner skill list (attach/view counts, save proposals, recent skill metrics); reads move no counter. */
97
+ skillsList: 'assistant_skills_list',
98
+ /** Owner: what the assistant remembered recently, with undo handles (memory design §3.2). */
99
+ memoryDigest: 'assistant_memory_digest',
100
+ /** Owner: reverse one remembered write or one batch (memory design §3.2). Never an assistant tool. */
101
+ memoryUndo: 'assistant_memory_undo',
102
+ /** Projects the assistant is following (open relay threads) — list / stop following. */
103
+ threads: 'assistant_threads',
104
+ threadClose: 'assistant_thread_close',
68
105
  } as const
69
106
 
70
107
  export type AssistantVerb = typeof ASSISTANT_VERB[keyof typeof ASSISTANT_VERB]
71
108
 
72
109
  /** The daemon verb each assistant tool calls. */
73
110
  export const ASSISTANT_TOOL_VERBS: Readonly<Record<AssistantTool, AssistantVerb>> = {
111
+ driver_list: ASSISTANT_VERB.driverList,
112
+ driver_describe: ASSISTANT_VERB.driverDescribe,
74
113
  projects: ASSISTANT_VERB.projects,
75
114
  environment: ASSISTANT_VERB.environment,
76
115
  assistant_action: ASSISTANT_VERB.action,
@@ -79,11 +118,21 @@ export const ASSISTANT_TOOL_VERBS: Readonly<Record<AssistantTool, AssistantVerb>
79
118
  project_send: ASSISTANT_VERB.projectSend,
80
119
  project_read: ASSISTANT_VERB.projectRead,
81
120
  project_add: ASSISTANT_VERB.projectAdd,
121
+ project_attach_remote: ASSISTANT_VERB.projectAttachRemote,
82
122
  discover_repos: ASSISTANT_VERB.discoverRepos,
83
123
  memory: ASSISTANT_VERB.memory,
124
+ memory_search: ASSISTANT_VERB.memorySearch,
84
125
  skill_view: ASSISTANT_VERB.skillView,
85
126
  skill_manage: ASSISTANT_VERB.skillManage,
86
127
  project_note: ASSISTANT_VERB.projectNote,
128
+ launch_defaults: ASSISTANT_VERB.launchDefaults,
129
+ launch_defaults_set: ASSISTANT_VERB.launchDefaultsSet,
130
+ artifact_list: ASSISTANT_VERB.artifactList,
131
+ artifact_read: ASSISTANT_VERB.artifactRead,
132
+ decision_answer: ASSISTANT_VERB.decisionAnswer,
133
+ decision_request: ASSISTANT_VERB.decisionRequest,
134
+ session_control: ASSISTANT_VERB.sessionControl,
135
+ file_transfer: ASSISTANT_VERB.fileTransfer,
87
136
  }
88
137
 
89
138
  /**
@@ -92,7 +141,7 @@ export const ASSISTANT_TOOL_VERBS: Readonly<Record<AssistantTool, AssistantVerb>
92
141
  * because they cause effects (a coordinator message or launch, a new
93
142
  * project), and MCP clients use readOnlyHint to skip confirmation.
94
143
  */
95
- export const ASSISTANT_WRITE_TOOLS: readonly AssistantTool[] = ['project_watch', 'assistant_action', 'memory', 'skill_manage', 'project_note', 'project_send', 'project_add']
144
+ export const ASSISTANT_WRITE_TOOLS: readonly AssistantTool[] = ['project_watch', 'assistant_action', 'memory', 'skill_manage', 'project_note', 'project_send', 'project_add', 'project_attach_remote', 'launch_defaults_set', 'decision_answer', 'decision_request', 'session_control', 'file_transfer']
96
145
 
97
146
  /** Owner-only verbs: never reachable from the assistant's MCP server (no `ipc`). */
98
147
  export const ASSISTANT_OWNER_VERBS: readonly AssistantVerb[] = [
@@ -100,18 +149,24 @@ export const ASSISTANT_OWNER_VERBS: readonly AssistantVerb[] = [
100
149
  ASSISTANT_VERB.stagedResolve,
101
150
  ASSISTANT_VERB.storeAdmin,
102
151
  ASSISTANT_VERB.importSkills,
152
+ ASSISTANT_VERB.skillsList,
153
+ ASSISTANT_VERB.memoryDigest,
154
+ ASSISTANT_VERB.memoryUndo,
155
+ ASSISTANT_VERB.threadClose,
103
156
  ]
104
157
 
105
158
  /** The only assistant verbs accepted while an idle review turn is open (§4.10.7). */
106
159
  export const ASSISTANT_REVIEW_TURN_VERBS: readonly AssistantVerb[] = [
107
160
  ASSISTANT_VERB.memory,
161
+ ASSISTANT_VERB.memorySearch,
108
162
  ASSISTANT_VERB.skillView,
109
163
  ASSISTANT_VERB.skillManage,
110
164
  ASSISTANT_VERB.projectNote,
111
165
  ]
112
166
 
113
- /**
114
- * Env var the daemon sets on the assistant CLI's process (§4.5), read by the
167
+ import { canonicalDaemonId } from './daemon-normalize'
168
+
169
+ /** Env var the daemon sets on the assistant CLI's process (§4.5), read by the
115
170
  * assistant MCP server and forwarded on every verb as
116
171
  * `ASSISTANT_SESSION_ID_ARG`. Routing / ownership only — never an auth gate.
117
172
  */
@@ -119,3 +174,236 @@ export const ASSISTANT_SESSION_ID_ENV = 'ADHDEV_ASSISTANT_SESSION_ID'
119
174
 
120
175
  /** Request arg carrying the calling assistant session id. */
121
176
  export const ASSISTANT_SESSION_ID_ARG = 'assistantSessionId'
177
+
178
+ // ─── Remote Assistant Project Follow & Host-Authoritative Grant (rc24) ──────
179
+
180
+ /**
181
+ * Conceptual single-assistant slot in the verified account namespace.
182
+ * Fixed to `'personal'` — one logical assistant per account with one
183
+ * owner-selected active execution daemon binding per project ACL.
184
+ */
185
+ export const ASSISTANT_ACCOUNT_SLOT = 'personal' as const
186
+ export type AssistantAccountSlot = typeof ASSISTANT_ACCOUNT_SLOT
187
+
188
+ /**
189
+ * Daemon commands for remote project discovery, host ACL grant/revoke, and
190
+ * assistant-side follow/unfollow. Registered outside `ASSISTANT_VERB` so the
191
+ * assistant MCP server tool/verb parity table remains untouched.
192
+ */
193
+ export const ASSISTANT_REMOTE_PROJECT_COMMAND = 'assistant_remote_project' as const
194
+ export const ASSISTANT_REMOTE_PROJECT_CATALOG_COMMAND = 'assistant_remote_project_catalog' as const
195
+ export const ASSISTANT_REMOTE_PROJECT_ACCESS_COMMAND = 'assistant_remote_project_access' as const
196
+ export const ASSISTANT_REMOTE_FOLLOW_COMMAND = 'assistant_remote_follow' as const
197
+
198
+ /**
199
+ * Narrow operations a non-roster follower deputy is permitted to invoke on
200
+ * `assistant_remote_project` when the host's `assistantRemoteAccess` ACL is active.
201
+ * `note`, `terminal`, and `inventory` remain strictly roster-member-only.
202
+ */
203
+ export const ASSISTANT_FOLLOWER_ALLOWED_OPS = ['status', 'read', 'poll', 'report', 'send', 'artifact_list', 'artifact_read', 'decision_list', 'decision_answer', 'decision_request'] as const
204
+ export type AssistantFollowerAllowedOp = typeof ASSISTANT_FOLLOWER_ALLOWED_OPS[number]
205
+
206
+ const ASSISTANT_FOLLOWER_ALLOWED_OP_SET: ReadonlySet<string> = new Set(ASSISTANT_FOLLOWER_ALLOWED_OPS)
207
+
208
+ export function isAssistantFollowerAllowedOp(value: unknown): value is AssistantFollowerAllowedOp {
209
+ return typeof value === 'string' && ASSISTANT_FOLLOWER_ALLOWED_OP_SET.has(value)
210
+ }
211
+
212
+ /**
213
+ * Owner-decision ops were added after grants were persisted with an explicit
214
+ * `allowedOps` list. A grant that already lets the follower read status (list)
215
+ * or send to the coordinator (answer / register) covers the matching decision op,
216
+ * so no existing grant needs re-issuing.
217
+ */
218
+ const DECISION_OP_IMPLIED_BY: Readonly<Record<string, AssistantFollowerAllowedOp>> = {
219
+ decision_list: 'status',
220
+ decision_answer: 'send',
221
+ decision_request: 'send',
222
+ }
223
+
224
+ export function followerOpPermitted(op: string, allowedOps: readonly AssistantFollowerAllowedOp[]): boolean {
225
+ if (!isAssistantFollowerAllowedOp(op)) return false
226
+ if ((allowedOps as readonly string[]).includes(op)) return true
227
+ const implied = DECISION_OP_IMPLIED_BY[op]
228
+ return implied !== undefined && allowedOps.includes(implied)
229
+ }
230
+
231
+ /**
232
+ * Host-authoritative narrow project ACL persisted on the hosting daemon's
233
+ * `LocalMeshEntry` in `meshes.json`. Revocation increments `grantRevision`
234
+ * and retains a `'revoked'` tombstone so stale follower caches cannot replay.
235
+ */
236
+ export interface AssistantRemoteAccessBinding {
237
+ hostDaemonId: string
238
+ meshId: string
239
+ accountSlot: AssistantAccountSlot
240
+ activeDaemonId: string
241
+ bindingRevision: number
242
+ grantRevision: number
243
+ status: 'active' | 'revoked'
244
+ allowedOps: readonly AssistantFollowerAllowedOp[]
245
+ allowCoordinatorLaunch?: boolean
246
+ allowArtifactRead?: boolean
247
+ grantedAt: number
248
+ revokedAt?: number
249
+ }
250
+
251
+ /**
252
+ * Durable owner-binding receipt persisted in the assistant daemon's
253
+ * `assistant.json`. Survives ordinary daemon restarts and session/provider
254
+ * replacements (`bindSession`), while missing/corrupt/mismatched receipts
255
+ * fail closed until owner reconciliation.
256
+ */
257
+ export interface AssistantOwnerBindingReceipt {
258
+ accountSlot: AssistantAccountSlot
259
+ daemonId: string
260
+ bindingRevision: number
261
+ boundAt: number | string
262
+ }
263
+
264
+ export type FollowedRemoteProjectState = 'followed' | 'unfollowed' | 'revoked'
265
+
266
+ export type RemoteAccessState =
267
+ | 'not_granted'
268
+ | 'granted_unfollowed'
269
+ | 'followed'
270
+ | 'revoked'
271
+ | 'host_unreachable'
272
+ | 'binding_mismatch'
273
+
274
+ /**
275
+ * Assistant-local followed remote project reference persisted in `assistant.json`.
276
+ * Never injected into `meshes.json`, `mesh-host-records.json`, `mesh-node-state-push.json`,
277
+ * or `inlineMeshCache`.
278
+ */
279
+ export interface FollowedRemoteProjectEntry {
280
+ /** Canonical key: `${canonicalDaemonId(hostDaemonId)}::${meshId}` */
281
+ key: string
282
+ hostDaemonId: string
283
+ hostLabel?: string
284
+ meshId: string
285
+ name: string
286
+ slug: string
287
+ sanitizedRepoIdentity: string | null
288
+ repoIdentity?: string
289
+ accountSlot: AssistantAccountSlot
290
+ bindingRevision: number
291
+ grantRevision: number
292
+ allowCoordinatorLaunch?: boolean
293
+ allowArtifactRead?: boolean
294
+ state: FollowedRemoteProjectState
295
+ followedAt: number | string
296
+ updatedAt: number | string
297
+ unfollowedAt?: number | string
298
+ revokedAt?: number | string
299
+ revokedReason?: string
300
+ lastCursor?: string | null
301
+ coordinatorSessionId?: string | null
302
+ lastErrorCode?: string
303
+ lastObserved?: {
304
+ observedAt: number | string
305
+ coordinatorState?: string
306
+ coordinatorMissing?: boolean
307
+ coordinatorPresent?: boolean
308
+ lastHeadline?: string
309
+ summary?: string
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Content-free canonical catalog metadata returned by `assistant_remote_project_catalog`
315
+ * for meshes actually hosted on the queried remote daemon.
316
+ */
317
+ export interface RemoteProjectCatalogItem {
318
+ hostDaemonId: string
319
+ meshId: string
320
+ name: string
321
+ sanitizedRepoIdentity: string | null
322
+ coordinatorState?: 'none' | 'idle' | 'working' | 'waiting' | string
323
+ allowCoordinatorLaunch?: boolean
324
+ allowArtifactRead?: boolean
325
+ capabilities: {
326
+ status: true
327
+ read: true
328
+ poll: true
329
+ report: true
330
+ send: true
331
+ coordinatorPresent?: boolean
332
+ allowCoordinatorLaunch?: boolean
333
+ allowArtifactRead?: boolean
334
+ }
335
+ observedAt: number | string
336
+ }
337
+
338
+ /** Build the canonical `(hostDaemonId, meshId)` key used across assistant follow state. */
339
+ export function followedRemoteProjectKey(hostDaemonId: string, meshId: string): string {
340
+ const canonHost = canonicalDaemonId(hostDaemonId) ?? hostDaemonId.trim()
341
+ return `${canonHost}::${meshId.trim()}`
342
+ }
343
+
344
+ /**
345
+ * Sanitize a repository identity or remote URL into a content-free `host/path`
346
+ * identifier suitable for remote discovery catalogs. Strips credentials, query
347
+ * strings, fragments, and `.git` suffixes, and rejects local filesystem paths.
348
+ */
349
+ export function sanitizeRemoteRepoIdentity(raw: string | null | undefined): string | null {
350
+ if (typeof raw !== 'string') return null
351
+ const trimmed = raw.trim()
352
+ if (!trimmed) return null
353
+
354
+ // Reject local filesystem paths (Unix absolute/relative/home, Windows drive/UNC, file:// URLs).
355
+ if (
356
+ trimmed.startsWith('/')
357
+ || trimmed.startsWith('./')
358
+ || trimmed.startsWith('../')
359
+ || trimmed.startsWith('~/')
360
+ || trimmed.startsWith('\\')
361
+ || /^[a-zA-Z]:[\\/]/.test(trimmed)
362
+ || /^file:/i.test(trimmed)
363
+ ) {
364
+ return null
365
+ }
366
+
367
+ const withoutQuery = trimmed.replace(/[?#].*$/, '').replace(/\/+$/, '')
368
+ if (!withoutQuery) return null
369
+
370
+ let host = ''
371
+ let repoPath = ''
372
+
373
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(withoutQuery)) {
374
+ try {
375
+ const url = new URL(withoutQuery)
376
+ if (url.protocol === 'file:') return null
377
+ host = url.hostname.toLowerCase()
378
+ repoPath = decodeURIComponent(url.pathname)
379
+ .replace(/^\/+|\/+$/g, '')
380
+ .replace(/\.git$/i, '')
381
+ } catch {
382
+ return null
383
+ }
384
+ } else {
385
+ const scpMatch = withoutQuery.match(/^(?:[^@/:]+@)?(\[[^\]]+\]|[^/:]+):(.+)$/)
386
+ if (scpMatch) {
387
+ host = scpMatch[1].replace(/^\[|\]$/g, '').toLowerCase()
388
+ repoPath = scpMatch[2].replace(/^\/+|\/+$/g, '').replace(/\.git$/i, '')
389
+ } else {
390
+ const slash = withoutQuery.indexOf('/')
391
+ if (slash > 0) {
392
+ const rawHost = withoutQuery.slice(0, slash)
393
+ const atIdx = rawHost.lastIndexOf('@')
394
+ host = (atIdx >= 0 ? rawHost.slice(atIdx + 1) : rawHost).toLowerCase()
395
+ repoPath = withoutQuery.slice(slash + 1).replace(/^\/+|\/+$/g, '').replace(/\.git$/i, '')
396
+ }
397
+ }
398
+ }
399
+
400
+ if (!host || !repoPath) return null
401
+ if (!host.includes('.') && host !== 'localhost') return null
402
+ if (/[\s@:\\]/.test(host)) return null
403
+ const segments = repoPath.split('/').filter(Boolean)
404
+ if (segments.length === 0) return null
405
+ if (segments.some(seg => seg === '.' || seg === '..' || /[\s@:\\]/.test(seg))) return null
406
+
407
+ return `${host}/${segments.join('/')}`.slice(0, 200)
408
+ }
409
+
@@ -108,13 +108,15 @@ export function isPhantomDaemonEntry(
108
108
  export function machineCoreFromDaemonId(id: string | null | undefined): string | undefined {
109
109
  const trimmed = readString(id)
110
110
  if (!trimmed) return undefined
111
+ const lower = trimmed.toLowerCase()
111
112
  for (const prefix of DAEMON_ID_PREFIXES) {
112
- if (trimmed.startsWith(prefix)) {
113
+ if (lower.startsWith(prefix)) {
113
114
  const core = trimmed.slice(prefix.length).trim()
114
- return core || undefined
115
+ if (!core) return undefined
116
+ return /^mach_/i.test(core) ? `mach_${core.slice(5)}` : core
115
117
  }
116
118
  }
117
- return trimmed
119
+ return /^mach_/i.test(trimmed) ? `mach_${trimmed.slice(5)}` : trimmed
118
120
  }
119
121
 
120
122
  /**
@@ -144,8 +146,8 @@ export function machineCoreFromDaemonId(id: string | null | undefined): string |
144
146
  export function canonicalDaemonId(id: string | null | undefined): string | undefined {
145
147
  const core = machineCoreFromDaemonId(id)
146
148
  if (!core) return undefined
147
- if (!core.startsWith('mach_')) return core
148
- return `daemon_${core}`
149
+ if (!/^mach_/i.test(core)) return core
150
+ return `daemon_mach_${core.slice(5)}`
149
151
  }
150
152
 
151
153
  /** True when both ids resolve to the same machine core — i.e. they are the same
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Opt-in "answer a decision from the push notification" relay (mission 4ae3edf2, owner 2026-10-29).
3
+ *
4
+ * ★ A deliberate, narrow exception to "no dashboard command relay over server WS" (CLAUDE.md).
5
+ * With the user's opt-in setting ON and no dashboard window open, the notification's
6
+ * recommended-option action is POSTed by the service worker to the server, which forwards it to the
7
+ * owning daemon over the existing daemon WS as ONE fixed command. What crosses the server is exactly
8
+ * `{ meshId, itemId, optionId }` (+ the single-use answer token that authorizes it) — never the
9
+ * question, context or free text. Shared so the server's frame and the daemon's ingress cannot drift.
10
+ */
11
+
12
+ /** Daemon command the server sends; its only accepted source is {@link DECISION_PUSH_RELAY_SOURCE}. */
13
+ export const DECISION_PUSH_RELAY_COMMAND = 'mission_decision_push_relay_answer'
14
+
15
+ /** Command source the server stamps on the relayed frame (never settable by REST/API callers). */
16
+ export const DECISION_PUSH_RELAY_SOURCE = 'push_relay'
17
+
18
+ /** The complete relayed payload — ids only. */
19
+ export type DecisionPushRelayPayload = {
20
+ meshId: string
21
+ itemId: string
22
+ optionId: string
23
+ }
package/src/index.ts CHANGED
@@ -41,6 +41,17 @@ export * from './session-launch'
41
41
  export * from './turn-ipc'
42
42
  export * from './path-ownership'
43
43
  export * from './mission-brief'
44
+ export * from './mission-items'
45
+ export * from './mission-git-state'
46
+ export * from './release'
47
+ export * from './decision-push-relay'
44
48
  export * from './keyed-doc-delta'
45
49
  export * from './provider-approval'
46
50
  export * from './provider-question'
51
+ export * from './launch-defaults'
52
+
53
+ export * from './role-launch';
54
+ export * from './task-source-phase';
55
+ export * from './light-task';
56
+ export * from './relay-reprobe'
57
+ export * from './task-stages'
@@ -0,0 +1,170 @@
1
+ /** Daemon-local launch intent and command wire contract. P2P/local only;
2
+ * never include this document or its history in cloud status_report.
3
+ * Publication through mesh-shared's barrel is a later integration step. */
4
+ export const LAUNCH_DEFAULT_ROLES = ['assistant', 'coordinator'] as const;
5
+ export type LaunchDefaultRole = typeof LAUNCH_DEFAULT_ROLES[number];
6
+ export const LAUNCH_DEFAULT_SOURCES = ['user', 'stored_default', 'project_default', 'provider_default'] as const;
7
+ export type LaunchDefaultSource = typeof LAUNCH_DEFAULT_SOURCES[number];
8
+ export const LAUNCH_DEFAULTS_NEXT_LAUNCH_NOTE = 'Applies to the next launch; running sessions are unchanged.';
9
+ export function isLaunchDefaultRole(value: unknown): value is LaunchDefaultRole {
10
+ return typeof value === 'string' && (LAUNCH_DEFAULT_ROLES as readonly string[]).includes(value);
11
+ }
12
+ export function isLaunchDefaultSource(value: unknown): value is LaunchDefaultSource {
13
+ return typeof value === 'string' && (LAUNCH_DEFAULT_SOURCES as readonly string[]).includes(value);
14
+ }
15
+ export interface LaunchDefaultSelection {
16
+ provider: string;
17
+ /** Omission means pass no model/thinking argument, not inherit another provider. */
18
+ model?: string;
19
+ thinkingLevel?: string;
20
+ }
21
+ export type LaunchDefaultToolRestriction = 'enforced' | 'prompt_only';
22
+ export type LaunchDefaultOrigin = 'owner' | 'human' | 'relay' | 'review' | 'review_tainted';
23
+ export interface LaunchDefaultEntry extends LaunchDefaultSelection {
24
+ revision: number;
25
+ setBy: 'owner' | 'assistant';
26
+ setAt: number;
27
+ /** Ordered quota-failover alternatives (<= 3, distinct providers). Absent = none. */
28
+ fallback?: LaunchDefaultSelection[];
29
+ }
30
+ export interface LaunchDefaultChange {
31
+ at: number;
32
+ role: LaunchDefaultRole;
33
+ by: 'owner' | 'assistant';
34
+ origin: LaunchDefaultOrigin;
35
+ from: LaunchDefaultEntry | null;
36
+ to: LaunchDefaultEntry | null;
37
+ }
38
+ export interface LaunchDefaultsDocument {
39
+ version: 1;
40
+ /** Global document token, including clears; distinct from entry revisions. */
41
+ revision: number;
42
+ assistant?: LaunchDefaultEntry;
43
+ coordinator?: LaunchDefaultEntry;
44
+ history: LaunchDefaultChange[];
45
+ }
46
+ export interface LaunchDefaultRef {
47
+ role: LaunchDefaultRole;
48
+ scope: 'global' | 'project';
49
+ /** Entry revision for global defaults; host project token for project defaults. */
50
+ revision: number;
51
+ projectId?: string;
52
+ }
53
+ export type LaunchDefaultField = keyof LaunchDefaultSelection;
54
+ export interface LaunchDefaultAxis {
55
+ value: string | null;
56
+ source: LaunchDefaultSource;
57
+ defaultRef?: LaunchDefaultRef;
58
+ }
59
+ export type LaunchDefaultWarning = 'catalog_unverified' | 'manual_mcp_setup_required';
60
+ export type LaunchDefaultValidationReason =
61
+ | 'invalid_schema' | 'provider_unknown' | 'provider_not_cli' | 'provider_disabled'
62
+ | 'provider_not_detected' | 'provider_not_eligible' | 'provider_quota_gated' | 'model_unsupported'
63
+ | 'model_provider_mismatch' | 'model_not_offered' | 'thinking_unsupported'
64
+ | 'thinking_not_offered' | 'catalog_unavailable';
65
+ export type LaunchDefaultResolution =
66
+ | { ok: true; selection: LaunchDefaultSelection; applied: Record<LaunchDefaultField, LaunchDefaultAxis>;
67
+ defaultRef?: LaunchDefaultRef; documentRevision: number; warnings: LaunchDefaultWarning[];
68
+ toolRestriction: LaunchDefaultToolRestriction }
69
+ | { ok: false; code: 'launch_default_required' | 'launch_default_unavailable' | 'launch_selection_invalid';
70
+ role: LaunchDefaultRole; field: LaunchDefaultField; reason: string; source?: LaunchDefaultSource;
71
+ value?: string | null; defaultRef?: LaunchDefaultRef; candidates?: readonly string[]; hint: string };
72
+ export interface LaunchDefaultsRoleView {
73
+ stored: LaunchDefaultEntry | null;
74
+ /** The existing daemon resolver's result, including loud failures. */
75
+ effective: LaunchDefaultResolution;
76
+ }
77
+ type Target = { role: 'assistant'; project?: never } | { role: 'coordinator'; project?: string };
78
+ export type LaunchDefaultsReadRequest =
79
+ | ({ action?: 'get' } & (Target | { role?: never; project?: never }))
80
+ | ({ action: 'check' } & Target & LaunchDefaultSelection);
81
+ /** Mandatory CAS: global document token, or host project token for project writes.
82
+ * 0 is explicit first setup; clears advance the token and never restore fallback. */
83
+ export type LaunchDefaultsSetRequest = Target & { expectedRevision: number } & (
84
+ | ({ action: 'set' } & LaunchDefaultSelection)
85
+ | { action: 'clear'; provider?: never; model?: never; thinkingLevel?: never }
86
+ );
87
+ /** Existing assistant routing envelope; session identity never supplies origin. */
88
+ export type AssistantLaunchDefaultsReadRequest = LaunchDefaultsReadRequest & { assistantSessionId?: string };
89
+ export type AssistantLaunchDefaultsSetRequest = LaunchDefaultsSetRequest & { assistantSessionId?: string };
90
+ export const LAUNCH_DEFAULT_ERROR_CODES = [
91
+ 'invalid_args', 'launch_default_required', 'launch_default_unavailable', 'launch_selection_invalid',
92
+ 'launch_default_invalid', 'revision_conflict', 'store_unavailable', 'store_busy', 'persistence_failed',
93
+ 'project_not_found', 'project_ambiguous', 'project_not_hosted', 'project_storage_unavailable',
94
+ 'staging_unavailable', 'staging_failed', 'review_turn_tool_denied',
95
+ ] as const;
96
+ export type LaunchDefaultsErrorCode = typeof LAUNCH_DEFAULT_ERROR_CODES[number];
97
+ export interface LaunchDefaultsError {
98
+ success: false;
99
+ code: LaunchDefaultsErrorCode;
100
+ error: string;
101
+ reason?: string;
102
+ role?: LaunchDefaultRole;
103
+ field?: LaunchDefaultField;
104
+ source?: LaunchDefaultSource;
105
+ value?: string | null;
106
+ defaultRef?: LaunchDefaultRef;
107
+ candidates?: readonly string[];
108
+ actualRevision?: number;
109
+ /** 0 for an absent global document; absent when it cannot be read. */
110
+ documentRevision?: number;
111
+ /** A persistence failure can replace intent without confirming durability.
112
+ * Re-read before retrying; never report applied on committed:true alone. */
113
+ committed?: boolean;
114
+ }
115
+ export interface LaunchDefaultsReadSuccess {
116
+ success: true;
117
+ result: 'get';
118
+ documentRevision: number;
119
+ roles: Partial<Record<LaunchDefaultRole, LaunchDefaultsRoleView>>;
120
+ project?: { projectId: string; revision: number; entry: LaunchDefaultEntry | null };
121
+ }
122
+ export interface LaunchDefaultsCheckSuccess {
123
+ success: true;
124
+ result: 'check';
125
+ role: LaunchDefaultRole;
126
+ selection: LaunchDefaultSelection;
127
+ warnings: LaunchDefaultWarning[];
128
+ toolRestriction: LaunchDefaultToolRestriction;
129
+ lowersToolLock: boolean;
130
+ }
131
+ export interface LaunchDefaultsApplied {
132
+ success: true;
133
+ result: 'applied';
134
+ role: LaunchDefaultRole;
135
+ scope: 'global' | 'project';
136
+ projectId?: string;
137
+ entry: LaunchDefaultEntry | null;
138
+ previous: LaunchDefaultEntry | null;
139
+ /** CAS token returned by the authority that performed the write. */
140
+ revision: number;
141
+ warnings: LaunchDefaultWarning[];
142
+ durable: true;
143
+ note: string;
144
+ }
145
+ export interface LaunchDefaultsStaged {
146
+ success: true;
147
+ result: 'staged';
148
+ role: LaunchDefaultRole;
149
+ stagedId: string;
150
+ previous: LaunchDefaultEntry | null;
151
+ selection: LaunchDefaultSelection | null;
152
+ expectedRevision: number;
153
+ warnings: LaunchDefaultWarning[];
154
+ note: string;
155
+ }
156
+ /** Existing owner Inbox adapter stores this proposal; it is not another default.
157
+ * Applying it must revalidate on the host and CAS via the same set handler. */
158
+ export interface LaunchDefaultsProposal {
159
+ kind: 'launch_defaults';
160
+ role: LaunchDefaultRole;
161
+ project?: string;
162
+ selection: LaunchDefaultSelection | null;
163
+ previous: LaunchDefaultEntry | null;
164
+ expectedRevision: number;
165
+ origin: LaunchDefaultOrigin;
166
+ callerSessionId?: string;
167
+ }
168
+ export type LaunchDefaultsReadResponse = LaunchDefaultsReadSuccess | LaunchDefaultsCheckSuccess | LaunchDefaultsError;
169
+ export type LaunchDefaultsSetResponse = LaunchDefaultsApplied | LaunchDefaultsStaged | LaunchDefaultsError;
170
+ export type LaunchDefaultsResponse = LaunchDefaultsReadResponse | LaunchDefaultsSetResponse;