@adhdev/mesh-shared 1.0.82-rc.5 → 1.0.82-rc.50

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 (69) hide show
  1. package/dist/assistant-protocol.d.ts +163 -6
  2. package/dist/decision-push-relay.d.ts +20 -0
  3. package/dist/index.d.ts +12 -0
  4. package/dist/index.js +1637 -124
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1499 -124
  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 +13 -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 +61 -1
  15. package/dist/outbound-message.d.ts +9 -2
  16. package/dist/path-ownership.d.ts +1 -1
  17. package/dist/protocol/daemon-server.d.ts +42 -2
  18. package/dist/protocol/dashboard-daemon-p2p.d.ts +1 -1
  19. package/dist/protocol/dashboard-server.d.ts +20 -2
  20. package/dist/provider-approval.d.ts +36 -0
  21. package/dist/provider-question.d.ts +19 -0
  22. package/dist/quota-freshness.d.ts +4 -4
  23. package/dist/relay-reprobe.d.ts +52 -0
  24. package/dist/release.d.ts +90 -0
  25. package/dist/role-launch.d.ts +11 -0
  26. package/dist/session-launch.d.ts +10 -22
  27. package/dist/slot-proposal.d.ts +14 -0
  28. package/dist/task-source-phase.d.ts +83 -0
  29. package/dist/task-stages.d.ts +206 -0
  30. package/dist/turn-evidence.d.ts +43 -13
  31. package/dist/turn-ipc-mission.d.ts +72 -1
  32. package/dist/turn-ipc-queue.d.ts +30 -0
  33. package/dist/turn-ipc.d.ts +2 -2
  34. package/dist/types.d.ts +1 -0
  35. package/dist/worker-protocol.d.ts +33 -1
  36. package/package.json +1 -1
  37. package/src/assistant-protocol.ts +306 -6
  38. package/src/daemon-normalize.ts +7 -5
  39. package/src/decision-push-relay.ts +23 -0
  40. package/src/index.ts +13 -0
  41. package/src/keyed-doc-delta.ts +9 -1
  42. package/src/launch-defaults.ts +170 -0
  43. package/src/light-task.ts +116 -0
  44. package/src/mesh-tool-names.ts +22 -0
  45. package/src/mesh-vocabulary.ts +12 -2
  46. package/src/mission-git-state.ts +112 -0
  47. package/src/mission-items.ts +421 -0
  48. package/src/node-facts.ts +56 -1
  49. package/src/outbound-message.ts +19 -0
  50. package/src/path-ownership.ts +4 -6
  51. package/src/protocol/daemon-server.ts +37 -2
  52. package/src/protocol/dashboard-server.ts +13 -2
  53. package/src/provider-approval.ts +59 -0
  54. package/src/provider-question.ts +31 -0
  55. package/src/quota-freshness.ts +29 -13
  56. package/src/relay-reprobe.ts +117 -0
  57. package/src/release.ts +121 -0
  58. package/src/role-launch.ts +51 -0
  59. package/src/session-launch.ts +17 -1
  60. package/src/slot-proposal.ts +61 -2
  61. package/src/task-source-phase.ts +70 -0
  62. package/src/task-stages.ts +455 -0
  63. package/src/turn-evidence.ts +56 -20
  64. package/src/turn-ipc-mission.ts +127 -11
  65. package/src/turn-ipc-queue.ts +43 -2
  66. package/src/turn-ipc-turn.ts +1 -1
  67. package/src/turn-ipc.ts +1 -0
  68. package/src/types.ts +1 -0
  69. package/src/worker-protocol.ts +79 -0
@@ -30,7 +30,7 @@
30
30
  * the protocol contract the marker demarcates.
31
31
  */
32
32
  import { type MissionBrief } from './mission-brief';
33
- export declare const WORKER_TOOLS: readonly ["report_completion", "progress_update", "peer_context_pull", "git_status", "git_log", "git_diff"];
33
+ export declare const WORKER_TOOLS: readonly ["report_completion", "progress_update", "peer_context_pull", "git_status", "git_log", "git_diff", "driver_list", "driver_describe", "driver_invoke", "driver_scaffold", "driver_validate", "driver_export", "driver_install", "artifact_register", "artifact_list", "artifact_read", "contract_read", "contract_observe", "contract_current"];
34
34
  export type WorkerTool = typeof WORKER_TOOLS[number];
35
35
  export declare function isWorkerTool(value: unknown): value is WorkerTool;
36
36
  /** Stable marker line so a body is never footered twice and tests can find it. */
@@ -53,7 +53,37 @@ export interface WorkerProtocolFooterInput {
53
53
  * which is what every worker launched with the default gate receives.
54
54
  */
55
55
  workerMcp?: boolean;
56
+ /**
57
+ * Same-machine light task: the worker runs in a temporary light workspace.
58
+ * Renders the light-workspace rules (stay inside, commit there, no installs).
59
+ */
60
+ light?: {
61
+ workspace: string;
62
+ baseSha: string;
63
+ ossBaseSha?: string;
64
+ ownedPaths: string[];
65
+ };
66
+ /**
67
+ * Code-changing task on a shared (non-worktree) node checkout, not a light task: the worker commits on the
68
+ * branch that is currently checked out. Renders the "do not create or switch branches" rule.
69
+ */
70
+ commitOnCurrentBranch?: boolean;
71
+ /**
72
+ * Review-in-task (docs/design/2026-11-01-review-in-task.md §9.3): present when this
73
+ * dispatch is one stage of a stage pipeline. `workspace` is the reviewer's pinned
74
+ * workspace path when the daemon prepared one.
75
+ */
76
+ stage?: {
77
+ role: 'implement' | 'revise' | 'review';
78
+ round: number;
79
+ maxRevisions: number;
80
+ workspace?: string;
81
+ };
56
82
  }
83
+ /** Light-workspace worker rules (design §9). */
84
+ export declare function renderLightWorkspaceRules(light: NonNullable<WorkerProtocolFooterInput['light']>): string[];
85
+ /** Base-node code changes land on the branch the coordinator and review expect: the one already checked out. */
86
+ export declare const WORKER_CURRENT_BRANCH_RULE: string;
57
87
  export declare function hasWorkerProtocolFooter(body: string): boolean;
58
88
  /**
59
89
  * The protocol block appended to a dispatched task. Written for the model that
@@ -61,6 +91,8 @@ export declare function hasWorkerProtocolFooter(body: string): boolean;
61
91
  * the worker does not go looking for coordinator tools.
62
92
  */
63
93
  export declare function renderWorkerProtocolFooter(input?: WorkerProtocolFooterInput): string;
94
+ /** The stage-pipeline paragraph of the worker footer (implement / revise / review). */
95
+ export declare function renderStageProtocolLines(stage: NonNullable<WorkerProtocolFooterInput['stage']>): string[];
64
96
  /**
65
97
  * The authored text of a dispatched body: everything before the footer marker.
66
98
  * Ledger descriptors, replay fixtures and tests compare authored text, never
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/mesh-shared",
3
- "version": "1.0.82-rc.5",
3
+ "version": "1.0.82-rc.50",
4
4
  "description": "ADHDev mesh-shared — pure mesh/git status normalizers shared by daemon-core and web-core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,22 +11,36 @@
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 = [
20
19
  'projects',
20
+ 'environment',
21
+ 'assistant_action',
22
+ 'project_watch',
21
23
  'project_status',
22
24
  'project_send',
23
25
  'project_read',
24
26
  'project_add',
27
+ 'project_attach_remote',
25
28
  'discover_repos',
26
29
  'memory',
30
+ 'memory_search',
27
31
  'skill_view',
28
32
  'skill_manage',
29
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',
30
44
  ] as const
31
45
 
32
46
  export type AssistantTool = typeof ASSISTANT_TOOLS[number]
@@ -40,16 +54,38 @@ export function isAssistantTool(value: unknown): value is AssistantTool {
40
54
  /** Daemon verb names (§4.4 table + the five verbs below it). */
41
55
  export const ASSISTANT_VERB = {
42
56
  // tool verbs
57
+ driverList: 'driver_list',
58
+ driverDescribe: 'driver_describe',
43
59
  projects: 'assistant_projects',
60
+ environment: 'assistant_environment',
61
+ action: 'assistant_action',
62
+ watch: 'assistant_project_watch',
63
+ executionState: 'assistant_execution_state',
64
+ executionSettings: 'assistant_execution_settings',
44
65
  projectStatus: 'assistant_project_status',
45
66
  projectSend: 'assistant_project_send',
46
67
  projectRead: 'assistant_project_read',
47
68
  projectAdd: 'assistant_project_add',
69
+ projectAttachRemote: 'assistant_project_attach_remote',
48
70
  discoverRepos: 'assistant_discover_repos',
49
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',
50
74
  skillView: 'assistant_skill_view',
51
75
  skillManage: 'assistant_skill_manage',
52
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',
53
89
  // assistant-side daemon verbs without a tool of the same name
54
90
  launch: 'launch_assistant',
55
91
  pendingRelays: 'assistant_pending_relays',
@@ -57,22 +93,46 @@ export const ASSISTANT_VERB = {
57
93
  stagedResolve: 'assistant_staged_resolve',
58
94
  storeAdmin: 'assistant_store_admin',
59
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',
60
105
  } as const
61
106
 
62
107
  export type AssistantVerb = typeof ASSISTANT_VERB[keyof typeof ASSISTANT_VERB]
63
108
 
64
109
  /** The daemon verb each assistant tool calls. */
65
110
  export const ASSISTANT_TOOL_VERBS: Readonly<Record<AssistantTool, AssistantVerb>> = {
111
+ driver_list: ASSISTANT_VERB.driverList,
112
+ driver_describe: ASSISTANT_VERB.driverDescribe,
66
113
  projects: ASSISTANT_VERB.projects,
114
+ environment: ASSISTANT_VERB.environment,
115
+ assistant_action: ASSISTANT_VERB.action,
116
+ project_watch: ASSISTANT_VERB.watch,
67
117
  project_status: ASSISTANT_VERB.projectStatus,
68
118
  project_send: ASSISTANT_VERB.projectSend,
69
119
  project_read: ASSISTANT_VERB.projectRead,
70
120
  project_add: ASSISTANT_VERB.projectAdd,
121
+ project_attach_remote: ASSISTANT_VERB.projectAttachRemote,
71
122
  discover_repos: ASSISTANT_VERB.discoverRepos,
72
123
  memory: ASSISTANT_VERB.memory,
124
+ memory_search: ASSISTANT_VERB.memorySearch,
73
125
  skill_view: ASSISTANT_VERB.skillView,
74
126
  skill_manage: ASSISTANT_VERB.skillManage,
75
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,
76
136
  }
77
137
 
78
138
  /**
@@ -81,25 +141,32 @@ export const ASSISTANT_TOOL_VERBS: Readonly<Record<AssistantTool, AssistantVerb>
81
141
  * because they cause effects (a coordinator message or launch, a new
82
142
  * project), and MCP clients use readOnlyHint to skip confirmation.
83
143
  */
84
- export const ASSISTANT_WRITE_TOOLS: readonly AssistantTool[] = ['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']
85
145
 
86
146
  /** Owner-only verbs: never reachable from the assistant's MCP server (no `ipc`). */
87
147
  export const ASSISTANT_OWNER_VERBS: readonly AssistantVerb[] = [
148
+ ASSISTANT_VERB.executionSettings,
88
149
  ASSISTANT_VERB.stagedResolve,
89
150
  ASSISTANT_VERB.storeAdmin,
90
151
  ASSISTANT_VERB.importSkills,
152
+ ASSISTANT_VERB.skillsList,
153
+ ASSISTANT_VERB.memoryDigest,
154
+ ASSISTANT_VERB.memoryUndo,
155
+ ASSISTANT_VERB.threadClose,
91
156
  ]
92
157
 
93
158
  /** The only assistant verbs accepted while an idle review turn is open (§4.10.7). */
94
159
  export const ASSISTANT_REVIEW_TURN_VERBS: readonly AssistantVerb[] = [
95
160
  ASSISTANT_VERB.memory,
161
+ ASSISTANT_VERB.memorySearch,
96
162
  ASSISTANT_VERB.skillView,
97
163
  ASSISTANT_VERB.skillManage,
98
164
  ASSISTANT_VERB.projectNote,
99
165
  ]
100
166
 
101
- /**
102
- * 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
103
170
  * assistant MCP server and forwarded on every verb as
104
171
  * `ASSISTANT_SESSION_ID_ARG`. Routing / ownership only — never an auth gate.
105
172
  */
@@ -107,3 +174,236 @@ export const ASSISTANT_SESSION_ID_ENV = 'ADHDEV_ASSISTANT_SESSION_ID'
107
174
 
108
175
  /** Request arg carrying the calling assistant session id. */
109
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,4 +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'
49
+ export * from './provider-approval'
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'
@@ -326,7 +326,15 @@ export function foldKeyedDoc<T extends Record<string, unknown>>(held: T, delta:
326
326
  const heldList = heldCollections.get(path)
327
327
  if (change?.absent) {
328
328
  const [head, tail] = splitPath(path)
329
- if (!tail) delete next[head]
329
+ if (!tail) {
330
+ delete next[head]
331
+ continue
332
+ }
333
+ const parent = next[head]
334
+ if (!isRecord(parent) || !(tail in parent)) continue
335
+ const copy = { ...parent }
336
+ delete copy[tail]
337
+ next[head] = copy
330
338
  continue
331
339
  }
332
340
  if (!change && heldList === undefined) continue