@dxos/compute 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/lib/AiMetering.mjs +1 -0
  2. package/dist/lib/Hook.mjs +1 -0
  3. package/dist/lib/Operation.mjs +3 -3
  4. package/dist/lib/Process.mjs +2 -2
  5. package/dist/lib/Trace.mjs +1 -1
  6. package/dist/lib/chunk-AgentIdentity.mjs +1 -1
  7. package/dist/lib/chunk-AgentService.mjs.map +1 -1
  8. package/dist/lib/chunk-AiMetering.mjs +77 -0
  9. package/dist/lib/chunk-AiMetering.mjs.map +1 -0
  10. package/dist/lib/chunk-Cancellation.mjs +1 -1
  11. package/dist/lib/chunk-Hook.mjs +78 -0
  12. package/dist/lib/chunk-Hook.mjs.map +1 -0
  13. package/dist/lib/chunk-Instructions.mjs +1 -1
  14. package/dist/lib/chunk-Operation.mjs +169 -5
  15. package/dist/lib/chunk-Operation.mjs.map +1 -1
  16. package/dist/lib/chunk-OperationHandlerSet.mjs +1 -1
  17. package/dist/lib/chunk-OperationRegistry.mjs +1 -1
  18. package/dist/lib/chunk-OperationRegistry.mjs.map +1 -1
  19. package/dist/lib/chunk-Process.mjs +18 -10
  20. package/dist/lib/chunk-Process.mjs.map +1 -1
  21. package/dist/lib/chunk-Project.mjs +52 -24
  22. package/dist/lib/chunk-Project.mjs.map +1 -1
  23. package/dist/lib/chunk-Reducer.mjs +827 -0
  24. package/dist/lib/chunk-Reducer.mjs.map +1 -0
  25. package/dist/lib/chunk-Routine.mjs +1 -1
  26. package/dist/lib/chunk-Runnable.mjs +1 -1
  27. package/dist/lib/chunk-ServiceResolver.mjs +1 -1
  28. package/dist/lib/chunk-Skill.mjs +10 -47
  29. package/dist/lib/chunk-Skill.mjs.map +1 -1
  30. package/dist/lib/chunk-Spec.mjs +49 -0
  31. package/dist/lib/chunk-Spec.mjs.map +1 -0
  32. package/dist/lib/chunk-SpecReview.mjs +98 -0
  33. package/dist/lib/chunk-SpecReview.mjs.map +1 -0
  34. package/dist/lib/chunk-SqlService.mjs.map +1 -1
  35. package/dist/lib/chunk-StorageService.mjs +1 -1
  36. package/dist/lib/chunk-Template.mjs +2 -2
  37. package/dist/lib/chunk-Trace.mjs +97 -13
  38. package/dist/lib/chunk-Trace.mjs.map +1 -1
  39. package/dist/lib/chunk-Trajectory.mjs +326 -0
  40. package/dist/lib/chunk-Trajectory.mjs.map +1 -0
  41. package/dist/lib/chunk-Transcript.mjs +84 -0
  42. package/dist/lib/chunk-Transcript.mjs.map +1 -0
  43. package/dist/lib/chunk-definitions.mjs +1 -1
  44. package/dist/lib/errors.mjs +3 -1
  45. package/dist/lib/errors.mjs.map +1 -1
  46. package/dist/lib/index.mjs +14 -8
  47. package/dist/lib/testing.mjs +2 -2
  48. package/dist/lib/trajectory/Reducer.mjs +1 -0
  49. package/dist/lib/trajectory/Trajectory.mjs +1 -0
  50. package/dist/lib/trajectory/Transcript.mjs +1 -0
  51. package/dist/lib/types/Project.mjs +1 -1
  52. package/dist/lib/types/Skill.mjs +1 -1
  53. package/dist/lib/types/Spec.mjs +1 -0
  54. package/dist/lib/types/SpecReview.mjs +1 -0
  55. package/dist/types/src/AgentService.d.ts +9 -0
  56. package/dist/types/src/AgentService.d.ts.map +1 -1
  57. package/dist/types/src/AiMetering.d.ts +23 -0
  58. package/dist/types/src/AiMetering.d.ts.map +1 -0
  59. package/dist/types/src/AiMetering.test.d.ts +2 -0
  60. package/dist/types/src/AiMetering.test.d.ts.map +1 -0
  61. package/dist/types/src/Hook.d.ts +84 -0
  62. package/dist/types/src/Hook.d.ts.map +1 -0
  63. package/dist/types/src/Hook.test.d.ts +2 -0
  64. package/dist/types/src/Hook.test.d.ts.map +1 -0
  65. package/dist/types/src/Operation.d.ts +276 -2
  66. package/dist/types/src/Operation.d.ts.map +1 -1
  67. package/dist/types/src/Process.d.ts +26 -4
  68. package/dist/types/src/Process.d.ts.map +1 -1
  69. package/dist/types/src/Script.test.d.ts +2 -0
  70. package/dist/types/src/Script.test.d.ts.map +1 -0
  71. package/dist/types/src/Trace.d.ts +103 -1
  72. package/dist/types/src/Trace.d.ts.map +1 -1
  73. package/dist/types/src/errors.d.ts +30 -0
  74. package/dist/types/src/errors.d.ts.map +1 -1
  75. package/dist/types/src/index.d.ts +3 -1
  76. package/dist/types/src/index.d.ts.map +1 -1
  77. package/dist/types/src/trajectory/Reducer.d.ts +191 -0
  78. package/dist/types/src/trajectory/Reducer.d.ts.map +1 -0
  79. package/dist/types/src/trajectory/Reducer.test.d.ts +2 -0
  80. package/dist/types/src/trajectory/Reducer.test.d.ts.map +1 -0
  81. package/dist/types/src/trajectory/Trajectory.d.ts +3211 -0
  82. package/dist/types/src/trajectory/Trajectory.d.ts.map +1 -0
  83. package/dist/types/src/trajectory/Trajectory.test.d.ts +2 -0
  84. package/dist/types/src/trajectory/Trajectory.test.d.ts.map +1 -0
  85. package/dist/types/src/trajectory/Transcript.d.ts +40 -0
  86. package/dist/types/src/trajectory/Transcript.d.ts.map +1 -0
  87. package/dist/types/src/trajectory/index.d.ts +4 -0
  88. package/dist/types/src/trajectory/index.d.ts.map +1 -0
  89. package/dist/types/src/trajectory/light-threads.test.d.ts +2 -0
  90. package/dist/types/src/trajectory/light-threads.test.d.ts.map +1 -0
  91. package/dist/types/src/trajectory/samples.test.d.ts +2 -0
  92. package/dist/types/src/trajectory/samples.test.d.ts.map +1 -0
  93. package/dist/types/src/types/Project.d.ts +11 -12
  94. package/dist/types/src/types/Project.d.ts.map +1 -1
  95. package/dist/types/src/types/Skill.d.ts +6 -51
  96. package/dist/types/src/types/Skill.d.ts.map +1 -1
  97. package/dist/types/src/types/Spec.d.ts +26 -0
  98. package/dist/types/src/types/Spec.d.ts.map +1 -0
  99. package/dist/types/src/types/SpecReview.d.ts +76 -0
  100. package/dist/types/src/types/SpecReview.d.ts.map +1 -0
  101. package/dist/types/src/types/index.d.ts +2 -0
  102. package/dist/types/src/types/index.d.ts.map +1 -1
  103. package/dist/types/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +59 -26
  105. package/src/AgentService.ts +9 -0
  106. package/src/AiMetering.test.ts +89 -0
  107. package/src/AiMetering.ts +93 -0
  108. package/src/Hook.test.ts +75 -0
  109. package/src/Hook.ts +154 -0
  110. package/src/Operation.test.ts +23 -0
  111. package/src/Operation.ts +334 -0
  112. package/src/Process.ts +33 -6
  113. package/src/Script.test.ts +74 -0
  114. package/src/Trace.ts +97 -4
  115. package/src/errors.ts +3 -0
  116. package/src/index.ts +3 -1
  117. package/src/trajectory/Reducer.test.ts +575 -0
  118. package/src/trajectory/Reducer.ts +1026 -0
  119. package/src/trajectory/Trajectory.test.ts +114 -0
  120. package/src/trajectory/Trajectory.ts +440 -0
  121. package/src/trajectory/Transcript.ts +113 -0
  122. package/src/trajectory/index.ts +7 -0
  123. package/src/trajectory/light-threads.test.ts +310 -0
  124. package/src/trajectory/samples.test.ts +285 -0
  125. package/src/types/Project.test.ts +2 -1
  126. package/src/types/Project.ts +43 -27
  127. package/src/types/Skill.ts +6 -61
  128. package/src/types/Spec.ts +68 -0
  129. package/src/types/SpecReview.ts +98 -0
  130. package/src/types/index.ts +2 -0
  131. package/dist/lib/McpServer.mjs +0 -1
  132. package/dist/lib/chunk-McpServer.mjs +0 -124
  133. package/dist/lib/chunk-McpServer.mjs.map +0 -1
  134. package/dist/types/src/McpServer.d.ts +0 -113
  135. package/dist/types/src/McpServer.d.ts.map +0 -1
  136. package/src/McpServer.ts +0 -142
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-Reducer.mjs","names":["Trajectory.threadOf","Transcript.snapshot","Trajectory.EventId","Trajectory.ThreadId","Trajectory.ThreadMode","Trajectory.Sender","Trajectory.MergeMode","Trajectory.Role","Trajectory.ThreadOrigin"],"sources":["../../src/trajectory/Reducer.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as HashMap from 'effect/HashMap';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaTransformation from 'effect/SchemaTransformation';\n\nimport { type Obj, type Ref } from '@dxos/echo';\nimport { ContentBlock } from '@dxos/types';\n\nimport * as Trajectory from './Trajectory.ts';\nimport * as Transcript from './Transcript.ts';\n\n/**\n * A left fold over events in feed order; every view of a trajectory is one of these, so state after `n + k` events\n * is `step` applied `k` times to the state after `n`, and a reader never has to start from the first event.\n */\nexport interface Reducer<S> {\n readonly initial: S;\n readonly step: (state: S, event: Trajectory.Event) => S;\n /**\n * Folds a batch at once, equal to stepping each event; lets a reducer copy its state once per batch rather than once\n * per event, which keeps a long fold linear. The state passed in is never modified.\n */\n readonly fold?: (state: S, events: readonly Trajectory.Event[]) => S;\n}\n\n/**\n * Reducer state after the event `head`; a cache that is always safe to drop, since replaying from the start\n * rebuilds it exactly.\n */\nexport type Checkpoint<S> = {\n readonly state: S;\n readonly head?: Trajectory.EventId;\n /** Events folded so far. */\n readonly count: number;\n};\n\n/**\n * Folds `events` (the tail after `from.head`) onto a checkpoint, or onto the initial state.\n * Fold in local order (`Feed.getLocalCursor`): it never changes under a reader, so a checkpoint stays valid as sync\n * repositions the feed.\n */\nexport const run = <S>(\n reducer: Reducer<S>,\n events: Iterable<Trajectory.Event>,\n from?: Checkpoint<S>,\n): Checkpoint<S> => {\n const batch = [...events];\n const initial = from?.state ?? reducer.initial;\n const state = reducer.fold\n ? reducer.fold(initial, batch)\n : batch.reduce((next, event) => reducer.step(next, event), initial);\n return { state, head: batch.at(-1)?.id ?? from?.head, count: (from?.count ?? 0) + batch.length };\n};\n\n//\n// Session state: what the agent process needs to decide its next step.\n//\n\nexport type Alarm = { readonly id: Trajectory.EventId; readonly wakeAt: number; readonly message?: string };\n\nexport type BackgroundTool = { readonly toolCallId: string; readonly pid?: string };\n\nexport type ThreadStatus = 'open' | 'merged' | Trajectory.ThreadStatus;\n\nexport type ThreadInfo = {\n readonly id: Trajectory.ThreadId;\n readonly mode: Trajectory.ThreadMode;\n readonly status: ThreadStatus;\n};\n\ntype SkillRef = Trajectory.ContextBind['skills'][number];\ntype ObjectRef = Trajectory.ContextBind['objects'][number];\n\nexport type SessionState = {\n /** User messages no `promptConsume` or `promptCancel` has named yet, oldest first. */\n readonly queue: readonly Trajectory.EventId[];\n readonly alarms: readonly Alarm[];\n readonly skills: readonly SkillRef[];\n readonly objects: readonly ObjectRef[];\n readonly background: readonly BackgroundTool[];\n readonly threads: readonly ThreadInfo[];\n readonly model?: Trajectory.ModelChange['model'];\n /** `turnBegin`s of turns that have not ended; more than one when several writers run turns at once. */\n readonly turns: readonly Trajectory.ThreadId[];\n /**\n * `promptConsume`s and `promptCancel`s whose message was no longer queued, because another writer consumed or\n * cancelled it first; a harness claims a message by writing its consume and runs only if that consume is not listed\n * here.\n */\n readonly rejected: readonly Trajectory.EventId[];\n /** Alarms fired since the last prompt a person typed: the count a harness caps self-wakes at. */\n readonly selfWakes: number;\n};\n\n/** Whether a message is a prompt a person typed, which ends a run of self-wakes. */\nconst isTypedPrompt = (event: Trajectory.Event, payload: Trajectory.Message): boolean =>\n event.sender.role === 'user' &&\n payload.blocks.some((block) => block._tag === 'text' && block.disposition !== 'synthetic');\n\nconst bind = <T extends { uri: string }>(current: readonly T[], added: readonly T[]): readonly T[] =>\n added.reduce<readonly T[]>(\n (refs, ref) => (refs.some((existing) => existing.uri === ref.uri) ? refs : [...refs, ref]),\n current,\n );\n\nconst unbind = <T extends { uri: string }>(current: readonly T[], removed: readonly T[]): readonly T[] =>\n current.filter((ref) => !removed.some((other) => other.uri === ref.uri));\n\nconst threadOf = Trajectory.threadOf;\n\n/** `ids` with the thread an opener opens; an opener not yet on a branch (unwritten) opens nothing. */\nconst withThread = (ids: readonly Trajectory.ThreadId[], id: Trajectory.ThreadId | undefined) =>\n id === undefined ? ids : [...ids, id];\n\nconst withOpened = (state: SessionState, id: Trajectory.ThreadId | undefined, mode: Trajectory.ThreadMode) =>\n id === undefined ? state : { ...state, threads: [...state.threads, { id, mode, status: 'open' as const }] };\n\nconst setThreadStatus = (threads: readonly ThreadInfo[], id: Trajectory.ThreadId | undefined, status: ThreadStatus) =>\n threads.map((thread) => (thread.id === id ? { ...thread, status } : thread));\n\nconst sessionFold: Reducer<SessionState> = {\n initial: {\n queue: [],\n alarms: [],\n skills: [],\n objects: [],\n background: [],\n threads: [],\n turns: [],\n rejected: [],\n selfWakes: 0,\n },\n step: (state, event) => {\n const payload = event.payload;\n switch (payload._tag) {\n case 'message':\n return event.sender.role === 'user'\n ? {\n ...state,\n queue: [...state.queue, event.id],\n selfWakes: isTypedPrompt(event, payload) ? 0 : state.selfWakes,\n }\n : state;\n case 'promptConsume':\n case 'promptCancel':\n return state.queue.includes(payload.message)\n ? { ...state, queue: state.queue.filter((id) => id !== payload.message) }\n : { ...state, rejected: [...state.rejected, event.id] };\n case 'turnBegin':\n return {\n ...state,\n turns: withThread(state.turns, threadOf(event)),\n model: payload.model ?? state.model,\n };\n case 'turnEnd':\n return { ...state, turns: state.turns.filter((id) => id !== threadOf(event)) };\n case 'modelChange':\n return { ...state, model: payload.model };\n case 'contextBind':\n return { ...state, skills: bind(state.skills, payload.skills), objects: bind(state.objects, payload.objects) };\n case 'contextUnbind':\n return {\n ...state,\n skills: unbind(state.skills, payload.skills),\n objects: unbind(state.objects, payload.objects),\n };\n case 'alarmSet':\n return {\n ...state,\n alarms: [...state.alarms, { id: event.id, wakeAt: payload.wakeAt, message: payload.message }],\n };\n case 'alarmCancel':\n return { ...state, alarms: state.alarms.filter((alarm) => alarm.id !== payload.alarm) };\n case 'alarmFire':\n return {\n ...state,\n alarms: state.alarms.filter((alarm) => alarm.id !== payload.alarm),\n selfWakes: state.selfWakes + 1,\n };\n case 'toolBackground':\n return { ...state, background: [...state.background, { toolCallId: payload.toolCallId, pid: payload.pid }] };\n case 'toolDeliver':\n return { ...state, background: state.background.filter((tool) => tool.toolCallId !== payload.toolCallId) };\n case 'threadOpen':\n return withOpened(state, threadOf(event), payload.mode);\n case 'threadMerge':\n return { ...state, threads: setThreadStatus(state.threads, threadOf(event), 'merged') };\n case 'threadClose':\n return { ...state, threads: setThreadStatus(state.threads, threadOf(event), payload.status) };\n default:\n return state;\n }\n },\n};\n\n//\n// Thread view: what the UI renders.\n//\n\n/** `rewound`: discarded by a rewind; kept so a reader can tell a message it already showed from a new one. */\nexport type ItemStatus = 'queued' | 'consumed' | 'cancelled' | 'sent' | 'rewound';\n\nexport type ThreadItem = {\n readonly id: Trajectory.EventId;\n readonly sender: Trajectory.Sender;\n readonly blocks: readonly ContentBlock.Any[];\n readonly created: string;\n /** Thread the message was written in; absent for the main thread. */\n readonly thread?: Trajectory.ThreadId;\n /** The lane the message belongs to: the top-level thread or turn its thread nests in; absent outside any. */\n readonly lane?: Trajectory.ThreadId;\n readonly status: ItemStatus;\n};\n\nexport type LaneStatus = 'running' | 'waiting' | 'done' | 'failed';\n\n/**\n * One top-level unit of work: a light (or other) thread opened on main, or a turn that runs on main. Several lanes\n * running at once are what the chat shows side by side.\n */\nexport type Lane = {\n readonly id: Trajectory.ThreadId;\n readonly kind: 'turn' | Trajectory.ThreadMode;\n readonly status: LaneStatus;\n readonly owner: Trajectory.Sender;\n readonly created: string;\n readonly purpose?: string;\n /** The lane this one is waiting for (`threadWait`). */\n readonly waitingOn?: Trajectory.ThreadId;\n /** Whether another lane was running at some point while this one was. */\n readonly overlapped?: boolean;\n /**\n * Whether a newer lane of the same owner opened while this one ran: the reader moved on to the newer request, so\n * this one works in the background from then on. Another owner's lane does not background it; agents talking to the\n * reader at once stay side by side. A delegated subagent (a `fresh` thread on main) is in the background from the\n * start.\n */\n readonly backgrounded?: boolean;\n /** A fork's fork point: the message of main it forks at. */\n readonly from?: Trajectory.EventId;\n /** How a person merged a fork into main: its whole work (`raw`), or its conclusion (`summary`). */\n readonly merged?: Trajectory.MergeMode;\n};\n\nexport type ThreadView = {\n readonly items: readonly ThreadItem[];\n /** In the order they opened. */\n readonly lanes: readonly Lane[];\n /** The lane of every thread and turn opened so far. */\n readonly laneOf: Readonly<Record<Trajectory.ThreadId, Trajectory.ThreadId>>;\n};\n\n/** `blocks` with the request the resolution answers settled; a request already settled keeps its first answer. */\nconst resolveRequest = (\n blocks: readonly ContentBlock.Any[],\n { requestId, resolution }: Trajectory.RequestResolve,\n): readonly ContentBlock.Any[] =>\n blocks.map((block) =>\n block._tag === 'request' && block.requestId === requestId && block.resolution === undefined\n ? { ...block, resolution }\n : block,\n );\n\ntype MutableView = {\n items: ThreadItem[];\n lanes: Lane[];\n laneOf: Record<Trajectory.ThreadId, Trajectory.ThreadId>;\n /** Where each lane is in `lanes`: every turn is a lane, so a search per update would make a fold quadratic. */\n laneIndex: Map<Trajectory.ThreadId, number>;\n /** The lanes still running or waiting, so opening a lane does not scan every lane. */\n running: Set<Trajectory.ThreadId>;\n};\n\nconst isRunning = (lane: Lane) => lane.status === 'running' || lane.status === 'waiting';\n\nconst updateLane = (view: MutableView, id: Trajectory.ThreadId | undefined, update: (lane: Lane) => Lane): boolean => {\n const index = id === undefined ? undefined : view.laneIndex.get(id);\n if (index === undefined) {\n return false;\n }\n const lane = update(view.lanes[index]);\n view.lanes[index] = lane;\n if (isRunning(lane)) {\n view.running.add(lane.id);\n } else {\n view.running.delete(lane.id);\n }\n return true;\n};\n\n/** Records a thread or turn opening: a lane of its own on main, or a member of its parent's lane. */\nconst openLane = (\n view: MutableView,\n event: Trajectory.Event,\n parent: Trajectory.ThreadId | undefined,\n lane: Omit<Lane, 'id' | 'status' | 'owner' | 'created'>,\n): boolean => {\n const id = threadOf(event);\n if (id === undefined) {\n return false;\n }\n if (parent !== undefined) {\n const parentLane = view.laneOf[parent];\n if (parentLane !== undefined) {\n view.laneOf[id] = parentLane;\n // A lane that runs another turn (after a wait, or for a queued prompt) is running again.\n updateLane(view, parentLane, (existing) => ({ ...existing, status: 'running', waitingOn: undefined }));\n }\n return parentLane !== undefined;\n }\n // A fork runs apart from main, so it neither overlaps the lanes on main nor sends them to the background.\n const running = (lane.kind === 'fork' ? [] : [...view.running]).flatMap((id) => {\n const index = view.laneIndex.get(id);\n return index === undefined ? [] : [view.lanes[index]];\n });\n for (const other of running) {\n const sameOwner = other.owner.name === event.sender.name;\n updateLane(view, other.id, (existing) => ({\n ...existing,\n overlapped: true,\n ...(sameOwner ? { backgrounded: true } : {}),\n }));\n }\n view.laneOf[id] = id;\n view.laneIndex.set(id, view.lanes.length);\n view.running.add(id);\n view.lanes.push({\n id,\n status: 'running',\n owner: event.sender,\n created: event.created,\n ...lane,\n ...(running.length > 0 ? { overlapped: true } : {}),\n // A fresh thread on main is a delegated subagent: the reader never asked it anything, so it works out of view.\n ...(lane.kind === 'fresh' ? { backgrounded: true } : {}),\n });\n return true;\n};\n\nconst laneOfThread = (view: MutableView, thread: Trajectory.ThreadId | undefined) =>\n thread === undefined ? undefined : view.laneOf[thread];\n\n/** Applies one event to the view, in place; `false` when the event leaves the view as it was. */\nconst applyThread = (view: MutableView, event: Trajectory.Event): boolean => {\n const items = view.items;\n const payload = event.payload;\n switch (payload._tag) {\n case 'message': {\n const lane = laneOfThread(view, threadOf(event));\n items.push({\n id: event.id,\n sender: event.sender,\n blocks: payload.blocks,\n created: event.created,\n thread: threadOf(event),\n ...(lane !== undefined ? { lane } : {}),\n status: event.sender.role === 'user' ? 'queued' : 'sent',\n });\n // A message after a wait means the lane is working again.\n updateLane(view, lane, (existing) =>\n existing.status === 'waiting' ? { ...existing, status: 'running', waitingOn: undefined } : existing,\n );\n return true;\n }\n case 'turnBegin':\n return openLane(view, event, payload.from?.thread, { kind: 'turn' });\n case 'threadOpen':\n return openLane(view, event, payload.from?.feed ? undefined : payload.from?.thread, {\n kind: payload.mode,\n ...(payload.mode === 'fork' && payload.from !== undefined ? { from: payload.from.event } : {}),\n ...(payload.purpose !== undefined ? { purpose: payload.purpose } : {}),\n });\n case 'turnEnd': {\n // A turn that is its own lane ends it; a turn inside a thread leaves the thread to its merge or close, except\n // in a fork, which rests between its turns because nothing merges it on its own.\n const turn = threadOf(event);\n const lane = laneOfThread(view, turn);\n const laneIndex = lane === undefined ? undefined : view.laneIndex.get(lane);\n if (turn !== undefined && lane !== turn && laneIndex !== undefined && view.lanes[laneIndex].kind === 'fork') {\n return updateLane(view, lane, (existing) => ({ ...existing, status: 'done', waitingOn: undefined }));\n }\n return turn !== undefined && view.laneOf[turn] === turn\n ? updateLane(view, turn, (lane) => ({\n ...lane,\n status: payload.finishReason === 'error' ? 'failed' : 'done',\n waitingOn: undefined,\n }))\n : false;\n }\n case 'threadMerge': {\n const thread = threadOf(event);\n const index = thread === undefined ? undefined : view.laneIndex.get(thread);\n if (thread === undefined || index === undefined || view.lanes[index].kind !== 'fork') {\n return thread !== undefined && view.laneOf[thread] === thread\n ? updateLane(view, thread, (lane) => ({ ...lane, status: 'done', waitingOn: undefined }))\n : false;\n }\n // A fork joins main only when a person merges it, so main shows the merge: its conclusion as one message.\n const fork = view.lanes[index];\n if (payload.mode === 'summary') {\n items.push({\n id: event.id,\n sender: { role: 'assistant', name: fork.purpose ?? 'fork' },\n blocks: payload.summary ?? [],\n created: event.created,\n status: 'sent',\n });\n }\n return updateLane(view, thread, (lane) => ({\n ...lane,\n status: 'done',\n merged: payload.mode,\n waitingOn: undefined,\n }));\n }\n case 'threadClose': {\n const failed = payload.status !== 'completed';\n const thread = threadOf(event);\n return thread !== undefined && view.laneOf[thread] === thread\n ? updateLane(view, thread, (lane) => ({\n ...lane,\n status: failed ? 'failed' : 'done',\n waitingOn: undefined,\n }))\n : false;\n }\n case 'threadWait':\n return updateLane(view, laneOfThread(view, threadOf(event)), (lane) => ({\n ...lane,\n status: 'waiting',\n waitingOn: view.laneOf[payload.on] ?? payload.on,\n }));\n case 'promptConsume': {\n // A second consume of the same message lost the claim, so the message stays where the first one put it.\n const index = items.findLastIndex((item) => item.id === payload.message && item.status === 'queued');\n if (index === -1) {\n return false;\n }\n const [item] = items.splice(index, 1);\n const lane = laneOfThread(view, threadOf(event));\n items.push({ ...item, thread: threadOf(event), ...(lane !== undefined ? { lane } : {}), status: 'consumed' });\n return true;\n }\n case 'requestResolve': {\n const index = items.findLastIndex((item) => item.id === payload.message);\n if (index === -1) {\n return false;\n }\n items[index] = { ...items[index], blocks: resolveRequest(items[index].blocks, payload) };\n return true;\n }\n case 'rewind': {\n const from = threadOf(event) === undefined ? items.findIndex((item) => item.id === payload.from) : -1;\n for (let index = Math.max(from, 0); from !== -1 && index < items.length; index++) {\n if (items[index].status !== 'queued') {\n items[index] = { ...items[index], status: 'rewound' };\n }\n }\n return from !== -1;\n }\n case 'promptCancel': {\n const index = items.findLastIndex((item) => item.id === payload.message && item.status === 'queued');\n if (index === -1) {\n return false;\n }\n items[index] = { ...items[index], status: 'cancelled' };\n return true;\n }\n default:\n return false;\n }\n};\n\n/**\n * Every message, including turn threads still streaming; a user message moves to where it is consumed, the position\n * the model sees it at, and joins the consuming turn's thread. A consume or cancel whose message lies outside the loaded window is ignored, so the UI can\n * fold just the tail of a long conversation.\n */\nconst foldThread = (state: ThreadView, events: readonly Trajectory.Event[]): ThreadView => {\n const view: MutableView = {\n items: [...state.items],\n lanes: [...state.lanes],\n laneOf: { ...state.laneOf },\n laneIndex: new Map(state.lanes.map((lane, index) => [lane.id, index])),\n running: new Set(state.lanes.filter(isRunning).map((lane) => lane.id)),\n };\n let changed = false;\n for (const event of events) {\n changed = applyThread(view, event) || changed;\n }\n return changed ? { items: view.items, lanes: view.lanes, laneOf: view.laneOf } : state;\n};\n\nconst threadFold: Reducer<ThreadView> = {\n initial: { items: [], lanes: [], laneOf: {} },\n step: (state, event) => foldThread(state, [event]),\n fold: foldThread,\n};\n\n//\n// Prompt: what the session process sends to the model.\n//\n\nexport type PromptEntry = {\n readonly role: Trajectory.Role;\n /** The sender's name, which lets the model tell several people (or sources) apart. */\n readonly name?: string;\n readonly blocks: readonly ContentBlock.Any[];\n /** Events this entry was built from, so a later `compact` can find its range. */\n readonly source: readonly Trajectory.EventId[];\n /** Feed position of the event that placed the entry in its current buffer. */\n readonly at: number;\n /** A light thread's snapshot of the threads running beside it; dropped when the thread merges. */\n readonly ephemeral?: boolean;\n};\n\n/**\n * Entries written in an open thread or turn, merged into `parent` (absent: main) when it ends.\n */\nexport type ThreadBuffer = {\n readonly parent?: Trajectory.ThreadId;\n /** How the thread opened; absent for a turn. The session engine's merge policy is per mode. */\n readonly mode?: Trajectory.ThreadMode;\n /** A fresh thread's prompt is its own entries only; a fork's starts with its parent's. */\n readonly fresh: boolean;\n /**\n * Feed position of the last event the thread saw when it opened (its `from.event`); parent entries placed later\n * were written concurrently and are not in its prompt.\n */\n readonly seen: number;\n /** Merged or closed while a child was still open; kept, frozen, so the child's prompt does not change under it. */\n readonly closed?: boolean;\n /** Title and owner a light thread's siblings see it by. */\n readonly purpose?: string;\n readonly owner?: string;\n readonly entries: readonly PromptEntry[];\n};\n\nexport type PromptState = {\n /** The main thread's prompt; only appended to, except by `compact`. */\n readonly entries: readonly PromptEntry[];\n /** User messages waiting for a `promptConsume`. */\n readonly held: Readonly<Record<Trajectory.EventId, PromptEntry>>;\n readonly threads: Readonly<Record<Trajectory.ThreadId, ThreadBuffer>>;\n /** Events folded so far, which is the feed position of the next one. */\n readonly position: number;\n /** Feed position of every folded event, to resolve a `from.event`; persistent, since a copy per event is quadratic. */\n readonly positions: HashMap.HashMap<Trajectory.EventId, number>;\n /**\n * Threads and turns that merged into a parent holding entries they never saw, with those entries' source events.\n * The merge still happens; whether to accept, re-run or correct is the harness's call.\n */\n readonly stale: Readonly<Record<Trajectory.ThreadId, readonly Trajectory.EventId[]>>;\n /** Conversation this feed continues (`fork`); its prompt up to `origin.event` precedes `entries`. */\n readonly origin?: Trajectory.ThreadOrigin;\n};\n\nconst omit = <V>(record: Readonly<Record<string, V>>, key: string): Readonly<Record<string, V>> =>\n Object.fromEntries(Object.entries(record).filter(([other]) => other !== key));\n\n/**\n * Entry arrays the running `fold` created, which nothing outside it holds yet, so it may push to them instead of\n * copying; `undefined` outside a fold, where every append copies.\n */\nlet owned: WeakMap<readonly PromptEntry[], PromptEntry[]> | undefined;\n\nconst grow = (entries: readonly PromptEntry[], entry: PromptEntry): readonly PromptEntry[] => {\n const mutable = owned?.get(entries);\n if (mutable) {\n mutable.push(entry);\n return mutable;\n }\n const copy = [...entries, entry];\n owned?.set(copy, copy);\n return copy;\n};\n\nconst append = (\n state: PromptState,\n threadId: Trajectory.ThreadId | undefined,\n placed: Omit<PromptEntry, 'at'>,\n): PromptState => {\n const entry: PromptEntry = { ...placed, at: state.position };\n if (threadId === undefined) {\n return { ...state, entries: grow(state.entries, entry) };\n }\n\n const buffer = state.threads[threadId] ?? { fresh: false, seen: state.position, entries: [] };\n return { ...state, threads: { ...state.threads, [threadId]: { ...buffer, entries: grow(buffer.entries, entry) } } };\n};\n\n/**\n * Closes a thread, appending `entries` to its parent; a parent that has already ended stands in for main.\n * A fresh thread never saw its parent, so only a fork or turn can be stale.\n */\nconst mergeInto = (state: PromptState, threadId: Trajectory.ThreadId, entries: readonly Omit<PromptEntry, 'at'>[]) => {\n const buffer = live(state, threadId);\n const parent = buffer?.parent;\n const target = parent !== undefined && live(state, parent) ? parent : undefined;\n const unseen = buffer && !buffer.fresh ? placedAfter(promptFor(state, target), buffer.seen) : [];\n return entries\n .filter((entry) => !entry.ephemeral)\n .reduce<PromptState>((next, entry) => append(next, target, entry), {\n ...state,\n threads: end(state.threads, threadId),\n stale: unseen.length > 0 ? { ...state.stale, [threadId]: unseen } : state.stale,\n });\n};\n\n/**\n * Source events of the entries placed after `position`. A prompt's entries are in placement order (a compaction\n * summary takes its range's earliest position), so the scan stops at the first entry placed at or before it.\n */\nconst placedAfter = (entries: readonly PromptEntry[], position: number): Trajectory.EventId[] => {\n let first = entries.length;\n while (first > 0 && entries[first - 1].at > position) {\n first--;\n }\n return entries.slice(first).flatMap((entry) => entry.source);\n};\n\n/** A thread that is open and has not been merged or closed. */\nconst live = (state: PromptState, id: Trajectory.ThreadId) => {\n const buffer = state.threads[id];\n return buffer && !buffer.closed ? buffer : undefined;\n};\n\n/**\n * Removes an ended thread, or freezes it while a child still builds on it; a frozen parent goes once its last child\n * has ended.\n */\nconst end = (threads: PromptState['threads'], id: Trajectory.ThreadId): PromptState['threads'] => {\n const buffer = threads[id];\n if (!buffer) {\n return threads;\n }\n\n if (Object.values(threads).some((other) => other.parent === id)) {\n return { ...threads, [id]: { ...buffer, closed: true } };\n }\n\n const rest = omit(threads, id);\n const parent = buffer.parent === undefined ? undefined : rest[buffer.parent];\n return buffer.parent !== undefined && parent?.closed ? end(rest, buffer.parent) : rest;\n};\n\n/**\n * Feed position a thread with this origin saw up to; an origin this log does not hold (it cannot precede the\n * opener in local order) falls back to everything before the opener.\n */\nconst seenAt = (state: PromptState, origin?: Trajectory.ThreadOrigin) =>\n origin && !origin.feed\n ? Option.getOrElse(HashMap.get(state.positions, origin.event), () => state.position)\n : state.position;\n\n/**\n * What a fork sees: main as it stood once the message it forks at was in it. A message a turn wrote joins main when\n * the turn ends, after the message itself, so the fork sees up to where the message was placed.\n */\nconst forkSeen = (state: PromptState, from: Trajectory.ThreadOrigin | undefined): number => {\n const seen = seenAt(state, from);\n const placed = from === undefined ? undefined : state.entries.find((entry) => entry.source.includes(from.event));\n return placed === undefined ? seen : Math.max(seen, placed.at);\n};\n\nconst open = (state: PromptState, id: Trajectory.ThreadId | undefined, buffer: ThreadBuffer): PromptState =>\n id === undefined ? state : { ...state, threads: { ...state.threads, [id]: buffer } };\n\n/**\n * The prompt a turn in `thread` sends: its own entries after its parents', back to main, unless a fresh thread\n * cuts the chain.\n */\nexport const promptFor = (state: PromptState, thread?: Trajectory.ThreadId): readonly PromptEntry[] => {\n const buffer = thread === undefined ? undefined : state.threads[thread];\n if (!buffer) {\n return state.entries;\n }\n\n return buffer.fresh\n ? buffer.entries\n : [...promptFor(state, buffer.parent).filter((entry) => entry.at <= buffer.seen), ...buffer.entries];\n};\n\n/**\n * A thread's own entries and those of its open children, as a sibling sees them: placed at or before `seen`, in\n * placement order.\n */\nconst workOf = (state: PromptState, id: Trajectory.ThreadId, seen: number): PromptEntry[] => {\n const own = state.threads[id]?.entries ?? [];\n const children = Object.entries(state.threads).flatMap(([childId, buffer]) =>\n buffer.parent === id ? workOf(state, Trajectory.ThreadId.make(childId), seen) : [],\n );\n return [...own, ...children]\n .filter((entry) => entry.at <= seen && !entry.ephemeral)\n .sort((left, right) => left.at - right.at);\n};\n\n/** A turn's title when it has none of its own: the start of the request it answers. */\nconst titleOf = (entries: readonly PromptEntry[]): string | undefined => {\n const request = entries\n .find((entry) => entry.role === 'user')\n ?.blocks.flatMap((block) => (block._tag === 'text' ? [block.text] : []))\n .join(' ')\n .replace(/\\s+/g, ' ')\n .trim();\n return request ? (request.length > 80 ? `${request.slice(0, 79)}…` : request) : undefined;\n};\n\n/**\n * Opens a light thread: a fork of main that starts with one entry holding the transcript of each running sibling.\n */\nconst openLight = (state: PromptState, event: Trajectory.Event, payload: Trajectory.ThreadOpen): PromptState => {\n const id = threadOf(event);\n if (id === undefined) {\n return state;\n }\n const seen = seenAt(state, payload.from);\n const siblings = (payload.siblings ?? []).flatMap((id): Transcript.Thread[] => {\n const buffer = state.threads[id];\n if (!buffer) {\n return [];\n }\n const entries = workOf(state, id, seen);\n return [{ id, purpose: buffer.purpose ?? titleOf(entries), owner: buffer.owner, status: 'running', entries }];\n });\n const entries: PromptEntry[] =\n siblings.length > 0\n ? [\n {\n role: 'event',\n name: 'threads',\n // Synthetic, as the system wrote it: it is context for the thread's prompt, not a prompt of its own.\n blocks: [{ _tag: 'text', text: Transcript.snapshot(siblings, id), disposition: 'synthetic' }],\n source: [event.id],\n at: state.position,\n ephemeral: true,\n },\n ]\n : [];\n return open(state, id, {\n mode: 'light',\n fresh: false,\n seen,\n purpose: payload.purpose,\n owner: event.sender.name,\n entries,\n });\n};\n\nconst compact = (state: PromptState, payload: Trajectory.Compact, id: Trajectory.EventId) => {\n const entries = state.entries;\n const first = entries.findIndex((entry) => entry.source.includes(payload.from));\n const last = entries.findLastIndex((entry) => entry.source.includes(payload.to));\n // An id that is not in the prompt (a queued or cancelled message, a non-content event) cannot place the range.\n if (first === -1 || last === -1 || first > last) {\n return entries;\n }\n\n // The summary keeps the ids it replaced, so a later range that starts inside it still finds where to begin.\n const replaced = entries.slice(first, last + 1).flatMap((entry) => entry.source);\n // A thread that saw only part of the range sees the whole summary; compaction rewrites history either way.\n const at = Math.min(...entries.slice(first, last + 1).map((entry) => entry.at));\n const summary: PromptEntry = { role: 'event', blocks: payload.summary, source: [id, ...replaced], at };\n return [...entries.slice(0, first), summary, ...entries.slice(last + 1)];\n};\n\n/**\n * Builds the model prompt. Apart from `compact` and `rewind`, every event leaves `entries` as a prefix of what it was, which is\n * what keeps the provider's prompt cache valid from one request to the next.\n */\nconst stepPrompt = (state: PromptState, event: Trajectory.Event): PromptState => {\n const next = place(state, event);\n return { ...next, position: state.position + 1, positions: HashMap.set(next.positions, event.id, state.position) };\n};\n\nconst promptFold: Reducer<PromptState> = {\n initial: { entries: [], held: {}, threads: {}, position: 0, positions: HashMap.empty(), stale: {} },\n step: stepPrompt,\n fold: (state, events) => {\n owned = new WeakMap();\n try {\n return events.reduce(stepPrompt, state);\n } finally {\n owned = undefined;\n }\n },\n};\n\nconst place = (state: PromptState, event: Trajectory.Event): PromptState => {\n const payload = event.payload;\n switch (payload._tag) {\n case 'message': {\n const entry: PromptEntry = {\n role: event.sender.role,\n ...(event.sender.name !== undefined ? { name: event.sender.name } : {}),\n blocks: payload.blocks,\n source: [event.id],\n at: state.position,\n };\n return event.sender.role === 'user'\n ? { ...state, held: { ...state.held, [event.id]: entry } }\n : append(state, threadOf(event), entry);\n }\n case 'promptConsume': {\n const entry = state.held[payload.message];\n if (!entry) {\n return state;\n }\n\n return append({ ...state, held: omit(state.held, payload.message) }, threadOf(event), {\n ...entry,\n source: [...entry.source, event.id],\n });\n }\n case 'promptCancel':\n return { ...state, held: omit(state.held, payload.message) };\n case 'toolDeliver':\n return append(state, threadOf(event), { role: 'event', blocks: [payload.result], source: [event.id] });\n case 'hookEnd':\n return payload.blocks\n ? append(state, threadOf(event), { role: 'event', blocks: payload.blocks, source: [event.id] })\n : state;\n case 'threadOpen':\n if (payload.mode === 'light') {\n return openLight(state, event, payload);\n }\n // A fork of another conversation has no parent in this log, so its history starts empty.\n return open(state, threadOf(event), {\n parent: payload.from?.feed ? undefined : payload.from?.thread,\n mode: payload.mode,\n ...(payload.purpose !== undefined ? { purpose: payload.purpose } : {}),\n ...(event.sender.name !== undefined ? { owner: event.sender.name } : {}),\n fresh: payload.mode === 'fresh' || payload.from?.feed !== undefined,\n seen: payload.mode === 'fork' ? forkSeen(state, payload.from) : seenAt(state, payload.from),\n entries: [],\n });\n case 'turnBegin':\n return open(state, threadOf(event), {\n parent: payload.from?.thread,\n fresh: false,\n seen: seenAt(state, payload.from),\n entries: [],\n });\n case 'turnEnd': {\n const id = threadOf(event);\n const turn = id === undefined ? undefined : live(state, id);\n return id !== undefined && turn ? mergeInto(state, id, turn.entries) : state;\n }\n case 'threadMerge': {\n const thread = threadOf(event);\n if (thread === undefined || state.threads[thread]?.closed) {\n return state;\n }\n\n const merged = state.threads[thread]?.entries ?? [];\n return payload.mode === 'summary'\n ? mergeInto(state, thread, [{ role: 'event', blocks: payload.summary ?? [], source: [event.id] }])\n : mergeInto(state, thread, merged);\n }\n case 'threadClose': {\n const thread = threadOf(event);\n return thread !== undefined && live(state, thread) ? { ...state, threads: end(state.threads, thread) } : state;\n }\n case 'compact':\n return threadOf(event) === undefined ? { ...state, entries: compact(state, payload, event.id) } : state;\n case 'rewind': {\n const from = state.entries.findIndex((entry) => entry.source.includes(payload.from));\n return threadOf(event) === undefined && from !== -1 ? { ...state, entries: state.entries.slice(0, from) } : state;\n }\n case 'fork':\n return { ...state, origin: payload.from };\n case 'requestResolve': {\n const resolve = (entry: PromptEntry): PromptEntry =>\n entry.source.includes(payload.message) ? { ...entry, blocks: resolveRequest(entry.blocks, payload) } : entry;\n return {\n ...state,\n entries: state.entries.map(resolve),\n threads: Object.fromEntries(\n Object.entries(state.threads).map(([id, buffer]) => [\n id,\n { ...buffer, entries: buffer.entries.map(resolve) },\n ]),\n ),\n };\n }\n default:\n return state;\n }\n};\n\n//\n// Durable: the reducers above, with a codec so a checkpoint can be stored and resumed.\n//\n\n/**\n * A reducer whose state can be stored, so a reader resumes from a saved checkpoint instead of refolding the feed.\n */\nexport interface Durable<S> extends Reducer<S> {\n /** Names the reducer and its state shape; a stored checkpoint under a different id is never read back. */\n readonly id: string;\n readonly schema: Schema.Codec<S, unknown>;\n /** Points decoded refs at a database, since a stored ref keeps its URI but not what resolves it. */\n readonly rebind?: (state: S, makeRef: MakeRef) => S;\n}\n\nexport type MakeRef = <T extends Obj.Unknown>(ref: Ref.Ref<T>) => Ref.Ref<T>;\n\nconst EventIds = Schema.Array(Trajectory.EventId);\nconst ThreadIds = Schema.Array(Trajectory.ThreadId);\n\nconst SessionStateSchema = Schema.Struct({\n queue: EventIds,\n alarms: Schema.Array(\n Schema.Struct({ id: Trajectory.EventId, wakeAt: Schema.Number, message: Schema.optional(Schema.String) }),\n ),\n skills: Trajectory.ContextBind.fields.skills,\n objects: Trajectory.ContextBind.fields.objects,\n background: Schema.Array(Schema.Struct({ toolCallId: Schema.String, pid: Schema.optional(Schema.String) })),\n threads: Schema.Array(\n Schema.Struct({\n id: Trajectory.ThreadId,\n mode: Trajectory.ThreadMode,\n status: Schema.Literals(['open', 'merged', 'completed', 'failed', 'cancelled']),\n }),\n ),\n model: Schema.optional(Trajectory.ModelChange.fields.model),\n turns: ThreadIds,\n rejected: EventIds,\n selfWakes: Schema.Number,\n});\n\nconst ThreadViewSchema = Schema.Struct({\n items: Schema.Array(\n Schema.Struct({\n id: Trajectory.EventId,\n sender: Trajectory.Sender,\n blocks: Schema.Array(ContentBlock.Any),\n created: Schema.String,\n thread: Schema.optional(Trajectory.ThreadId),\n lane: Schema.optional(Trajectory.ThreadId),\n status: Schema.Literals(['queued', 'consumed', 'cancelled', 'sent', 'rewound']),\n }),\n ),\n lanes: Schema.Array(\n Schema.Struct({\n id: Trajectory.ThreadId,\n kind: Schema.Literals(['turn', 'fork', 'fresh', 'light']),\n from: Schema.optional(Trajectory.EventId),\n merged: Schema.optional(Trajectory.MergeMode),\n status: Schema.Literals(['running', 'waiting', 'done', 'failed']),\n owner: Trajectory.Sender,\n created: Schema.String,\n purpose: Schema.optional(Schema.String),\n waitingOn: Schema.optional(Trajectory.ThreadId),\n overlapped: Schema.optional(Schema.Boolean),\n backgrounded: Schema.optional(Schema.Boolean),\n }),\n ),\n laneOf: Schema.Record(Trajectory.ThreadId, Trajectory.ThreadId),\n});\n\nconst PromptEntrySchema = Schema.Struct({\n role: Trajectory.Role,\n name: Schema.optional(Schema.String),\n blocks: Schema.Array(ContentBlock.Any),\n source: EventIds,\n at: Schema.Number,\n ephemeral: Schema.optional(Schema.Boolean),\n});\n\nconst PromptStateSchema = Schema.Struct({\n entries: Schema.Array(PromptEntrySchema),\n held: Schema.Record(Schema.String, PromptEntrySchema),\n threads: Schema.Record(\n Schema.String,\n Schema.Struct({\n parent: Schema.optional(Trajectory.ThreadId),\n mode: Schema.optional(Trajectory.ThreadMode),\n fresh: Schema.Boolean,\n seen: Schema.Number,\n closed: Schema.optional(Schema.Boolean),\n purpose: Schema.optional(Schema.String),\n owner: Schema.optional(Schema.String),\n entries: Schema.Array(PromptEntrySchema),\n }),\n ),\n position: Schema.Number,\n positions: Schema.Record(Trajectory.EventId, Schema.Number).pipe(\n Schema.decodeTo(\n Schema.HashMap(Trajectory.EventId, Schema.Number),\n SchemaTransformation.transform({\n decode: (record) => HashMap.fromIterable(Object.entries(record)),\n encode: (positions) => Object.fromEntries(positions),\n }),\n ),\n ),\n stale: Schema.Record(Schema.String, EventIds),\n origin: Schema.optional(Trajectory.ThreadOrigin),\n});\n\nexport const session: Durable<SessionState> = {\n ...sessionFold,\n id: 'session@3',\n schema: SessionStateSchema,\n rebind: (state, makeRef) => ({\n ...state,\n skills: state.skills.map((ref) => makeRef(ref)),\n objects: state.objects.map((ref) => makeRef(ref)),\n }),\n};\n\nexport const thread: Durable<ThreadView> = { ...threadFold, id: 'thread@5', schema: ThreadViewSchema };\n\nexport const prompt: Durable<PromptState> = {\n ...promptFold,\n id: 'prompt@3',\n schema: PromptStateSchema,\n rebind: (state, makeRef) =>\n state.origin?.feed ? { ...state, origin: { ...state.origin, feed: makeRef(state.origin.feed) } } : state,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,OACX,SACA,QACA,SACkB;CAClB,MAAM,QAAQ,CAAC,GAAG,MAAM;CACxB,MAAM,UAAU,MAAM,SAAS,QAAQ;CAIvC,OAAO;EAAE,OAHK,QAAQ,OAClB,QAAQ,KAAK,SAAS,KAAK,IAC3B,MAAM,QAAQ,MAAM,UAAU,QAAQ,KAAK,MAAM,KAAK,GAAG,OAAO;EACpD,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,MAAM;EAAM,QAAQ,MAAM,SAAS,KAAK,MAAM;CAAO;AACjG;;AA2CA,IAAM,iBAAiB,OAAyB,YAC9C,MAAM,OAAO,SAAS,UACtB,QAAQ,OAAO,MAAM,UAAU,MAAM,SAAS,UAAU,MAAM,gBAAgB,WAAW;AAE3F,IAAM,QAAmC,SAAuB,UAC9D,MAAM,QACH,MAAM,QAAS,KAAK,MAAM,aAAa,SAAS,QAAQ,IAAI,GAAG,IAAI,OAAO,CAAC,GAAG,MAAM,GAAG,GACxF,OACF;AAEF,IAAM,UAAqC,SAAuB,YAChE,QAAQ,QAAQ,QAAQ,CAAC,QAAQ,MAAM,UAAU,MAAM,QAAQ,IAAI,GAAG,CAAC;AAEzE,IAAM,WAAWA;;AAGjB,IAAM,cAAc,KAAqC,OACvD,OAAO,KAAA,IAAY,MAAM,CAAC,GAAG,KAAK,EAAE;AAEtC,IAAM,cAAc,OAAqB,IAAqC,SAC5E,OAAO,KAAA,IAAY,QAAQ;CAAE,GAAG;CAAO,SAAS,CAAC,GAAG,MAAM,SAAS;EAAE;EAAI;EAAM,QAAQ;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,MAAM,OAAO,KAAK,QAAQ,QAAQ,GAAG,CAAC;EAC9C,SAAS,MAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG,CAAC;CAClD;AACF;AAEA,IAAa,SAA8B;CAAE,GAAG;CAAY,IAAI;CAAY,QAAQ;AAAiB;AAErG,IAAa,SAA+B;CAC1C,GAAG;CACH,IAAI;CACJ,QAAQ;CACR,SAAS,OAAO,YACd,MAAM,QAAQ,OAAO;EAAE,GAAG;EAAO,QAAQ;GAAE,GAAG,MAAM;GAAQ,MAAM,QAAQ,MAAM,OAAO,IAAI;EAAE;CAAE,IAAI;AACvG"}
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { n as Instructions } from "./chunk-Instructions.mjs";
2
3
  import { t as Runnable } from "./chunk-Runnable.mjs";
3
4
  import { d as Trigger } from "./chunk-Trigger.mjs";
4
- import { n as Instructions } from "./chunk-Instructions.mjs";
5
5
  import * as Schema from "effect/Schema";
6
6
  import { Annotation, DXN, Format, Obj, Ref, Type } from "@dxos/echo";
7
7
  import { LabelAnnotation } from "@dxos/echo/internal";
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
- import { d as PersistentOperation } from "./chunk-Operation.mjs";
2
+ import { f as PersistentOperation } from "./chunk-Operation.mjs";
3
3
  //#region src/Runnable.ts
4
4
  var Runnable_exports = /* @__PURE__ */ __exportAll({ Runnable: () => Runnable });
5
5
  var Runnable = PersistentOperation;
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
2
  import { ServiceNotAvailableError } from "./errors.mjs";
3
- import * as Effect from "effect/Effect";
4
3
  import * as Option from "effect/Option";
4
+ import * as Effect from "effect/Effect";
5
5
  import * as Context from "effect/Context";
6
6
  import * as Layer from "effect/Layer";
7
7
  import * as Result from "effect/Result";
@@ -1,18 +1,14 @@
1
1
  import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
- import { a as Spec } from "./chunk-McpServer.mjs";
3
- import { H as toolName } from "./chunk-Operation.mjs";
2
+ import { st as toolName } from "./chunk-Operation.mjs";
4
3
  import { a as make$1, r as Template } from "./chunk-Template.mjs";
5
- import { i as InputTemplate } from "./chunk-Trigger.mjs";
6
4
  import { BaseError } from "@dxos/errors";
5
+ import * as Option from "effect/Option";
7
6
  import * as Schema from "effect/Schema";
8
7
  import { Annotation, DXN, Database, Filter, Format, Obj, Ref, Registry, Type, URI } from "@dxos/echo";
9
8
  import * as Effect from "effect/Effect";
10
- import * as Option from "effect/Option";
11
9
  import { ToolId } from "@dxos/ai";
12
10
  //#region src/types/Skill.ts
13
11
  var Skill_exports = /* @__PURE__ */ __exportAll({
14
- Hook: () => Hook,
15
- HookSpec: () => HookSpec,
16
12
  McpPromptAnnotation: () => McpPromptAnnotation,
17
13
  NotFoundError: () => NotFoundError,
18
14
  Skill: () => Skill,
@@ -35,6 +31,12 @@ var Skill_exports = /* @__PURE__ */ __exportAll({
35
31
  * Skills contain instructions, tools, and artifacts that guide the AI's behavior.
36
32
  * Skills may use tools to create and read artifacts, which are managed by the assistant.
37
33
  *
34
+ * Follows the Agent Skills spec (https://agentskills.io/specification) as closely as it can, so a skill
35
+ * means the same here as in any other harness. Add a field the spec lacks only with a strong reason,
36
+ * and say what it is. Credentials and MCP servers do not belong here: a server is a connection, which
37
+ * the space owns and each conversation can turn off. Nor do hooks: a plugin contributes those beside its
38
+ * skills (`@dxos/compute/Hook`).
39
+ *
38
40
  * The registry `key` and `version` are stored in the object meta — access them via
39
41
  * `Obj.getMeta(skill).key` and `Obj.getMeta(skill).version`.
40
42
  */
@@ -59,51 +61,12 @@ var Skill = class extends Type.makeObject(DXN.make("org.dxos.type.skill", "0.2.0
59
61
  /**
60
62
  * Whether an agent is allowed to auto-enable this skill in a conversation.
61
63
  */
62
- agentCanEnable: Schema.optional(Schema.Boolean).annotate({ description: "Whether an agent is allowed to auto-enable this skill in a conversation." }),
63
- /**
64
- * Array of MCP servers that the AI assistant can use when this skill is active.
65
- */
66
- mcpServers: Schema.optional(Schema.Array(Spec)),
67
- /**
68
- * Hooks triggered automatically at certain points in the agent's lifecycle.
69
- */
70
- hooks: Schema.optional(Schema.Array(Schema.suspend(() => Hook)))
64
+ agentCanEnable: Schema.optional(Schema.Boolean).annotate({ description: "Whether an agent is allowed to auto-enable this skill in a conversation." })
71
65
  }).pipe(Annotation.LabelAnnotation.set(["name"]), Annotation.IconAnnotation.set({
72
66
  icon: "ph--student--regular",
73
67
  hue: "amber"
74
68
  }), Annotation.UserType.set())) {};
75
69
  /**
76
- * Controls when the hook is triggered.
77
- */
78
- var HookSpec = Schema.Union([Schema.TaggedStruct("begin-request", {}), Schema.TaggedStruct("end-request", {})]);
79
- /**
80
- * Allows hooking into the agent's lifecycle.
81
- * NOTE: Intentionally similar to Trigger, perhaps we should merge them.
82
- */
83
- var Hook = Schema.Struct({
84
- /**
85
- * What to do when the hook is triggered.
86
- *
87
- * Can be a Ref to a PersistentOperation.
88
- */
89
- function: Schema.optional(Ref.Ref(Obj.Unknown).annotate({ title: "Function" })),
90
- /**
91
- * Controls when the hook is triggered.
92
- */
93
- spec: HookSpec,
94
- /**
95
- * Passed as the input data to the function.
96
- * Must match the function's input schema.
97
- */
98
- input: InputTemplate.pipe(Annotation.FormInputAnnotation.set(false), Schema.optional),
99
- /**
100
- * Run in the background (end-request only): the request settles without waiting for the hook, and
101
- * the agent process awaits it before it finishes. For work the user should not wait on, e.g.
102
- * reviewing the turn that just ended.
103
- */
104
- async: Schema.optional(Schema.Boolean.annotate({ title: "Run in background" }))
105
- });
106
- /**
107
70
  * Create a new Skill.
108
71
  * The `key` (and optional `version`) are stored in the object meta.
109
72
  * `key` must be a valid DXN name (e.g. `org.dxos.skill.mySkill`).
@@ -234,6 +197,6 @@ var upsert = (key) => Effect.gen(function* () {
234
197
  });
235
198
  var NotFoundError = class extends BaseError.extend("SkillNotFound", "Skill not found") {};
236
199
  //#endregion
237
- export { resolveAnnotatedSkills as _, Skill as a, annotatedSkillKeys as c, getVersion as d, isMcpPrompt as f, resolve as g, registryURI as h, NotFoundError as i, annotatedSkillRefs as l, makeRef as m, HookSpec as n, Skill_exports as o, make as p, McpPromptAnnotation as r, SkillsAnnotation as s, Hook as t, getKey as u, toolDefinitions as v, upsert as y };
200
+ export { upsert as _, SkillsAnnotation as a, getKey as c, make as d, makeRef as f, toolDefinitions as g, resolveAnnotatedSkills as h, Skill_exports as i, getVersion as l, resolve as m, NotFoundError as n, annotatedSkillKeys as o, registryURI as p, Skill as r, annotatedSkillRefs as s, McpPromptAnnotation as t, isMcpPrompt as u };
238
201
 
239
202
  //# sourceMappingURL=chunk-Skill.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-Skill.mjs","names":["McpServer.Spec","Template.make","Operation.toolName"],"sources":["../../src/types/Skill.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { ToolId } from '@dxos/ai';\nimport { Annotation, Database, DXN, Filter, Format, Obj, Ref, Registry, Type, URI } from '@dxos/echo';\nimport { BaseError } from '@dxos/errors';\n// Text is referenced in the inferred type of Skill (via Template.Template → Ref.Ref(Text.Text));\n// the import lets TypeScript name it in the emitted .d.ts.\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { type Text } from '@dxos/schema';\n\nimport * as McpServer from '../McpServer.ts';\nimport * as Operation from '../Operation.ts';\nimport * as Template from './Template.ts';\nimport * as Trigger from './Trigger.ts';\n\n/**\n * Skill schema defines the structure for AI assistant skills.\n * Skills contain instructions, tools, and artifacts that guide the AI's behavior.\n * Skills may use tools to create and read artifacts, which are managed by the assistant.\n *\n * The registry `key` and `version` are stored in the object meta — access them via\n * `Obj.getMeta(skill).key` and `Obj.getMeta(skill).version`.\n */\nexport class Skill extends Type.makeObject<Skill>(DXN.make('org.dxos.type.skill', '0.2.0'))(\n Schema.Struct({\n /**\n * Human-readable name of the skill.\n */\n name: Schema.String.annotate({\n description: 'Human-readable name of the skill',\n }),\n\n /**\n * Description of the skill's purpose and functionality.\n */\n description: Schema.optional(Format.Text).annotate({\n description: \"Description of the skill's purpose and functionality\",\n }),\n\n /**\n * Instructions that guide the AI assistant's behavior and responses.\n * These are system prompts or guidelines that the AI should follow.\n */\n instructions: Template.Template.annotate({\n description: \"Instructions that guide the AI assistant's behavior and responses\",\n }),\n\n /**\n * Array of tools that the AI assistant can use when this skill is active.\n */\n tools: Schema.Array(ToolId).annotate({\n description: 'Array of tools that the AI assistant can use when this skill is active',\n }),\n\n /**\n * Whether an agent is allowed to auto-enable this skill in a conversation.\n */\n agentCanEnable: Schema.optional(Schema.Boolean).annotate({\n description: 'Whether an agent is allowed to auto-enable this skill in a conversation.',\n }),\n\n /**\n * Array of MCP servers that the AI assistant can use when this skill is active.\n */\n mcpServers: Schema.optional(Schema.Array(McpServer.Spec)),\n\n /**\n * Hooks triggered automatically at certain points in the agent's lifecycle.\n */\n hooks: Schema.optional(Schema.Array(Schema.suspend(() => Hook))),\n }).pipe(\n Annotation.LabelAnnotation.set(['name']),\n Annotation.IconAnnotation.set({ icon: 'ph--student--regular', hue: 'amber' }),\n Annotation.UserType.set(),\n ),\n) {}\n\n/**\n * Controls when the hook is triggered.\n */\nexport const HookSpec = Schema.Union([\n /**\n * Triggered when the agent is about to start a request.\n * A request is a series of agent/tool turns that the model drives.\n */\n Schema.TaggedStruct('begin-request', {}),\n /**\n * Triggered when the agent has completed a request.\n * A request is a series of agent/tool turns that the model drives.\n */\n Schema.TaggedStruct('end-request', {}),\n]);\n\n/**\n * Allows hooking into the agent's lifecycle.\n * NOTE: Intentionally similar to Trigger, perhaps we should merge them.\n */\nexport const Hook = Schema.Struct({\n /**\n * What to do when the hook is triggered.\n *\n * Can be a Ref to a PersistentOperation.\n */\n function: Schema.optional(Ref.Ref(Obj.Unknown).annotate({ title: 'Function' })),\n\n /**\n * Controls when the hook is triggered.\n */\n spec: HookSpec,\n\n /**\n * Passed as the input data to the function.\n * Must match the function's input schema.\n */\n input: Trigger.InputTemplate.pipe(Annotation.FormInputAnnotation.set(false), Schema.optional),\n\n /**\n * Run in the background (end-request only): the request settles without waiting for the hook, and\n * the agent process awaits it before it finishes. For work the user should not wait on, e.g.\n * reviewing the turn that just ended.\n */\n async: Schema.optional(Schema.Boolean.annotate({ title: 'Run in background' })),\n});\n\nexport type Hook = Schema.Schema.Type<typeof Hook>;\n\n/**\n * Create a new Skill.\n * The `key` (and optional `version`) are stored in the object meta.\n * `key` must be a valid DXN name (e.g. `org.dxos.skill.mySkill`).\n */\nexport const make: {\n <T extends string>(\n props: {\n key: [DXN.Name<T>] extends [never] ? `Invalid DXN name \"${T}\": final segment must be camelCase (no hyphens)` : T;\n version?: string;\n name: string;\n /** Opt into MCP projection; see {@link McpPromptAnnotation}. Stored in meta, not as a field. */\n mcpPrompt?: boolean;\n } & Partial<Skill>,\n ): Skill;\n} = ({ key, version, mcpPrompt, tools = [], instructions = Template.make(), ...props }) => {\n const annotations: Annotation.Dictionary = {};\n if (mcpPrompt !== undefined) {\n Annotation.setDictionary(annotations, McpPromptAnnotation, mcpPrompt);\n }\n return Obj.make(Skill, {\n [Obj.Meta]: { key, version, annotations },\n tools,\n instructions,\n ...props,\n });\n};\n\n/**\n * Annotation opting a skill into MCP projection: it becomes a prompt and is loadable by name\n * through the server's `loadSkill` tool.\n *\n * Opt-in: a skill written for an in-app chat runtime may assume tools an MCP client does not have,\n * and only the author can judge whether the workflow still holds on the MCP surface. Absent ⇒ the\n * skill stays internal to hosts that resolve skills directly.\n *\n * Rides in the object's meta rather than on `Definition`, so it survives into a persisted skill —\n * `Definition` is a build-time factory type and cannot describe a skill stored in a space.\n */\n/**\n * Skill keys a session scoped to an instance of the annotated type should carry — read by the AI\n * companion, the blank routine template, and project chat creation. Held as plain dotted keys so the\n * annotated type does not depend on the plugin that owns each skill.\n */\nexport const SkillsAnnotation = Annotation.make<string[]>({\n id: 'org.dxos.annotation.skills',\n schema: Schema.mutable(Schema.Array(Schema.String)),\n});\n\nexport const McpPromptAnnotation = Annotation.make({\n id: 'org.dxos.skill.mcp-prompt',\n schema: Schema.Boolean,\n});\n\n/** Whether the skill opted into MCP projection; see {@link McpPromptAnnotation}. */\nexport const isMcpPrompt = (skill: Skill): boolean =>\n Annotation.get(skill, McpPromptAnnotation).pipe(Option.getOrElse(() => false));\n\n/**\n * Get the registry key for a skill.\n */\nexport const getKey = (skill: Skill): string => {\n const key = Obj.getMeta(skill).key;\n if (key === undefined) {\n throw new Error('Skill is missing the meta key.');\n }\n return key;\n};\n\n/**\n * Get the registry version for a skill, if any.\n */\nexport const getVersion = (skill: Skill): string | undefined => Obj.getMeta(skill).version;\n\n/**\n * Util to create tool definitions for a skill.\n * Operation tool ids are the model-facing names (see {@link Operation.toolName}), so the skill's\n * `tools` array and the session toolkit speak one identifier space.\n */\nexport const toolDefinitions = ({\n tools = [],\n operations = [],\n}: {\n tools?: readonly string[];\n operations?: readonly Operation.Definition.Any[];\n}) => [...operations.map((op) => ToolId.make(Operation.toolName(op))), ...tools.map((tool) => ToolId.make(tool))];\n\n/**\n * Factory for the skills.\n */\nexport type Definition = {\n key: DXN.Name<string>;\n make: () => Skill;\n /**\n * Operation definitions behind the skill's `tools` list, for hosts that serve the skill without\n * a registry to resolve ToolIds against (see mcp-server `McpServer.fromSkills`). Absent ⇒ the skill is\n * only served through a registry-backed host.\n */\n operations?: readonly Operation.Definition.Any[];\n};\n\n/**\n * Returns the canonical URI used to reference this skill in the registry.\n * Use this URI with `Ref.fromURI` to bind a skill without cloning it to the DB.\n *\n * TODO(wittjosiah): Should use Obj.getURI instead once it supports options to prefer meta key over EID.\n */\nexport const registryURI = (key: DXN.Name<string>): URI.URI => (DXN.tryMake(`dxn:${key}`) ?? URI.make(key)) as URI.URI;\n\n/**\n * The ref a session binds for a resolved skill: a skill in a database is bound as-is (it is\n * space-authored or a fork carrying the user's edits), anything else by its registry URI, so a\n * rebind never substitutes the pristine copy for the fork or vice versa.\n */\nexport const makeRef = (skill: Skill): Ref.Ref<Skill> =>\n Obj.getDatabase(skill) !== undefined ? Ref.make(skill) : Ref.fromURI(registryURI(getKey(skill)));\n\n/**\n * Registry skill refs declared by an object's type via {@link SkillsAnnotation}.\n * Bound by URI rather than a DB clone, so the ref resolves through the hypergraph registry.\n */\nexport const annotatedSkillRefs = (object: Obj.Unknown): Ref.Ref<Skill>[] => {\n const type = Obj.getType(object);\n if (!type) {\n return [];\n }\n\n return annotatedSkillKeys(type).map((key) => Ref.fromURI(registryURI(key)));\n};\n\n/** Skill keys declared by a type via {@link SkillsAnnotation}. */\nexport const annotatedSkillKeys = (type: Type.AnyEntity): string[] =>\n Option.getOrElse(() => [] as string[])(SkillsAnnotation.get(Type.getSchema(type)));\n\n/**\n * Refs for an object's {@link SkillsAnnotation} keys; a space copy wins, since it is a fork of the\n * registry skill and carries the user's edits.\n *\n * TODO(wittjosiah): Lift this two-source merge into the query layer; it is how forking should work\n * for any type, not just skills.\n */\nexport const resolveAnnotatedSkills = Effect.fnUntraced(function* (object: Obj.Unknown) {\n const type = Obj.getType(object);\n const keys = type ? annotatedSkillKeys(type) : [];\n if (keys.length === 0) {\n return [] as Ref.Ref<Skill>[];\n }\n\n const byKey = new Map<string, Ref.Ref<Skill>>();\n for (const skill of yield* Registry.runQuery(Filter.type(Skill))) {\n const key = Obj.getMeta(skill).key;\n if (key && keys.includes(key)) {\n // By URI rather than a clone: the ECHO ref resolver already spans the registry.\n byKey.set(key, Ref.fromURI(registryURI(key)));\n }\n }\n for (const skill of yield* Database.query(Filter.type(Skill)).run) {\n const key = Obj.getMeta(skill).key;\n if (key && keys.includes(key)) {\n byKey.set(key, Ref.make(skill));\n }\n }\n\n return [...byKey.values()];\n});\n\n/**\n * Resolves a skill from the registry by its meta key.\n * Does not check the local database for the skill.\n */\nexport const resolve = (key: string): Effect.Effect<Skill, NotFoundError, Registry.Service> =>\n Effect.gen(function* () {\n const results = yield* Registry.runQuery(Filter.and(Filter.type(Skill), Filter.key(key)));\n const skill = results[0];\n if (!skill) {\n return yield* Effect.fail(new NotFoundError({ context: { key } }));\n }\n return skill;\n });\n\n/**\n * Upserts a skill into the database.\n * If the skill already exists in the database, the local (possibly forked) copy is returned as-is.\n * Otherwise, a fresh copy is cloned from the registry and added.\n * @deprecated Since we're using a registry we no longer need to store skills in the database.\n */\n// TODO(dmaretskyi): Remove.\nexport const upsert = (key: string): Effect.Effect<Skill, NotFoundError, Registry.Service | Database.Service> =>\n Effect.gen(function* () {\n const local = yield* Database.query(Filter.and(Filter.type(Skill), Filter.key(key))).run;\n if (local.length > 0) {\n return local[0];\n }\n return yield* Database.add(Obj.clone(yield* resolve(key), { deep: 'all' }));\n });\n\nexport class NotFoundError extends BaseError.extend('SkillNotFound', 'Skill not found') {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,QAAb,cAA2B,KAAK,WAAkB,IAAI,KAAK,uBAAuB,OAAO,CAAC,CAAC,CACzF,OAAO,OAAO;;;;CAIZ,MAAM,OAAO,OAAO,SAAS,EAC3B,aAAa,mCACf,CAAC;;;;CAKD,aAAa,OAAO,SAAS,OAAO,IAAI,CAAC,CAAC,SAAS,EACjD,aAAa,uDACf,CAAC;;;;;CAMD,cAAA,SAAgC,SAAS,EACvC,aAAa,oEACf,CAAC;;;;CAKD,OAAO,OAAO,MAAM,MAAM,CAAC,CAAC,SAAS,EACnC,aAAa,yEACf,CAAC;;;;CAKD,gBAAgB,OAAO,SAAS,OAAO,OAAO,CAAC,CAAC,SAAS,EACvD,aAAa,2EACf,CAAC;;;;CAKD,YAAY,OAAO,SAAS,OAAO,MAAMA,IAAc,CAAC;;;;CAKxD,OAAO,OAAO,SAAS,OAAO,MAAM,OAAO,cAAc,IAAI,CAAC,CAAC;AACjE,CAAC,CAAC,CAAC,KACD,WAAW,gBAAgB,IAAI,CA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CAAC,CAAC;EAC/B,IAAI,OAAO,KAAK,SAAS,GAAG,GAE1B,MAAM,IAAI,KAAK,IAAI,QAAQ,YAAY,GAAG,CAAC,CAAC;CAEhD;CACA,KAAK,MAAM,SAAS,OAAO,SAAS,MAAM,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK;EACjE,MAAM,MAAM,IAAI,QAAQ,KAAK,CAAC,CAAC;EAC/B,IAAI,OAAO,KAAK,SAAS,GAAG,GAC1B,MAAM,IAAI,KAAK,IAAI,KAAK,KAAK,CAAC;CAElC;CAEA,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC;AAC3B,CAAC;;;;;AAMD,IAAa,WAAW,QACtB,OAAO,IAAI,aAAa;CAEtB,MAAM,SAAQ,OADS,SAAS,SAAS,OAAO,IAAI,OAAO,KAAK,KAAK,GAAG,OAAO,IAAI,GAAG,CAAC,CAAC,EAAA,CAClE;CACtB,IAAI,CAAC,OACH,OAAO,OAAO,OAAO,KAAK,IAAI,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;CAEnE,OAAO;AACT,CAAC;;;;;;;AASH,IAAa,UAAU,QACrB,OAAO,IAAI,aAAa;CACtB,MAAM,QAAQ,OAAO,SAAS,MAAM,OAAO,IAAI,OAAO,KAAK,KAAK,GAAG,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CACrF,IAAI,MAAM,SAAS,GACjB,OAAO,MAAM;CAEf,OAAO,OAAO,SAAS,IAAI,IAAI,MAAM,OAAO,QAAQ,GAAG,GAAG,EAAE,MAAM,MAAM,CAAC,CAAC;AAC5E,CAAC;AAEH,IAAa,gBAAb,cAAmC,UAAU,OAAO,iBAAiB,iBAAiB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"chunk-Skill.mjs","names":["Template.make","Operation.toolName"],"sources":["../../src/types/Skill.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { ToolId } from '@dxos/ai';\nimport { Annotation, Database, DXN, Filter, Format, Obj, Ref, Registry, Type, URI } from '@dxos/echo';\nimport { BaseError } from '@dxos/errors';\n// Text is referenced in the inferred type of Skill (via Template.Template → Ref.Ref(Text.Text));\n// the import lets TypeScript name it in the emitted .d.ts.\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { type Text } from '@dxos/schema';\n\nimport * as Operation from '../Operation.ts';\nimport * as Template from './Template.ts';\n\n/**\n * Skill schema defines the structure for AI assistant skills.\n * Skills contain instructions, tools, and artifacts that guide the AI's behavior.\n * Skills may use tools to create and read artifacts, which are managed by the assistant.\n *\n * Follows the Agent Skills spec (https://agentskills.io/specification) as closely as it can, so a skill\n * means the same here as in any other harness. Add a field the spec lacks only with a strong reason,\n * and say what it is. Credentials and MCP servers do not belong here: a server is a connection, which\n * the space owns and each conversation can turn off. Nor do hooks: a plugin contributes those beside its\n * skills (`@dxos/compute/Hook`).\n *\n * The registry `key` and `version` are stored in the object meta — access them via\n * `Obj.getMeta(skill).key` and `Obj.getMeta(skill).version`.\n */\nexport class Skill extends Type.makeObject<Skill>(DXN.make('org.dxos.type.skill', '0.2.0'))(\n Schema.Struct({\n /**\n * Human-readable name of the skill.\n */\n name: Schema.String.annotate({\n description: 'Human-readable name of the skill',\n }),\n\n /**\n * Description of the skill's purpose and functionality.\n */\n description: Schema.optional(Format.Text).annotate({\n description: \"Description of the skill's purpose and functionality\",\n }),\n\n /**\n * Instructions that guide the AI assistant's behavior and responses.\n * These are system prompts or guidelines that the AI should follow.\n */\n instructions: Template.Template.annotate({\n description: \"Instructions that guide the AI assistant's behavior and responses\",\n }),\n\n /**\n * Array of tools that the AI assistant can use when this skill is active.\n */\n tools: Schema.Array(ToolId).annotate({\n description: 'Array of tools that the AI assistant can use when this skill is active',\n }),\n\n /**\n * Whether an agent is allowed to auto-enable this skill in a conversation.\n */\n agentCanEnable: Schema.optional(Schema.Boolean).annotate({\n description: 'Whether an agent is allowed to auto-enable this skill in a conversation.',\n }),\n }).pipe(\n Annotation.LabelAnnotation.set(['name']),\n Annotation.IconAnnotation.set({ icon: 'ph--student--regular', hue: 'amber' }),\n Annotation.UserType.set(),\n ),\n) {}\n\n/**\n * Create a new Skill.\n * The `key` (and optional `version`) are stored in the object meta.\n * `key` must be a valid DXN name (e.g. `org.dxos.skill.mySkill`).\n */\nexport const make: {\n <T extends string>(\n props: {\n key: [DXN.Name<T>] extends [never] ? `Invalid DXN name \"${T}\": final segment must be camelCase (no hyphens)` : T;\n version?: string;\n name: string;\n /** Opt into MCP projection; see {@link McpPromptAnnotation}. Stored in meta, not as a field. */\n mcpPrompt?: boolean;\n } & Partial<Skill>,\n ): Skill;\n} = ({ key, version, mcpPrompt, tools = [], instructions = Template.make(), ...props }) => {\n const annotations: Annotation.Dictionary = {};\n if (mcpPrompt !== undefined) {\n Annotation.setDictionary(annotations, McpPromptAnnotation, mcpPrompt);\n }\n return Obj.make(Skill, {\n [Obj.Meta]: { key, version, annotations },\n tools,\n instructions,\n ...props,\n });\n};\n\n/**\n * Annotation opting a skill into MCP projection: it becomes a prompt and is loadable by name\n * through the server's `loadSkill` tool.\n *\n * Opt-in: a skill written for an in-app chat runtime may assume tools an MCP client does not have,\n * and only the author can judge whether the workflow still holds on the MCP surface. Absent ⇒ the\n * skill stays internal to hosts that resolve skills directly.\n *\n * Rides in the object's meta rather than on `Definition`, so it survives into a persisted skill —\n * `Definition` is a build-time factory type and cannot describe a skill stored in a space.\n */\n/**\n * Skill keys a session scoped to an instance of the annotated type should carry — read by the AI\n * companion, the blank routine template, and project chat creation. Held as plain dotted keys so the\n * annotated type does not depend on the plugin that owns each skill.\n */\nexport const SkillsAnnotation = Annotation.make<string[]>({\n id: 'org.dxos.annotation.skills',\n schema: Schema.mutable(Schema.Array(Schema.String)),\n});\n\nexport const McpPromptAnnotation = Annotation.make({\n id: 'org.dxos.skill.mcp-prompt',\n schema: Schema.Boolean,\n});\n\n/** Whether the skill opted into MCP projection; see {@link McpPromptAnnotation}. */\nexport const isMcpPrompt = (skill: Skill): boolean =>\n Annotation.get(skill, McpPromptAnnotation).pipe(Option.getOrElse(() => false));\n\n/**\n * Get the registry key for a skill.\n */\nexport const getKey = (skill: Skill): string => {\n const key = Obj.getMeta(skill).key;\n if (key === undefined) {\n throw new Error('Skill is missing the meta key.');\n }\n return key;\n};\n\n/**\n * Get the registry version for a skill, if any.\n */\nexport const getVersion = (skill: Skill): string | undefined => Obj.getMeta(skill).version;\n\n/**\n * Util to create tool definitions for a skill.\n * Operation tool ids are the model-facing names (see {@link Operation.toolName}), so the skill's\n * `tools` array and the session toolkit speak one identifier space.\n */\nexport const toolDefinitions = ({\n tools = [],\n operations = [],\n}: {\n tools?: readonly string[];\n operations?: readonly Operation.Definition.Any[];\n}) => [...operations.map((op) => ToolId.make(Operation.toolName(op))), ...tools.map((tool) => ToolId.make(tool))];\n\n/**\n * Factory for the skills.\n */\nexport type Definition = {\n key: DXN.Name<string>;\n make: () => Skill;\n /**\n * Operation definitions behind the skill's `tools` list, for hosts that serve the skill without\n * a registry to resolve ToolIds against (see mcp-server `McpServer.fromSkills`). Absent ⇒ the skill is\n * only served through a registry-backed host.\n */\n operations?: readonly Operation.Definition.Any[];\n};\n\n/**\n * Returns the canonical URI used to reference this skill in the registry.\n * Use this URI with `Ref.fromURI` to bind a skill without cloning it to the DB.\n *\n * TODO(wittjosiah): Should use Obj.getURI instead once it supports options to prefer meta key over EID.\n */\nexport const registryURI = (key: DXN.Name<string>): URI.URI => (DXN.tryMake(`dxn:${key}`) ?? URI.make(key)) as URI.URI;\n\n/**\n * The ref a session binds for a resolved skill: a skill in a database is bound as-is (it is\n * space-authored or a fork carrying the user's edits), anything else by its registry URI, so a\n * rebind never substitutes the pristine copy for the fork or vice versa.\n */\nexport const makeRef = (skill: Skill): Ref.Ref<Skill> =>\n Obj.getDatabase(skill) !== undefined ? Ref.make(skill) : Ref.fromURI(registryURI(getKey(skill)));\n\n/**\n * Registry skill refs declared by an object's type via {@link SkillsAnnotation}.\n * Bound by URI rather than a DB clone, so the ref resolves through the hypergraph registry.\n */\nexport const annotatedSkillRefs = (object: Obj.Unknown): Ref.Ref<Skill>[] => {\n const type = Obj.getType(object);\n if (!type) {\n return [];\n }\n\n return annotatedSkillKeys(type).map((key) => Ref.fromURI(registryURI(key)));\n};\n\n/** Skill keys declared by a type via {@link SkillsAnnotation}. */\nexport const annotatedSkillKeys = (type: Type.AnyEntity): string[] =>\n Option.getOrElse(() => [] as string[])(SkillsAnnotation.get(Type.getSchema(type)));\n\n/**\n * Refs for an object's {@link SkillsAnnotation} keys; a space copy wins, since it is a fork of the\n * registry skill and carries the user's edits.\n *\n * TODO(wittjosiah): Lift this two-source merge into the query layer; it is how forking should work\n * for any type, not just skills.\n */\nexport const resolveAnnotatedSkills = Effect.fnUntraced(function* (object: Obj.Unknown) {\n const type = Obj.getType(object);\n const keys = type ? annotatedSkillKeys(type) : [];\n if (keys.length === 0) {\n return [] as Ref.Ref<Skill>[];\n }\n\n const byKey = new Map<string, Ref.Ref<Skill>>();\n for (const skill of yield* Registry.runQuery(Filter.type(Skill))) {\n const key = Obj.getMeta(skill).key;\n if (key && keys.includes(key)) {\n // By URI rather than a clone: the ECHO ref resolver already spans the registry.\n byKey.set(key, Ref.fromURI(registryURI(key)));\n }\n }\n for (const skill of yield* Database.query(Filter.type(Skill)).run) {\n const key = Obj.getMeta(skill).key;\n if (key && keys.includes(key)) {\n byKey.set(key, Ref.make(skill));\n }\n }\n\n return [...byKey.values()];\n});\n\n/**\n * Resolves a skill from the registry by its meta key.\n * Does not check the local database for the skill.\n */\nexport const resolve = (key: string): Effect.Effect<Skill, NotFoundError, Registry.Service> =>\n Effect.gen(function* () {\n const results = yield* Registry.runQuery(Filter.and(Filter.type(Skill), Filter.key(key)));\n const skill = results[0];\n if (!skill) {\n return yield* Effect.fail(new NotFoundError({ context: { key } }));\n }\n return skill;\n });\n\n/**\n * Upserts a skill into the database.\n * If the skill already exists in the database, the local (possibly forked) copy is returned as-is.\n * Otherwise, a fresh copy is cloned from the registry and added.\n * @deprecated Since we're using a registry we no longer need to store skills in the database.\n */\n// TODO(dmaretskyi): Remove.\nexport const upsert = (key: string): Effect.Effect<Skill, NotFoundError, Registry.Service | Database.Service> =>\n Effect.gen(function* () {\n const local = yield* Database.query(Filter.and(Filter.type(Skill), Filter.key(key))).run;\n if (local.length > 0) {\n return local[0];\n }\n return yield* Database.add(Obj.clone(yield* resolve(key), { deep: 'all' }));\n });\n\nexport class NotFoundError extends BaseError.extend('SkillNotFound', 'Skill not found') {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,QAAb,cAA2B,KAAK,WAAkB,IAAI,KAAK,uBAAuB,OAAO,CAAC,CAAC,CACzF,OAAO,OAAO;;;;CAIZ,MAAM,OAAO,OAAO,SAAS,EAC3B,aAAa,mCACf,CAAC;;;;CAKD,aAAa,OAAO,SAAS,OAAO,IAAI,CAAC,CAAC,SAAS,EACjD,aAAa,uDACf,CAAC;;;;;CAMD,cAAA,SAAgC,SAAS,EACvC,aAAa,oEACf,CAAC;;;;CAKD,OAAO,OAAO,MAAM,MAAM,CAAC,CAAC,SAAS,EACnC,aAAa,yEACf,CAAC;;;;CAKD,gBAAgB,OAAO,SAAS,OAAO,OAAO,CAAC,CAAC,SAAS,EACvD,aAAa,2EACf,CAAC;AACH,CAAC,CAAC,CAAC,KACD,WAAW,gBAAgB,IAAI,CAAC,MAAM,CAAC,GACvC,WAAW,eAAe,IAAI;CAAE,MAAM;CAAwB,KAAK;AAAQ,CAAC,GAC5E,WAAW,SAAS,IAAI,CAC1B,CACF,CAAC,CAAC,CAAC;;;;;;AAOH,IAAa,QAUR,EAAE,KAAK,SAAS,WAAW,QAAQ,CAAC,GAAG,eAAeA,OAAc,GAAG,GAAG,YAAY;CACzF,MAAM,cAAqC,CAAC;CAC5C,IAAI,cAAc,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AAI,aAAa;CACtB,MAAM,QAAQ,OAAO,SAAS,MAAM,OAAO,IAAI,OAAO,KAAK,KAAK,GAAG,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CACrF,IAAI,MAAM,SAAS,GACjB,OAAO,MAAM;CAEf,OAAO,OAAO,SAAS,IAAI,IAAI,MAAM,OAAO,QAAQ,GAAG,GAAG,EAAE,MAAM,MAAM,CAAC,CAAC;AAC5E,CAAC;AAEH,IAAa,gBAAb,cAAmC,UAAU,OAAO,iBAAiB,iBAAiB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { a as SkillsAnnotation } from "./chunk-Skill.mjs";
3
+ import * as Schema from "effect/Schema";
4
+ import { Annotation, DXN, Format, Obj, Ref, Type } from "@dxos/echo";
5
+ import { FactoryAnnotation, Text } from "@dxos/schema";
6
+ //#region src/types/Spec.ts
7
+ var Spec_exports = /* @__PURE__ */ __exportAll({
8
+ Spec: () => Spec,
9
+ instanceOf: () => instanceOf,
10
+ make: () => make
11
+ });
12
+ /**
13
+ * A spec: normative `.mdl` text that its project's work delivers. Its dialects say which block kinds beyond the core
14
+ * and changelog ones the text uses, which a plugin then extracts into objects of its own and keeps as annotations on
15
+ * the spec. A project owns its specs (`Project.specs`), so a spec is not a type of its own in a space. A `.mdl` file's
16
+ * front matter is the spec's fields and meta rather than its text: `name` is `name`, `id` and `version` are the
17
+ * meta's `key` and `version`.
18
+ */
19
+ var Spec = class extends Type.makeObject(DXN.make("org.dxos.type.projects.spec", "0.4.0"))(Schema.Struct({
20
+ name: Schema.String.pipe(Schema.annotate({ title: "Name" })),
21
+ description: Schema.optional(Schema.String.pipe(Format.FormatAnnotation.set(Format.TypeFormat.Markdown), Schema.annotate({
22
+ title: "Description",
23
+ description: "What the spec describes when its work is complete."
24
+ }))),
25
+ /**
26
+ * The ids of the dialect specs whose blocks the text uses, as a `.mdl` file lists them in its front matter's
27
+ * `extends`. Empty means the core and changelog blocks only.
28
+ */
29
+ dialects: Schema.Array(Schema.String).pipe(Annotation.FormInputAnnotation.set(false)),
30
+ /** The `.mdl` text; owned, so it is deleted with the spec. */
31
+ content: Ref.Ref(Text.Text).pipe(Annotation.SetParent.set(), Annotation.FormInputAnnotation.set(false))
32
+ }).pipe(Annotation.LabelAnnotation.set(["name"]), Annotation.IconAnnotation.set({
33
+ icon: "ph--blueprint--regular",
34
+ hue: "violet"
35
+ }), SkillsAnnotation.set(["org.dxos.skill.code.featureMap"]), FactoryAnnotation.set((values) => make({
36
+ name: "",
37
+ ...values
38
+ })))) {};
39
+ /** `dialects` starts as an empty list so two peers lazily creating it cannot each write a fresh one. */
40
+ var make = ({ content, dialects = [], ...props }) => Obj.make(Spec, {
41
+ ...props,
42
+ dialects: [...dialects],
43
+ content: Ref.make(Text.make({ content: content ?? "" }))
44
+ });
45
+ var instanceOf = (value) => Obj.instanceOf(Spec, value);
46
+ //#endregion
47
+ export { make as i, Spec_exports as n, instanceOf as r, Spec as t };
48
+
49
+ //# sourceMappingURL=chunk-Spec.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-Spec.mjs","names":[],"sources":["../../src/types/Spec.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, DXN, Format, Obj, Ref, Type } from '@dxos/echo';\nimport { FactoryAnnotation, Text } from '@dxos/schema';\n\nimport * as Skill from './Skill.ts';\n\n/**\n * A spec: normative `.mdl` text that its project's work delivers. Its dialects say which block kinds beyond the core\n * and changelog ones the text uses, which a plugin then extracts into objects of its own and keeps as annotations on\n * the spec. A project owns its specs (`Project.specs`), so a spec is not a type of its own in a space. A `.mdl` file's\n * front matter is the spec's fields and meta rather than its text: `name` is `name`, `id` and `version` are the\n * meta's `key` and `version`.\n */\nexport class Spec extends Type.makeObject<Spec>(DXN.make('org.dxos.type.projects.spec', '0.4.0'))(\n Schema.Struct({\n name: Schema.String.pipe(Schema.annotate({ title: 'Name' })),\n\n description: Schema.optional(\n Schema.String.pipe(\n Format.FormatAnnotation.set(Format.TypeFormat.Markdown),\n Schema.annotate({\n title: 'Description',\n description: 'What the spec describes when its work is complete.',\n }),\n ),\n ),\n\n /**\n * The ids of the dialect specs whose blocks the text uses, as a `.mdl` file lists them in its front matter's\n * `extends`. Empty means the core and changelog blocks only.\n */\n dialects: Schema.Array(Schema.String).pipe(Annotation.FormInputAnnotation.set(false)),\n\n /** The `.mdl` text; owned, so it is deleted with the spec. */\n content: Ref.Ref(Text.Text).pipe(Annotation.SetParent.set(), Annotation.FormInputAnnotation.set(false)),\n }).pipe(\n Annotation.LabelAnnotation.set(['name']),\n Annotation.IconAnnotation.set({ icon: 'ph--blueprint--regular', hue: 'violet' }),\n // The feature-map skill edits a spec's blocks, so an agent bound to a spec (a comment on it) can change them. Plain\n // dotted key, so the type does not depend on the plugin that owns the skill.\n Skill.SkillsAnnotation.set(['org.dxos.skill.code.featureMap']),\n // A form's create needs the backing text, which `Obj.make` alone leaves out.\n FactoryAnnotation.set((values): unknown => make({ name: '', ...values })),\n ),\n) {}\n\nexport type MakeProps = Omit<Obj.MakeProps<typeof Spec>, 'dialects' | 'content'> &\n Partial<Pick<Obj.MakeProps<typeof Spec>, 'dialects'>> & {\n /** The `.mdl` text, without front matter; empty by default. */\n content?: string;\n };\n\n/** `dialects` starts as an empty list so two peers lazily creating it cannot each write a fresh one. */\nexport const make = ({ content, dialects = [], ...props }: MakeProps): Spec =>\n Obj.make(Spec, {\n ...props,\n dialects: [...dialects],\n content: Ref.make(Text.make({ content: content ?? '' })),\n });\n\nexport const instanceOf = (value: unknown): value is Spec => Obj.instanceOf(Spec, value);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,IAAa,OAAb,cAA0B,KAAK,WAAiB,IAAI,KAAK,+BAA+B,OAAO,CAAC,CAAC,CAC/F,OAAO,OAAO;CACZ,MAAM,OAAO,OAAO,KAAK,OAAO,SAAS,EAAE,OAAO,OAAO,CAAC,CAAC;CAE3D,aAAa,OAAO,SAClB,OAAO,OAAO,KACZ,OAAO,iBAAiB,IAAI,OAAO,WAAW,QAAQ,GACtD,OAAO,SAAS;EACd,OAAO;EACP,aAAa;CACf,CAAC,CACH,CACF;;;;;CAMA,UAAU,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC,KAAK,WAAW,oBAAoB,IAAI,KAAK,CAAC;;CAGpF,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,KAAK,WAAW,UAAU,IAAI,GAAG,WAAW,oBAAoB,IAAI,KAAK,CAAC;AACxG,CAAC,CAAC,CAAC,KACD,WAAW,gBAAgB,IAAI,CAAC,MAAM,CAAC,GACvC,WAAW,eAAe,IAAI;CAAE,MAAM;CAA0B,KAAK;AAAS,CAAC,GAAA,iBAGxD,IAAI,CAAC,gCAAgC,CAAC,GAE7D,kBAAkB,KAAK,WAAoB,KAAK;CAAE,MAAM;CAAI,GAAG;AAAO,CAAC,CAAC,CAC1E,CACF,CAAC,CAAC,CAAC;;AASH,IAAa,QAAQ,EAAE,SAAS,WAAW,CAAC,GAAG,GAAG,YAChD,IAAI,KAAK,MAAM;CACb,GAAG;CACH,UAAU,CAAC,GAAG,QAAQ;CACtB,SAAS,IAAI,KAAK,KAAK,KAAK,EAAE,SAAS,WAAW,GAAG,CAAC,CAAC;AACzD,CAAC;AAEH,IAAa,cAAc,UAAkC,IAAI,WAAW,MAAM,KAAK"}
@@ -0,0 +1,98 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { t as Spec } from "./chunk-Spec.mjs";
3
+ import * as Option from "effect/Option";
4
+ import * as Schema from "effect/Schema";
5
+ import { Annotation, DXN, Filter, Obj, Query, Ref, Type } from "@dxos/echo";
6
+ //#region src/types/SpecReview.ts
7
+ var SpecReview_exports = /* @__PURE__ */ __exportAll({
8
+ ReviewsAnnotation: () => ReviewsAnnotation,
9
+ SpecReview: () => SpecReview,
10
+ Verdict: () => Verdict,
11
+ VerdictStatus: () => VerdictStatus,
12
+ WalkthroughStep: () => WalkthroughStep,
13
+ byNewest: () => byNewest,
14
+ instanceOf: () => instanceOf,
15
+ make: () => make,
16
+ query: () => query,
17
+ sameReview: () => sameReview
18
+ });
19
+ /**
20
+ * How far the code meets one spec item, least severe first: `done` as specified, `untested` present but with no test
21
+ * that covers it, `partial` in part, `diverged` implemented differently from what the spec says, `missing` not at all.
22
+ */
23
+ var VerdictStatus = Schema.Literals([
24
+ "done",
25
+ "untested",
26
+ "partial",
27
+ "diverged",
28
+ "missing"
29
+ ]);
30
+ /** One segment of a walkthrough: a sentence and the `github:` key of the code it describes. */
31
+ var WalkthroughStep = Schema.Struct({
32
+ text: Schema.String,
33
+ key: Schema.String
34
+ });
35
+ /** A review's judgement of one spec item. */
36
+ var Verdict = Schema.Struct({
37
+ status: VerdictStatus,
38
+ summary: Schema.optional(Schema.String),
39
+ note: Schema.optional(Schema.String),
40
+ /** `github:` keys of the code that supports the verdict. */
41
+ evidence: Schema.Array(Schema.String),
42
+ /** `github:` keys of the tests that exercise the item. */
43
+ tests: Schema.Array(Schema.String),
44
+ /** Where each part of the item is implemented, in reading order. */
45
+ walkthrough: Schema.Array(WalkthroughStep)
46
+ });
47
+ /**
48
+ * One compliance review of a spec: which commit's code was read, when and by whom, and a verdict per spec item. The
49
+ * format is fixed (a `.review.mdl` file's), so a review is created whole and never edited by hand. A spec's history
50
+ * is its reviews; an item's current status is its newest verdict in any of them.
51
+ */
52
+ var SpecReview = class extends Type.makeObject(DXN.make("org.dxos.type.projects.specReview", "0.1.0"))(Schema.Struct({
53
+ spec: Ref.Ref(Spec),
54
+ /** The commit the code was read at. */
55
+ commit: Schema.String,
56
+ /** When the review was made: `YYYY-MM-DD`, or `YYYY-MM-DDTHH:MMZ` in UTC to order the reviews of one day. */
57
+ date: Schema.String,
58
+ /** Who made it: `user:<handle>` or `agent:<name>`. */
59
+ by: Schema.String,
60
+ summary: Schema.optional(Schema.String),
61
+ /** Keyed by spec item id: a block (`Scene`, `F-3`) or a nested requirement (`F-3.2`). */
62
+ verdicts: Schema.Record(Schema.String, Verdict)
63
+ }).pipe(Annotation.IconAnnotation.set({
64
+ icon: "ph--seal-check--regular",
65
+ hue: "violet"
66
+ }))) {};
67
+ /** The reviews a spec holds; the refs make the spec each review's owner, so deleting the spec deletes them. */
68
+ var ReviewsAnnotation = Annotation.make({
69
+ id: "org.dxos.projects.reviews",
70
+ schema: Schema.Array(Ref.Ref(SpecReview))
71
+ });
72
+ /** A review listed on and owned by its spec, so it is deleted with the spec. */
73
+ var make = ({ spec, ...props }) => {
74
+ const review = Obj.make(SpecReview, {
75
+ [Obj.Parent]: spec,
76
+ ...props,
77
+ spec: Ref.make(spec)
78
+ });
79
+ const ref = Ref.make(review);
80
+ if (Option.isNone(Annotation.get(spec, ReviewsAnnotation))) Obj.update(spec, (spec) => {
81
+ Annotation.set(spec, ReviewsAnnotation, [ref]);
82
+ });
83
+ else Annotation.update(spec, ReviewsAnnotation, (reviews) => {
84
+ reviews.push(ref);
85
+ });
86
+ return review;
87
+ };
88
+ var instanceOf = (value) => Obj.instanceOf(SpecReview, value);
89
+ /** The reviews of a spec; none without one. */
90
+ var query = (spec) => Query.select(spec ? Filter.id(spec.id) : Filter.nothing()).referencedBy(SpecReview, "spec");
91
+ /** Whether two reviews are the same one: the same commit, date and reviewer. */
92
+ var sameReview = (a, b) => a.commit === b.commit && a.date === b.date && a.by === b.by;
93
+ /** Newest first, by review date; a date with a time orders after that day's plain date. */
94
+ var byNewest = (a, b) => b.date.localeCompare(a.date);
95
+ //#endregion
96
+ export { VerdictStatus as a, instanceOf as c, sameReview as d, Verdict as i, make as l, SpecReview as n, WalkthroughStep as o, SpecReview_exports as r, byNewest as s, ReviewsAnnotation as t, query as u };
97
+
98
+ //# sourceMappingURL=chunk-SpecReview.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-SpecReview.mjs","names":["Spec.Spec"],"sources":["../../src/types/SpecReview.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, DXN, Filter, Obj, Query, Ref, Type } from '@dxos/echo';\n\nimport * as Spec from './Spec.ts';\n\n/**\n * How far the code meets one spec item, least severe first: `done` as specified, `untested` present but with no test\n * that covers it, `partial` in part, `diverged` implemented differently from what the spec says, `missing` not at all.\n */\nexport const VerdictStatus = Schema.Literals(['done', 'untested', 'partial', 'diverged', 'missing']);\nexport type VerdictStatus = Schema.Schema.Type<typeof VerdictStatus>;\n\n/** One segment of a walkthrough: a sentence and the `github:` key of the code it describes. */\nexport const WalkthroughStep = Schema.Struct({ text: Schema.String, key: Schema.String });\nexport interface WalkthroughStep extends Schema.Schema.Type<typeof WalkthroughStep> {}\n\n/** A review's judgement of one spec item. */\nexport const Verdict = Schema.Struct({\n status: VerdictStatus,\n summary: Schema.optional(Schema.String),\n note: Schema.optional(Schema.String),\n /** `github:` keys of the code that supports the verdict. */\n evidence: Schema.Array(Schema.String),\n /** `github:` keys of the tests that exercise the item. */\n tests: Schema.Array(Schema.String),\n /** Where each part of the item is implemented, in reading order. */\n walkthrough: Schema.Array(WalkthroughStep),\n});\nexport interface Verdict extends Schema.Schema.Type<typeof Verdict> {}\n\n/**\n * One compliance review of a spec: which commit's code was read, when and by whom, and a verdict per spec item. The\n * format is fixed (a `.review.mdl` file's), so a review is created whole and never edited by hand. A spec's history\n * is its reviews; an item's current status is its newest verdict in any of them.\n */\nexport class SpecReview extends Type.makeObject<SpecReview>(DXN.make('org.dxos.type.projects.specReview', '0.1.0'))(\n Schema.Struct({\n spec: Ref.Ref(Spec.Spec),\n /** The commit the code was read at. */\n commit: Schema.String,\n /** When the review was made: `YYYY-MM-DD`, or `YYYY-MM-DDTHH:MMZ` in UTC to order the reviews of one day. */\n date: Schema.String,\n /** Who made it: `user:<handle>` or `agent:<name>`. */\n by: Schema.String,\n summary: Schema.optional(Schema.String),\n /** Keyed by spec item id: a block (`Scene`, `F-3`) or a nested requirement (`F-3.2`). */\n verdicts: Schema.Record(Schema.String, Verdict),\n }).pipe(Annotation.IconAnnotation.set({ icon: 'ph--seal-check--regular', hue: 'violet' })),\n) {}\n\n/** The reviews a spec holds; the refs make the spec each review's owner, so deleting the spec deletes them. */\nexport const ReviewsAnnotation = Annotation.make({\n id: 'org.dxos.projects.reviews',\n schema: Schema.Array(Ref.Ref(SpecReview)),\n});\n\nexport type MakeProps = Omit<Obj.MakeProps<typeof SpecReview>, 'spec'> & { spec: Spec.Spec };\n\n/** A review listed on and owned by its spec, so it is deleted with the spec. */\nexport const make = ({ spec, ...props }: MakeProps): SpecReview => {\n const review = Obj.make(SpecReview, { [Obj.Parent]: spec, ...props, spec: Ref.make(spec) });\n const ref = Ref.make(review);\n if (Option.isNone(Annotation.get(spec, ReviewsAnnotation))) {\n Obj.update(spec, (spec) => {\n Annotation.set(spec, ReviewsAnnotation, [ref]);\n });\n } else {\n // Appended in place, so two peers recording reviews each keep theirs.\n Annotation.update(spec, ReviewsAnnotation, (reviews) => {\n reviews.push(ref);\n });\n }\n return review;\n};\n\nexport const instanceOf = (value: unknown): value is SpecReview => Obj.instanceOf(SpecReview, value);\n\n/** The reviews of a spec; none without one. */\nexport const query = (spec: Spec.Spec | undefined) =>\n Query.select(spec ? Filter.id(spec.id) : Filter.nothing()).referencedBy(SpecReview, 'spec');\n\n/** Whether two reviews are the same one: the same commit, date and reviewer. */\nexport const sameReview = (\n a: Pick<SpecReview, 'commit' | 'date' | 'by'>,\n b: Pick<SpecReview, 'commit' | 'date' | 'by'>,\n) => a.commit === b.commit && a.date === b.date && a.by === b.by;\n\n/** Newest first, by review date; a date with a time orders after that day's plain date. */\nexport const byNewest = (a: Pick<SpecReview, 'date'>, b: Pick<SpecReview, 'date'>): number =>\n b.date.localeCompare(a.date);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,IAA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