@picassohq/cli 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/agents/browser_agent.yaml +53 -0
  2. package/agents/code_reviewer.yaml +49 -0
  3. package/agents/codebase_investigator.yaml +70 -0
  4. package/agents/design_auditor.yaml +50 -0
  5. package/agents/devex_auditor.yaml +50 -0
  6. package/agents/doc_writer.yaml +54 -0
  7. package/agents/engineering_architect.yaml +51 -0
  8. package/agents/generalist.yaml +55 -0
  9. package/agents/migration_planner.yaml +51 -0
  10. package/agents/product_reviewer.yaml +48 -0
  11. package/agents/qa_operator.yaml +52 -0
  12. package/agents/release_engineer.yaml +50 -0
  13. package/agents/security_auditor.yaml +62 -0
  14. package/agents/test_writer.yaml +52 -0
  15. package/assets/first-light-lockup.png +0 -0
  16. package/assets/first-light-tagline.png +0 -0
  17. package/assets/house/README.md +26 -0
  18. package/assets/house/auraone-banner.png +0 -0
  19. package/assets/house/auraone-logo.png +0 -0
  20. package/assets/house/kiro-prism-banner.png +0 -0
  21. package/assets/house/kiro-prism-logo.png +0 -0
  22. package/assets/house/picasso-banner.png +0 -0
  23. package/assets/house/picasso-logo.png +0 -0
  24. package/assets/wordmark-app.png +0 -0
  25. package/assets/wordmark-tight.png +0 -0
  26. package/assets/wordmark.png +0 -0
  27. package/design/styles.css +1042 -0
  28. package/dist/build-info.json +37 -0
  29. package/dist/index.js +3028 -0
  30. package/goals/cli-hardening.yaml +40 -0
  31. package/goals/repo-maintenance.yaml +40 -0
  32. package/package.json +49 -4
  33. package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
  34. package/runtime/dsh/picasso-ecosystem.community.json +185 -0
  35. package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
  36. package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
  37. package/runtime/dsh/picasso-isolation.patch.yml +25 -0
  38. package/runtime/dsh/picasso-providers.patch.yml +373 -0
  39. package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
  40. package/runtime/dsh/picasso-sdk.patch.yml +204 -0
  41. package/runtime/engine-manifest.json +214 -0
  42. package/runtime/package.json +6 -0
  43. package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
  44. package/runtime/packages/picasso-cache-probe/index.js +477 -0
  45. package/runtime/packages/picasso-cache-probe/package.json +38 -0
  46. package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
  47. package/runtime/packages/picasso-commands/fresh-review.js +573 -0
  48. package/runtime/packages/picasso-commands/index.js +497 -0
  49. package/runtime/packages/picasso-commands/package.json +28 -0
  50. package/runtime/packages/picasso-instructions/conflicts.js +115 -0
  51. package/runtime/packages/picasso-instructions/formats.js +145 -0
  52. package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
  53. package/runtime/packages/picasso-instructions/glob.js +114 -0
  54. package/runtime/packages/picasso-instructions/globals.js +90 -0
  55. package/runtime/packages/picasso-instructions/imports.js +123 -0
  56. package/runtime/packages/picasso-instructions/index.js +326 -0
  57. package/runtime/packages/picasso-instructions/modes.js +64 -0
  58. package/runtime/packages/picasso-instructions/package.json +30 -0
  59. package/runtime/packages/picasso-instructions/parse.js +134 -0
  60. package/runtime/packages/picasso-instructions/report.js +161 -0
  61. package/runtime/packages/picasso-instructions/resolve.js +939 -0
  62. package/runtime/packages/picasso-instructions/scan.js +181 -0
  63. package/runtime/packages/picasso-instructions/settings.js +150 -0
  64. package/runtime/packages/picasso-instructions/skills.js +345 -0
  65. package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
  66. package/runtime/packages/picasso-lean-context/index.js +6049 -0
  67. package/runtime/packages/picasso-lean-context/package.json +26 -0
  68. package/runtime/packages/picasso-lean-context/timeline.js +417 -0
  69. package/runtime/packages/picasso-librarian/classify.js +146 -0
  70. package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
  71. package/runtime/packages/picasso-librarian/index.js +878 -0
  72. package/runtime/packages/picasso-librarian/notes.js +159 -0
  73. package/runtime/packages/picasso-librarian/package.json +34 -0
  74. package/runtime/packages/picasso-librarian/state.js +478 -0
  75. package/runtime/packages/picasso-memory/index.js +1184 -0
  76. package/runtime/packages/picasso-memory/package.json +21 -0
  77. package/runtime/packages/picasso-model-router/connections.js +895 -0
  78. package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
  79. package/runtime/packages/picasso-model-router/index.js +1081 -0
  80. package/runtime/packages/picasso-model-router/package.json +30 -0
  81. package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
  82. package/runtime/packages/picasso-options/index.js +263 -0
  83. package/runtime/packages/picasso-options/package.json +28 -0
  84. package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
  85. package/runtime/packages/picasso-progress-reports/index.js +267 -0
  86. package/runtime/packages/picasso-progress-reports/package.json +30 -0
  87. package/runtime/packages/picasso-progress-reports/report.js +235 -0
  88. package/runtime/packages/picasso-sdk-server/aside.js +128 -0
  89. package/runtime/packages/picasso-sdk-server/connections.js +38 -0
  90. package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
  91. package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
  92. package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
  93. package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
  94. package/runtime/packages/picasso-sdk-server/goal.js +131 -0
  95. package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
  96. package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
  97. package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
  98. package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
  99. package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
  100. package/runtime/packages/picasso-sdk-server/index.js +886 -0
  101. package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
  102. package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
  103. package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
  104. package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
  105. package/runtime/packages/picasso-sdk-server/package.json +50 -0
  106. package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
  107. package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
  108. package/runtime/packages/picasso-sdk-server/queue.js +322 -0
  109. package/runtime/packages/picasso-sdk-server/requester.js +43 -0
  110. package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
  111. package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
  112. package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
  113. package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
  114. package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
  115. package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
  116. package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
  117. package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
  118. package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
  119. package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
  120. package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
  121. package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
  122. package/runtime/packages/picasso-web-search/backends.js +350 -0
  123. package/runtime/packages/picasso-web-search/config.js +121 -0
  124. package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
  125. package/runtime/packages/picasso-web-search/failure.js +111 -0
  126. package/runtime/packages/picasso-web-search/format.js +35 -0
  127. package/runtime/packages/picasso-web-search/index.js +66 -0
  128. package/runtime/packages/picasso-web-search/package.json +38 -0
  129. package/runtime/packages/picasso-web-search/router.js +155 -0
  130. package/runtime/packages/picasso-x-reader/circle.js +324 -0
  131. package/runtime/packages/picasso-x-reader/command.js +169 -0
  132. package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
  133. package/runtime/packages/picasso-x-reader/index.js +170 -0
  134. package/runtime/packages/picasso-x-reader/package.json +39 -0
  135. package/runtime/packages/picasso-x-reader/read.js +370 -0
  136. package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
  137. package/runtime/packages/picasso-x-reader/settings.js +131 -0
  138. package/runtime/packages/picasso-x-reader/urls.js +154 -0
  139. package/runtime/packages/picasso-x-reader/xmd.js +512 -0
  140. package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
  141. package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
  142. package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
  143. package/runtime/plugins/picasso-auto-approve/package.json +28 -0
  144. package/runtime/plugins/picasso-browser/index.js +424 -0
  145. package/runtime/plugins/picasso-browser/package.json +28 -0
  146. package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
  147. package/runtime/plugins/picasso-checkpoints/index.js +885 -0
  148. package/runtime/plugins/picasso-checkpoints/package.json +29 -0
  149. package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
  150. package/runtime/plugins/picasso-commands/index.js +497 -0
  151. package/runtime/plugins/picasso-commands/package.json +28 -0
  152. package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
  153. package/runtime/plugins/picasso-instructions/formats.js +145 -0
  154. package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
  155. package/runtime/plugins/picasso-instructions/glob.js +114 -0
  156. package/runtime/plugins/picasso-instructions/globals.js +90 -0
  157. package/runtime/plugins/picasso-instructions/imports.js +123 -0
  158. package/runtime/plugins/picasso-instructions/index.js +326 -0
  159. package/runtime/plugins/picasso-instructions/modes.js +64 -0
  160. package/runtime/plugins/picasso-instructions/package.json +30 -0
  161. package/runtime/plugins/picasso-instructions/parse.js +134 -0
  162. package/runtime/plugins/picasso-instructions/report.js +161 -0
  163. package/runtime/plugins/picasso-instructions/resolve.js +939 -0
  164. package/runtime/plugins/picasso-instructions/scan.js +181 -0
  165. package/runtime/plugins/picasso-instructions/settings.js +150 -0
  166. package/runtime/plugins/picasso-instructions/skills.js +345 -0
  167. package/runtime/plugins/picasso-lean-context/index.js +6049 -0
  168. package/runtime/plugins/picasso-lean-context/package.json +26 -0
  169. package/runtime/plugins/picasso-lean-context/timeline.js +417 -0
  170. package/runtime/plugins/picasso-librarian/classify.js +146 -0
  171. package/runtime/plugins/picasso-librarian/index.js +878 -0
  172. package/runtime/plugins/picasso-librarian/notes.js +159 -0
  173. package/runtime/plugins/picasso-librarian/package.json +34 -0
  174. package/runtime/plugins/picasso-librarian/state.js +478 -0
  175. package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
  176. package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
  177. package/runtime/plugins/picasso-mail/inbox.js +207 -0
  178. package/runtime/plugins/picasso-mail/index.js +293 -0
  179. package/runtime/plugins/picasso-mail/package.json +22 -0
  180. package/runtime/plugins/picasso-memory/index.js +1184 -0
  181. package/runtime/plugins/picasso-memory/package.json +21 -0
  182. package/runtime/plugins/picasso-model-router/connections.js +895 -0
  183. package/runtime/plugins/picasso-model-router/index.js +1081 -0
  184. package/runtime/plugins/picasso-model-router/package.json +30 -0
  185. package/runtime/plugins/picasso-options/index.js +263 -0
  186. package/runtime/plugins/picasso-options/package.json +28 -0
  187. package/runtime/plugins/picasso-progress-reports/index.js +267 -0
  188. package/runtime/plugins/picasso-progress-reports/package.json +30 -0
  189. package/runtime/plugins/picasso-progress-reports/report.js +235 -0
  190. package/runtime/plugins/picasso-provider-models/index.js +436 -0
  191. package/runtime/plugins/picasso-provider-models/package.json +28 -0
  192. package/runtime/plugins/picasso-repo-index/index.js +1850 -0
  193. package/runtime/plugins/picasso-repo-index/package.json +28 -0
  194. package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
  195. package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
  196. package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
  197. package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
  198. package/runtime/plugins/picasso-trackers/index.js +895 -0
  199. package/runtime/plugins/picasso-trackers/package.json +28 -0
  200. package/runtime/plugins/picasso-web-search/backends.js +350 -0
  201. package/runtime/plugins/picasso-web-search/config.js +121 -0
  202. package/runtime/plugins/picasso-web-search/failure.js +111 -0
  203. package/runtime/plugins/picasso-web-search/format.js +35 -0
  204. package/runtime/plugins/picasso-web-search/index.js +66 -0
  205. package/runtime/plugins/picasso-web-search/package.json +38 -0
  206. package/runtime/plugins/picasso-web-search/router.js +155 -0
  207. package/runtime/plugins/picasso-x-reader/circle.js +324 -0
  208. package/runtime/plugins/picasso-x-reader/command.js +169 -0
  209. package/runtime/plugins/picasso-x-reader/index.js +170 -0
  210. package/runtime/plugins/picasso-x-reader/package.json +39 -0
  211. package/runtime/plugins/picasso-x-reader/read.js +370 -0
  212. package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
  213. package/runtime/plugins/picasso-x-reader/settings.js +131 -0
  214. package/runtime/plugins/picasso-x-reader/urls.js +154 -0
  215. package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
  216. package/runtime/relay/attachment-text.mjs +737 -0
  217. package/runtime/relay/companion/companion.css +126 -0
  218. package/runtime/relay/companion/companion.js +648 -0
  219. package/runtime/relay/companion/icon.svg +5 -0
  220. package/runtime/relay/companion/index.html +25 -0
  221. package/runtime/relay/companion/manifest.json +13 -0
  222. package/runtime/relay/companion/sw.js +41 -0
  223. package/runtime/relay/main.mjs +37252 -0
  224. package/runtime/relay/model-listing.mjs +614 -0
  225. package/runtime/relay/versions-routes.mjs +1198 -0
  226. package/runtime/verify-plugins.mjs +205 -0
  227. package/runtime-lock/package-lock.json +10779 -0
  228. package/runtime-lock/package.json +7 -0
  229. package/scripts/install-runtime.mjs +400 -0
  230. package/README.md +0 -3
@@ -0,0 +1,211 @@
1
+ // Live token deltas for SDK clients.
2
+ //
3
+ // dsh's SDK server only notifies durable `session.event` envelopes, so a
4
+ // step's text reaches the client in one piece when `assistant/message` lands.
5
+ // This taps dsh's `llm/stream` waterfall and mirrors every `text-delta` /
6
+ // `reasoning-delta` chunk as a `session.delta` notification
7
+ // `{ sessionId, kind: 'text' | 'reasoning', text }`. Chunks are passed through
8
+ // unchanged and undelayed; forwarding failures are swallowed so they can never
9
+ // break generation. The durable `assistant/message` stays the source of truth.
10
+ //
11
+ // Whole responses: a route whose upstream cannot stream yields one giant
12
+ // `text-delta` chunk, which clients used to repaint in a single jump. Chunks
13
+ // larger than DELTA_PIECE_CHARS are therefore re-revealed as smaller
14
+ // `session.delta` pieces, paced so a coalescing renderer sees real progress.
15
+ // The pieces are exact substrings — the reveal drains BEFORE the chunk is
16
+ // handed on, so it can never be overtaken by the durable `assistant/message`
17
+ // (which would tail-fill a duplicate tail). A cancelled iterator stops the
18
+ // reveal immediately; a failed attempt's reset drops it.
19
+ //
20
+ // Attribution: dsh-agent-loop stamps every loop-built request with its own
21
+ // agent's `sessionId` (a subagent's loop carries the child session id), so a
22
+ // delta is tagged with exactly the session whose loop made the call. Calls
23
+ // without a session id and auxiliary calls (`purpose`: compaction, session
24
+ // title) are not forwarded.
25
+ //
26
+ // Retries: dsh-llm-retry makes a fresh `llm/stream` call for the next attempt
27
+ // (after `llm/retry-started`). When the failed attempt already forwarded
28
+ // deltas, `{ sessionId, kind: 'reset' }` is notified once, before the new
29
+ // attempt's first delta (on `llm/retry-started`, or at the start of the next
30
+ // stream when no durable `assistant/message` closed the previous one), so a
31
+ // client drops the live text of the failed attempt.
32
+
33
+ export const SESSION_DELTA_METHOD = 'session.delta';
34
+
35
+ const DELTA_KINDS = Object.freeze({ 'text-delta': 'text', 'reasoning-delta': 'reasoning' });
36
+
37
+ /** Chunks larger than this are re-revealed as ~this-sized pieces. */
38
+ export const DELTA_PIECE_CHARS = 48;
39
+ /** Delay between reveal pieces when a whole response is re-chunked. */
40
+ export const DELTA_PIECE_DELAY_MS = 18;
41
+ /** Upper bound on how long a whole-response reveal may stretch. */
42
+ export const DELTA_MAX_REVEAL_MS = 2500;
43
+
44
+ const defaultSleep = (ms) =>
45
+ new Promise((resolve) => {
46
+ const timer = setTimeout(resolve, ms);
47
+ timer.unref?.();
48
+ });
49
+
50
+ const isDeltaBoundary = (char) => char === undefined || /\s/u.test(char);
51
+
52
+ /**
53
+ * Ordered word-boundary pieces of `text`, each ≤ `pieceChars` unless a single
54
+ * word is longer (then it hard-splits, never inside a surrogate pair). Pure
55
+ * substrings: concatenating the pieces reproduces `text` byte-for-byte.
56
+ */
57
+ export function* deltaPieces(text, pieceChars = DELTA_PIECE_CHARS) {
58
+ if (text.length <= pieceChars) {
59
+ if (text.length > 0) yield text;
60
+ return;
61
+ }
62
+ let start = 0;
63
+ while (start < text.length) {
64
+ let end = Math.min(start + pieceChars, text.length);
65
+ if (end < text.length && !isDeltaBoundary(text[end - 1]) && !isDeltaBoundary(text[end])) {
66
+ let boundary = -1;
67
+ for (let index = end - 1; index > start; index -= 1) {
68
+ if (isDeltaBoundary(text[index])) {
69
+ boundary = index;
70
+ break;
71
+ }
72
+ }
73
+ if (boundary !== -1) {
74
+ end = boundary;
75
+ } else if (text.charCodeAt(end - 1) >= 0xd800 && text.charCodeAt(end - 1) <= 0xdbff) {
76
+ end -= 1;
77
+ }
78
+ }
79
+ if (end > start) yield text.slice(start, end);
80
+ start = end;
81
+ }
82
+ }
83
+
84
+ /** The session a model request belongs to, or undefined when its deltas must not be forwarded. */
85
+ export function deltaSessionOf(options) {
86
+ try {
87
+ if (options === null || typeof options !== 'object') return undefined;
88
+ if (options.purpose !== undefined) return undefined;
89
+ const sessionId = options.sessionId;
90
+ if (typeof sessionId !== 'string' || sessionId.length === 0) return undefined;
91
+ return sessionId;
92
+ } catch {
93
+ return undefined;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Wrap a chunk stream so each text/reasoning delta is reported to `emit`
99
+ * before the chunk is handed on. The iterator protocol (next/return/throw) is
100
+ * delegated as is; the returned iterable yields exactly the source's chunks.
101
+ *
102
+ * A chunk carrying a whole response (`text` longer than `pace.pieceChars`) is
103
+ * re-revealed as paced pieces, awaited inside `next()` — the reveal finishes
104
+ * (or is cancelled by return/throw) before the consumer sees the chunk, so
105
+ * the durable `assistant/message` can never overtake live pieces.
106
+ */
107
+ export function tapStreamDeltas(source, sessionId, emit, pace = {}) {
108
+ if (source === null || typeof source !== 'object' || typeof source[Symbol.asyncIterator] !== 'function') return source;
109
+ const pieceChars = pace.pieceChars ?? DELTA_PIECE_CHARS;
110
+ const pieceDelayMs = pace.pieceDelayMs ?? DELTA_PIECE_DELAY_MS;
111
+ const maxRevealMs = pace.maxRevealMs ?? DELTA_MAX_REVEAL_MS;
112
+ const sleep = pace.sleep ?? defaultSleep;
113
+ return {
114
+ [Symbol.asyncIterator]() {
115
+ const iterator = source[Symbol.asyncIterator]();
116
+ let closed = false;
117
+ const report = async (chunk) => {
118
+ try {
119
+ const kind = DELTA_KINDS[chunk?.type];
120
+ if (kind === undefined || typeof chunk.text !== 'string' || chunk.text.length === 0) return;
121
+ const text = chunk.text;
122
+ if (text.length <= pieceChars) {
123
+ emit({ sessionId, kind, text });
124
+ return;
125
+ }
126
+ const pieces = [...deltaPieces(text, pieceChars)];
127
+ // Spread the reveal over at most maxRevealMs, at pieceDelayMs a step.
128
+ const delay = Math.min(pieceDelayMs, maxRevealMs / pieces.length);
129
+ for (let index = 0; index < pieces.length; index += 1) {
130
+ if (closed) return;
131
+ if (index > 0 && delay > 0) await sleep(delay);
132
+ if (closed) return;
133
+ try {
134
+ emit({ sessionId, kind, text: pieces[index] });
135
+ } catch {
136
+ // forwarding is best-effort and never affects the model stream
137
+ }
138
+ }
139
+ } catch {
140
+ // forwarding is best-effort and never affects the model stream
141
+ }
142
+ };
143
+ const wrapped = {
144
+ async next(...args) {
145
+ const result = await iterator.next(...args);
146
+ if (result?.done !== true) await report(result?.value);
147
+ return result;
148
+ },
149
+ };
150
+ if (typeof iterator.return === 'function') {
151
+ wrapped.return = (...args) => {
152
+ closed = true;
153
+ return iterator.return(...args);
154
+ };
155
+ }
156
+ if (typeof iterator.throw === 'function') {
157
+ wrapped.throw = (...args) => {
158
+ closed = true;
159
+ return iterator.throw(...args);
160
+ };
161
+ }
162
+ return wrapped;
163
+ },
164
+ };
165
+ }
166
+
167
+ /**
168
+ * Install the `llm/stream` tap. `enabled()` gates forwarding (the client
169
+ * opts in through `picasso/capabilities`); `notify(method, params)` writes
170
+ * the notification. `pace` optionally overrides the whole-response reveal
171
+ * cadence (pieceChars / pieceDelayMs / maxRevealMs / sleep). Registered global
172
+ * so model calls made under isolated `llm` services (subagent scopes) are
173
+ * attributed too.
174
+ */
175
+ export function installStreamDeltas(ctx, { enabled, notify, pace }) {
176
+ /** Sessions whose current attempt forwarded deltas that no durable message has closed yet. */
177
+ const open = new Set();
178
+ const reset = (sessionId) => {
179
+ if (!open.delete(sessionId)) return;
180
+ try {
181
+ notify(SESSION_DELTA_METHOD, { sessionId, kind: 'reset' });
182
+ } catch {
183
+ // best-effort, like every delta
184
+ }
185
+ };
186
+ const disposeEvents = ctx.on('session/event', (session, event) => {
187
+ const sessionId = session?.id === undefined ? undefined : String(session.id);
188
+ if (sessionId === undefined) return;
189
+ if (event?.type === 'llm/retry-started') reset(sessionId);
190
+ else if (event?.type === 'assistant/message' || event?.type === 'turn/end') open.delete(sessionId);
191
+ });
192
+ const disposeStream = ctx.on('llm/stream', (options, next) => {
193
+ let sessionId;
194
+ try {
195
+ sessionId = enabled() ? deltaSessionOf(options) : undefined;
196
+ } catch {
197
+ sessionId = undefined;
198
+ }
199
+ if (sessionId !== undefined) reset(sessionId);
200
+ const source = next();
201
+ if (sessionId === undefined) return source;
202
+ return tapStreamDeltas(source, sessionId, (params) => {
203
+ open.add(sessionId);
204
+ notify(SESSION_DELTA_METHOD, params);
205
+ }, pace);
206
+ }, { global: true, prepend: true });
207
+ return () => {
208
+ disposeEvents?.();
209
+ disposeStream?.();
210
+ };
211
+ }
@@ -0,0 +1,451 @@
1
+ // Named, durable task lists shared across sessions and agents (upstream ask
2
+ // T4.8). `/tasks` shows only the attached session's background jobs; these
3
+ // methods expose claimable boards any client or agent session can read and
4
+ // transition through the SDK.
5
+ //
6
+ // team/task/lists { sessionId } -> { lists }
7
+ // Every named list anchored in the session's log,
8
+ // with per-status counts.
9
+ // team/task/list { sessionId, list, includeClosed? } -> { list, tasks }
10
+ // Current non-deleted task snapshots in id order.
11
+ // team/task/create { sessionId, list, subject, description?, blockedBy?, writeScopes? }
12
+ // -> { list, task }
13
+ // team/task/claim { sessionId, list, taskId, owner?, expectedRevision? }
14
+ // -> { list, task }
15
+ // pending -> in_progress; refuses a task another owner
16
+ // holds (`team/task-claimed`) unless `force` is set.
17
+ // team/task/complete { sessionId, list, taskId, owner? } -> { list, task }
18
+ // team/task/delete { sessionId, list, taskId } -> { list, task }
19
+ // Tombstones (`status: 'deleted'`); the log keeps the
20
+ // record, readers filter it.
21
+ //
22
+ // Durability and broadcast ride dsh's own session log: every mutation appends
23
+ // a real `team/task` session event whose payload mirrors the experimental
24
+ // agent-team contract (`{ version: 2, teamId, task }`, task in
25
+ // TeamTaskSnapshot shape). The append lands in the anchor session's durable
26
+ // log — it survives runtime restart and resume, is carried through fork like
27
+ // every other log event, and reaches attached clients through the normal
28
+ // `session.event` notification + `agentTeam`-style folding (the TUI's
29
+ // `listTeamState` already folds this type). A named list is a `teamId`
30
+ // namespace (`list/<name>`): the anchor session's log is the board's home,
31
+ // exactly like dsh storing team tasks only in the Team Lead's log, and any
32
+ // client or teammate session manages it by naming the anchor `sessionId`.
33
+ //
34
+ // Reads fold the log through `sessionQuery.observeSession`, so they work for
35
+ // any persisted session even when it is not attached; writes need the anchor
36
+ // session live (its Session owns append). `expectedRevision` is the
37
+ // compare-and-set guard matching the agent-team update verb.
38
+ //
39
+ // Errors carry codes as a `code: message` prefix (the SDK transport only
40
+ // forwards the message): session/not-found, gateway/bad-request,
41
+ // team/task-not-found, team/task-claimed, team/task-closed,
42
+ // team/revision-conflict.
43
+
44
+ export const TEAM_TASK_METHODS = Object.freeze([
45
+ 'team/task/lists',
46
+ 'team/task/list',
47
+ 'team/task/create',
48
+ 'team/task/claim',
49
+ 'team/task/complete',
50
+ 'team/task/delete',
51
+ ]);
52
+
53
+ /** `team/task` events under this `teamId` prefix are Picasso named lists (dsh agent-team boards use raw session ids). */
54
+ export const TEAM_LIST_PREFIX = 'list/';
55
+ /** Event payload version, matching dsh's `team/task` SessionEventMap declaration. */
56
+ export const TEAM_TASK_EVENT_VERSION = 2;
57
+
58
+ const TASK_STATUSES = new Set(['pending', 'in_progress', 'completed', 'deleted']);
59
+ const MAX_LIST_NAME = 80;
60
+ const MAX_SUBJECT = 200;
61
+ const MAX_DESCRIPTION = 4000;
62
+
63
+ export class TeamTaskError extends Error {
64
+ constructor(code, message, data = {}) {
65
+ super(`${code}: ${message}`);
66
+ this.name = 'TeamTaskError';
67
+ this.code = code;
68
+ this.data = data;
69
+ }
70
+ }
71
+
72
+ /** The `teamId` namespace one named list occupies inside a session log. */
73
+ export function teamIdForList(list) {
74
+ return `${TEAM_LIST_PREFIX}${list}`;
75
+ }
76
+
77
+ /** The list name a `teamId` namespaces, or undefined for non-list teams. */
78
+ export function listForTeamId(teamId) {
79
+ return typeof teamId === 'string' && teamId.startsWith(TEAM_LIST_PREFIX)
80
+ ? teamId.slice(TEAM_LIST_PREFIX.length)
81
+ : undefined;
82
+ }
83
+
84
+ function isRecord(value) {
85
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
86
+ }
87
+
88
+ function cleanString(value, what, max) {
89
+ if (typeof value !== 'string' || value.trim().length === 0) {
90
+ throw new TeamTaskError('gateway/bad-request', `${what} must be a non-empty string`);
91
+ }
92
+ const trimmed = value.trim();
93
+ if ([...trimmed].length > max) throw new TeamTaskError('gateway/bad-request', `${what} must be at most ${max} characters`);
94
+ return trimmed;
95
+ }
96
+
97
+ function optionalString(value, what, max) {
98
+ if (value === undefined || value === null) return undefined;
99
+ return cleanString(value, what, max);
100
+ }
101
+
102
+ function stringArray(value, what) {
103
+ if (value === undefined) return [];
104
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== 'string' || entry.length === 0)) {
105
+ throw new TeamTaskError('gateway/bad-request', `${what} must be an array of strings`);
106
+ }
107
+ return [...new Set(value)];
108
+ }
109
+
110
+ /** A task snapshot as folded from the log; extra Picasso fields (list, title, assignee, timestamps) extend the dsh TeamTaskSnapshot shape. */
111
+ function sanitizeTask(task) {
112
+ if (!isRecord(task)) return undefined;
113
+ const id = typeof task.id === 'string' && task.id.length > 0 ? task.id : undefined;
114
+ const status = TASK_STATUSES.has(task.status) ? task.status : undefined;
115
+ if (id === undefined || status === undefined) return undefined;
116
+ return {
117
+ id,
118
+ revision: Number.isSafeInteger(task.revision) && task.revision >= 1 ? task.revision : 1,
119
+ subject: typeof task.subject === 'string' ? task.subject : '',
120
+ description: typeof task.description === 'string' ? task.description : '',
121
+ status,
122
+ blockedBy: Array.isArray(task.blockedBy) ? task.blockedBy.filter((entry) => typeof entry === 'string') : [],
123
+ writeScopes: Array.isArray(task.writeScopes) ? task.writeScopes.filter((entry) => typeof entry === 'string') : [],
124
+ ...(typeof task.ownerId === 'string' ? { ownerId: task.ownerId } : {}),
125
+ ...(typeof task.ownerName === 'string' ? { ownerName: task.ownerName } : {}),
126
+ ...(typeof task.assignee === 'string' ? { assignee: task.assignee } : {}),
127
+ ...(typeof task.title === 'string' ? { title: task.title } : {}),
128
+ ...(typeof task.list === 'string' ? { list: task.list } : {}),
129
+ ...(typeof task.createdAt === 'string' ? { createdAt: task.createdAt } : {}),
130
+ ...(typeof task.updatedAt === 'string' ? { updatedAt: task.updatedAt } : {}),
131
+ ...(typeof task.createdBy === 'string' ? { createdBy: task.createdBy } : {}),
132
+ ...(typeof task.completedBy === 'string' ? { completedBy: task.completedBy } : {}),
133
+ };
134
+ }
135
+
136
+ /** Fold `team/task` events into per-list task snapshots (latest revision wins per task id). */
137
+ function foldTasks(events) {
138
+ const lists = new Map();
139
+ for (const event of events ?? []) {
140
+ if (event?.type !== 'team/task' || !isRecord(event.data)) continue;
141
+ const list = listForTeamId(event.data.teamId);
142
+ if (list === undefined) continue;
143
+ const task = sanitizeTask(event.data.task);
144
+ if (task === undefined) continue;
145
+ let tasks = lists.get(list);
146
+ if (tasks === undefined) {
147
+ tasks = new Map();
148
+ lists.set(list, tasks);
149
+ }
150
+ const prior = tasks.get(task.id);
151
+ if (prior === undefined || task.revision >= prior.revision) tasks.set(task.id, task);
152
+ }
153
+ return lists;
154
+ }
155
+
156
+ const NUMERIC_ID = /^t-(\d+)$/u;
157
+
158
+ /** The next `t-<n>` id inside one list (stable and short for the CLI verbs). */
159
+ function nextTaskId(tasks) {
160
+ let highest = 0;
161
+ for (const id of tasks.keys()) {
162
+ const match = NUMERIC_ID.exec(id);
163
+ if (match !== null) highest = Math.max(highest, Number.parseInt(match[1], 10));
164
+ }
165
+ return `t-${highest + 1}`;
166
+ }
167
+
168
+ /**
169
+ * @param {object} deps
170
+ * @param {(sessionId: string) => any} deps.agentFor - the live agent (undefined when not attached); writes append to its session log.
171
+ * @param {(sessionId: string) => Promise<readonly any[]>} deps.eventsFor - the session's durable events (sessionQuery.observeSession's log snapshot).
172
+ * @param {(message: string) => void} [deps.warn] - hydration failures are reported here.
173
+ */
174
+ export function createTeamTasks({ agentFor, eventsFor, warn = () => {} }) {
175
+ /** Folded per-session list state; held between hydration and observed appends. */
176
+ const boards = new Map();
177
+ const hydrated = new Set();
178
+ const hydrating = new Map();
179
+ /** `team/task` events seen live before hydration, keyed by sessionId then seq. */
180
+ const pendingEvents = new Map();
181
+ /** Serializes mutations per session so read-revision-then-append stays atomic against our own verbs. */
182
+ const writers = new Map();
183
+
184
+ const ingest = (sessionId, event) => {
185
+ if (event?.type !== 'team/task') return;
186
+ if (!hydrated.has(sessionId)) {
187
+ const buffered = pendingEvents.get(sessionId) ?? new Map();
188
+ if (typeof event.seq === 'number') buffered.set(event.seq, event);
189
+ pendingEvents.set(sessionId, buffered);
190
+ }
191
+ const data = isRecord(event.data) ? event.data : undefined;
192
+ const list = listForTeamId(data?.teamId);
193
+ const task = sanitizeTask(data?.task);
194
+ if (list === undefined || task === undefined) return;
195
+ let tasks = boards.get(sessionId)?.get(list);
196
+ if (tasks === undefined) {
197
+ if (!boards.has(sessionId)) boards.set(sessionId, new Map());
198
+ tasks = new Map();
199
+ boards.get(sessionId).set(list, tasks);
200
+ }
201
+ const prior = tasks.get(task.id);
202
+ if (prior === undefined || task.revision >= prior.revision) tasks.set(task.id, task);
203
+ };
204
+
205
+ /** Feed every `session/event` so live appends (ours and a mounted agent-team's) refresh the board. */
206
+ const observe = (session, event) => {
207
+ const sessionId = typeof session === 'string' ? session : session?.id;
208
+ if (typeof sessionId === 'string' && sessionId.length > 0) ingest(sessionId, event);
209
+ };
210
+
211
+ const hydrate = async (sessionId) => {
212
+ if (hydrated.has(sessionId)) return;
213
+ if (hydrating.has(sessionId)) return hydrating.get(sessionId);
214
+ const task = (async () => {
215
+ const events = await eventsFor(sessionId);
216
+ const folded = foldTasks(events);
217
+ // Events observed while the snapshot loaded merge over it (seq order is
218
+ // irrelevant: revision decides).
219
+ for (const event of (pendingEvents.get(sessionId) ?? new Map()).values()) {
220
+ const data = isRecord(event?.data) ? event.data : undefined;
221
+ const list = listForTeamId(data?.teamId);
222
+ const task = sanitizeTask(data?.task);
223
+ if (list === undefined || task === undefined) continue;
224
+ let tasks = folded.get(list);
225
+ if (tasks === undefined) {
226
+ tasks = new Map();
227
+ folded.set(list, tasks);
228
+ }
229
+ const prior = tasks.get(task.id);
230
+ if (prior === undefined || task.revision >= prior.revision) tasks.set(task.id, task);
231
+ }
232
+ boards.set(sessionId, folded);
233
+ hydrated.add(sessionId);
234
+ pendingEvents.delete(sessionId);
235
+ })();
236
+ hydrating.set(sessionId, task);
237
+ try {
238
+ await task.catch((error) => {
239
+ warn(`Picasso team-task hydration failed for ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
240
+ hydrated.add(sessionId);
241
+ boards.set(sessionId, boards.get(sessionId) ?? new Map());
242
+ });
243
+ } finally {
244
+ hydrating.delete(sessionId);
245
+ }
246
+ };
247
+
248
+ const tasksOf = (sessionId, list) => {
249
+ const board = boards.get(sessionId);
250
+ const tasks = board?.get(list);
251
+ return tasks ?? new Map();
252
+ };
253
+
254
+ const listTasks = (sessionId, list, { includeClosed = false } = {}) =>
255
+ [...tasksOf(sessionId, list).values()]
256
+ .filter((task) => task.status !== 'deleted' && (includeClosed || task.status !== 'completed'))
257
+ .sort((a, b) => a.id.localeCompare(b.id, undefined, { numeric: true }));
258
+
259
+ const findTask = (sessionId, list, taskId) => {
260
+ const task = tasksOf(sessionId, list).get(taskId);
261
+ if (task === undefined || task.status === 'deleted') {
262
+ throw new TeamTaskError('team/task-not-found', `task "${taskId}" not found in list "${list}"`, { list, taskId });
263
+ }
264
+ return task;
265
+ };
266
+
267
+ const checkRevision = (task, expectedRevision) => {
268
+ if (expectedRevision === undefined) return;
269
+ if (!Number.isSafeInteger(expectedRevision) || expectedRevision < 1) {
270
+ throw new TeamTaskError('gateway/bad-request', 'expectedRevision must be a positive integer');
271
+ }
272
+ if (expectedRevision !== task.revision) {
273
+ throw new TeamTaskError(
274
+ 'team/revision-conflict',
275
+ `task "${task.id}" is at revision ${task.revision}, not ${expectedRevision} — reload and retry`,
276
+ { taskId: task.id, revision: task.revision },
277
+ );
278
+ }
279
+ };
280
+
281
+ /**
282
+ * Serialize one mutation: hydrate, compute the next snapshot, append it (the
283
+ * append re-enters through `observe`, so the board updates synchronously).
284
+ * `fn` returns `{ task, changed }`; a `changed: false` result skips the
285
+ * append so idempotent re-claims and re-completes leave no log noise.
286
+ */
287
+ const mutate = (sessionId, list, fn) => {
288
+ const run = (writers.get(sessionId) ?? Promise.resolve()).then(async () => {
289
+ const agent = agentFor(sessionId);
290
+ if (agent === undefined) {
291
+ throw new TeamTaskError('session/not-found', `session "${sessionId}" not found (not attached)`, { sessionId });
292
+ }
293
+ const session = agent.session;
294
+ if (session === undefined || typeof session.append !== 'function') {
295
+ throw new TeamTaskError('session/not-found', `session "${sessionId}" cannot record tasks (no appendable log)`, { sessionId });
296
+ }
297
+ await hydrate(sessionId);
298
+ const { task, changed } = fn();
299
+ if (changed) {
300
+ session.append('team/task', {
301
+ version: TEAM_TASK_EVENT_VERSION,
302
+ teamId: teamIdForList(list),
303
+ task,
304
+ });
305
+ }
306
+ return task;
307
+ });
308
+ writers.set(sessionId, run.then(() => undefined, () => undefined));
309
+ return run;
310
+ };
311
+
312
+ const requireSession = (params) => {
313
+ if (typeof params?.sessionId !== 'string' || params.sessionId.length === 0) {
314
+ throw new TeamTaskError('gateway/bad-request', 'a non-empty sessionId is required');
315
+ }
316
+ return params.sessionId;
317
+ };
318
+
319
+ const methods = {
320
+ async 'team/task/lists'(params) {
321
+ const sessionId = requireSession(params);
322
+ await hydrate(sessionId);
323
+ const lists = [...(boards.get(sessionId) ?? new Map()).entries()].map(([name, tasks]) => {
324
+ const live = [...tasks.values()].filter((task) => task.status !== 'deleted');
325
+ return {
326
+ name,
327
+ total: live.length,
328
+ pending: live.filter((task) => task.status === 'pending').length,
329
+ inProgress: live.filter((task) => task.status === 'in_progress').length,
330
+ completed: live.filter((task) => task.status === 'completed').length,
331
+ };
332
+ });
333
+ lists.sort((a, b) => a.name.localeCompare(b.name));
334
+ return { lists };
335
+ },
336
+ async 'team/task/list'(params) {
337
+ const sessionId = requireSession(params);
338
+ const list = cleanString(params?.list, 'list', MAX_LIST_NAME);
339
+ await hydrate(sessionId);
340
+ return { list, tasks: listTasks(sessionId, list, { includeClosed: params?.includeClosed === true }) };
341
+ },
342
+ async 'team/task/create'(params) {
343
+ const sessionId = requireSession(params);
344
+ const list = cleanString(params?.list, 'list', MAX_LIST_NAME);
345
+ const subject = cleanString(params?.subject, 'subject', MAX_SUBJECT);
346
+ const description = optionalString(params?.description, 'description', MAX_DESCRIPTION) ?? '';
347
+ const blockedBy = stringArray(params?.blockedBy, 'blockedBy');
348
+ const writeScopes = stringArray(params?.writeScopes, 'writeScopes');
349
+ const task = await mutate(sessionId, list, () => {
350
+ const now = new Date().toISOString();
351
+ return {
352
+ changed: true,
353
+ task: {
354
+ id: nextTaskId(tasksOf(sessionId, list)),
355
+ revision: 1,
356
+ subject,
357
+ title: subject,
358
+ description,
359
+ status: 'pending',
360
+ blockedBy,
361
+ writeScopes,
362
+ list,
363
+ createdBy: sessionId,
364
+ createdAt: now,
365
+ updatedAt: now,
366
+ },
367
+ };
368
+ });
369
+ return { list, task };
370
+ },
371
+ async 'team/task/claim'(params) {
372
+ const sessionId = requireSession(params);
373
+ const list = cleanString(params?.list, 'list', MAX_LIST_NAME);
374
+ const taskId = cleanString(params?.taskId, 'taskId', MAX_SUBJECT);
375
+ const owner = optionalString(params?.owner, 'owner', MAX_SUBJECT) ?? sessionId;
376
+ const ownerSessionId = optionalString(params?.ownerSessionId, 'ownerSessionId', MAX_SUBJECT);
377
+ const task = await mutate(sessionId, list, () => {
378
+ const current = findTask(sessionId, list, taskId);
379
+ checkRevision(current, params?.expectedRevision);
380
+ if (current.status === 'completed') {
381
+ throw new TeamTaskError('team/task-closed', `task "${taskId}" is completed`, { taskId });
382
+ }
383
+ const holder = ownerSessionId ?? owner;
384
+ if (current.status === 'in_progress') {
385
+ if (current.ownerName === owner || current.ownerId === holder) {
386
+ return { changed: false, task: current };
387
+ }
388
+ if (params?.force !== true) {
389
+ throw new TeamTaskError('team/task-claimed', `task "${taskId}" is claimed by ${current.ownerName ?? current.ownerId ?? 'another owner'}`, { taskId, owner: current.ownerName ?? current.ownerId });
390
+ }
391
+ }
392
+ return {
393
+ changed: true,
394
+ task: {
395
+ ...current,
396
+ revision: current.revision + 1,
397
+ status: 'in_progress',
398
+ ownerName: owner,
399
+ assignee: owner,
400
+ updatedAt: new Date().toISOString(),
401
+ ownerId: holder,
402
+ },
403
+ };
404
+ });
405
+ return { list, task };
406
+ },
407
+ async 'team/task/complete'(params) {
408
+ const sessionId = requireSession(params);
409
+ const list = cleanString(params?.list, 'list', MAX_LIST_NAME);
410
+ const taskId = cleanString(params?.taskId, 'taskId', MAX_SUBJECT);
411
+ const owner = optionalString(params?.owner, 'owner', MAX_SUBJECT);
412
+ const task = await mutate(sessionId, list, () => {
413
+ const current = findTask(sessionId, list, taskId);
414
+ checkRevision(current, params?.expectedRevision);
415
+ if (current.status === 'completed') return { changed: false, task: current };
416
+ return {
417
+ changed: true,
418
+ task: {
419
+ ...current,
420
+ revision: current.revision + 1,
421
+ status: 'completed',
422
+ updatedAt: new Date().toISOString(),
423
+ ...(owner === undefined ? {} : { completedBy: owner }),
424
+ },
425
+ };
426
+ });
427
+ return { list, task };
428
+ },
429
+ async 'team/task/delete'(params) {
430
+ const sessionId = requireSession(params);
431
+ const list = cleanString(params?.list, 'list', MAX_LIST_NAME);
432
+ const taskId = cleanString(params?.taskId, 'taskId', MAX_SUBJECT);
433
+ const task = await mutate(sessionId, list, () => {
434
+ const current = findTask(sessionId, list, taskId);
435
+ checkRevision(current, params?.expectedRevision);
436
+ return {
437
+ changed: true,
438
+ task: {
439
+ ...current,
440
+ revision: current.revision + 1,
441
+ status: 'deleted',
442
+ updatedAt: new Date().toISOString(),
443
+ },
444
+ };
445
+ });
446
+ return { list, task };
447
+ },
448
+ };
449
+
450
+ return { methods, observe };
451
+ }