deictic 0.3.0 → 0.4.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 (175) hide show
  1. package/API.md +31 -19
  2. package/README.md +6 -26
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.js +1 -1
  5. package/dist/annotations/index.d.ts +2 -101
  6. package/dist/annotations/index.js +1 -22
  7. package/dist/astro.d.ts +1 -1
  8. package/dist/astro.js +1 -1
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +37 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/index.js +1 -10
  13. package/dist/logs/client.d.ts +1 -1
  14. package/dist/logs/client.js +1 -1
  15. package/dist/logs/index.d.ts +2 -18
  16. package/dist/logs/index.js +1 -21
  17. package/dist/network/client.d.ts +1 -1
  18. package/dist/network/client.js +1 -1
  19. package/dist/network/index.d.ts +1 -1
  20. package/dist/network/index.js +1 -37
  21. package/dist/recommended/index.d.ts +7 -7
  22. package/dist/recommended/index.js +1 -26
  23. package/dist/recordings/client.d.ts +1 -1
  24. package/dist/recordings/client.js +1 -1
  25. package/dist/recordings/index.d.ts +1 -1
  26. package/dist/screenshots/client.d.ts +1 -1
  27. package/dist/screenshots/client.js +1 -108
  28. package/dist/screenshots/dom.d.ts +1 -1
  29. package/dist/screenshots/dom.js +1 -1
  30. package/dist/screenshots/index.d.ts +1 -1
  31. package/dist/screenshots/index.js +1 -98
  32. package/dist/screenshots/rrweb.d.ts +2 -1
  33. package/dist/screenshots/rrweb.d.ts.map +1 -1
  34. package/dist/screenshots/rrweb.js +6 -2
  35. package/dist/screenshots/rrweb.js.map +1 -1
  36. package/dist/shared/annotations.js +22 -0
  37. package/dist/shared/annotations.js.map +1 -0
  38. package/dist/shared/board.js +190 -0
  39. package/dist/shared/board.js.map +1 -0
  40. package/dist/shared/client.js +108 -0
  41. package/dist/{screenshots → shared}/client.js.map +1 -1
  42. package/dist/shared/endpoints.js +4 -1
  43. package/dist/shared/endpoints.js.map +1 -1
  44. package/dist/shared/find.js +156 -0
  45. package/dist/shared/find.js.map +1 -0
  46. package/dist/shared/frame.js +75 -0
  47. package/dist/shared/frame.js.map +1 -0
  48. package/dist/shared/index.d.ts +5 -0
  49. package/dist/shared/index.d.ts.map +1 -1
  50. package/dist/shared/index2.d.ts +85 -84
  51. package/dist/shared/index2.d.ts.map +1 -1
  52. package/dist/shared/index3.d.ts +83 -89
  53. package/dist/shared/index3.d.ts.map +1 -1
  54. package/dist/shared/index4.d.ts +98 -50
  55. package/dist/shared/index4.d.ts.map +1 -1
  56. package/dist/shared/index5.d.ts +13 -215
  57. package/dist/shared/index5.d.ts.map +1 -1
  58. package/dist/shared/index6.d.ts +55 -61
  59. package/dist/shared/index6.d.ts.map +1 -1
  60. package/dist/shared/index7.d.ts +224 -0
  61. package/dist/shared/index7.d.ts.map +1 -0
  62. package/dist/shared/index8.d.ts +52 -0
  63. package/dist/shared/index8.d.ts.map +1 -0
  64. package/dist/shared/index9.d.ts +70 -0
  65. package/dist/shared/index9.d.ts.map +1 -0
  66. package/dist/shared/init.js +472 -0
  67. package/dist/shared/init.js.map +1 -0
  68. package/dist/shared/local.js +165 -0
  69. package/dist/shared/local.js.map +1 -0
  70. package/dist/shared/logs.js +22 -0
  71. package/dist/shared/logs.js.map +1 -0
  72. package/dist/shared/network.js +39 -0
  73. package/dist/shared/network.js.map +1 -0
  74. package/dist/shared/packages.js +125 -0
  75. package/dist/shared/packages.js.map +1 -0
  76. package/dist/shared/playwright.js +36 -9
  77. package/dist/shared/playwright.js.map +1 -1
  78. package/dist/shared/recommended.js +26 -0
  79. package/dist/shared/recommended.js.map +1 -0
  80. package/dist/shared/recording.js +316 -0
  81. package/dist/shared/recording.js.map +1 -0
  82. package/dist/shared/recordings.js +2 -1
  83. package/dist/shared/recordings.js.map +1 -1
  84. package/dist/shared/screenshots.js +108 -0
  85. package/dist/shared/screenshots.js.map +1 -0
  86. package/dist/shared/src.js +10 -0
  87. package/dist/shared/src.js.map +1 -0
  88. package/dist/shared/task.js +108 -0
  89. package/dist/shared/task.js.map +1 -0
  90. package/dist/shared/tasks.js +33 -191
  91. package/dist/shared/tasks.js.map +1 -1
  92. package/dist/shared/transcribe.js +128 -0
  93. package/dist/shared/transcribe.js.map +1 -0
  94. package/dist/shared/vb.js +13 -0
  95. package/dist/shared/vb.js.map +1 -0
  96. package/dist/shared/vite.d.ts +16 -0
  97. package/dist/shared/vite.d.ts.map +1 -0
  98. package/dist/shared/vite.js +61 -0
  99. package/dist/shared/vite.js.map +1 -0
  100. package/dist/shared/voice.js +84 -0
  101. package/dist/{voice/index.js.map → shared/voice.js.map} +1 -1
  102. package/dist/shared/voice2.js +90 -0
  103. package/dist/shared/voice2.js.map +1 -0
  104. package/dist/shared/watch.js +209 -0
  105. package/dist/shared/watch.js.map +1 -0
  106. package/dist/shared/watchers.js +62 -0
  107. package/dist/shared/watchers.js.map +1 -0
  108. package/dist/tailwind/client.d.ts +1 -1
  109. package/dist/tailwind/client.js +1 -1
  110. package/dist/tailwind/index.d.ts +1 -1
  111. package/dist/tailwind/index.js +1 -1
  112. package/dist/tasks/client.d.ts +1 -1
  113. package/dist/tasks/client.d.ts.map +1 -1
  114. package/dist/tasks/client.js +45 -8
  115. package/dist/tasks/client.js.map +1 -1
  116. package/dist/tasks/index.d.ts +1 -1
  117. package/dist/tasks/index.js +3 -1
  118. package/dist/vite.d.ts +2 -15
  119. package/dist/vite.js +2 -60
  120. package/dist/voice/client.d.ts +1 -1
  121. package/dist/voice/client.js +1 -1
  122. package/dist/voice/index.d.ts +2 -52
  123. package/dist/voice/index.js +1 -84
  124. package/package.json +6 -9
  125. package/skills/deictic/SKILL.md +27 -42
  126. package/skills/deictic/references/recordings.md +9 -108
  127. package/skills/deictic/references/tasks.md +21 -107
  128. package/skills/deictic/references/watch.md +13 -66
  129. package/src/cli/board.ts +204 -0
  130. package/src/cli/bun.ts +133 -0
  131. package/src/cli/edit.ts +56 -0
  132. package/src/cli/find.ts +147 -0
  133. package/src/cli/frame.ts +90 -0
  134. package/src/cli/init.ts +388 -0
  135. package/src/cli/recording.ts +383 -0
  136. package/src/cli/task.ts +126 -0
  137. package/src/cli/transcribe.ts +129 -0
  138. package/src/cli/vb.ts +11 -0
  139. package/src/cli/voice.ts +59 -0
  140. package/src/cli/watch.ts +221 -0
  141. package/src/cli.ts +37 -0
  142. package/src/index.ts +5 -0
  143. package/src/plugins/logs/index.ts +1 -0
  144. package/src/plugins/network/index.ts +1 -0
  145. package/src/plugins/recordings/index.ts +1 -0
  146. package/src/plugins/screenshots/client.ts +3 -2
  147. package/src/plugins/screenshots/index.ts +10 -3
  148. package/src/plugins/screenshots/playwright.ts +34 -7
  149. package/src/plugins/screenshots/rrweb.ts +5 -1
  150. package/src/plugins/tasks/client.ts +62 -7
  151. package/src/plugins/tasks/index.ts +41 -20
  152. package/src/plugins/tasks/local.ts +19 -6
  153. package/src/plugins/tasks/watchers.ts +41 -6
  154. package/src/tools/endpoints.ts +3 -0
  155. package/src/tools/packages.ts +107 -0
  156. package/dist/annotations/index.d.ts.map +0 -1
  157. package/dist/annotations/index.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/logs/index.d.ts.map +0 -1
  160. package/dist/logs/index.js.map +0 -1
  161. package/dist/network/index.js.map +0 -1
  162. package/dist/recommended/index.js.map +0 -1
  163. package/dist/screenshots/index.js.map +0 -1
  164. package/dist/vite.d.ts.map +0 -1
  165. package/dist/vite.js.map +0 -1
  166. package/dist/voice/index.d.ts.map +0 -1
  167. package/skills/deictic/references/install.md +0 -103
  168. package/skills/deictic/scripts/frame.mjs +0 -62
  169. package/skills/deictic/scripts/lib.mjs +0 -277
  170. package/skills/deictic/scripts/recording.mjs +0 -266
  171. package/skills/deictic/scripts/task.mjs +0 -113
  172. package/skills/deictic/scripts/transcribe.mjs +0 -93
  173. package/skills/deictic/scripts/vb.mjs +0 -12
  174. package/skills/deictic/scripts/voice.mjs +0 -50
  175. package/skills/deictic/scripts/watch.mjs +0 -115
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/plugins/voice/index.ts"],"sourcesContent":["/**\n * `deictic/voice`: records the mic, for other plugins to attach (tasks does) or play along with\n * something (a recording does). No tab of its own. The page half asks for the mic the first time, records\n * with `MediaRecorder` and sends each take as it's spoken, its start to the `add` route and the rest to\n * `more/<id>`, so one a page load cuts short is kept up to there; the server half keeps the latest `keep`\n * clips under `.deictic/voice` and serves them at `clip/<id>`.\n */\nimport { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { definePlugin } from '#src/index.ts';\nimport { keptIn } from '#src/tools/kept.ts';\n\n/** A clip as the page knows it: its ID, where it plays from, how long it runs in milliseconds, and its type. */\nexport interface Clip {\n id: string;\n url: string;\n duration: number;\n type: string;\n}\n\n/** A take going on: `stop` ends it and answers its clip, `cancel` ends it with none (what was sent of it goes as the oldest clips do). */\nexport interface Take {\n /** When it started, as `Date.now()`. */\n started: number;\n /** The mic, while it's recorded: to show it's heard (`liveWaveform` from `deictic/client`). */\n stream: MediaStream;\n /**\n * What's kept of it by now, as the clip it would be if it ended here, or nothing before its first second is:\n * for a page that's going, with no time left to `stop` it.\n */\n soFar(): Pick<Clip, 'id' | 'duration'> | undefined;\n stop(): Promise<Clip>;\n cancel(): void;\n}\n\n/** The page's half, for other plugins' page halves. */\nexport interface Voice {\n /** Starts recording the mic, asking for it the first time: rejects when it's refused or there's none. */\n start(): Promise<Take>;\n}\n\n/** The server's half, for other plugins' server halves. */\nexport interface Clips {\n /** A clip's audio, or nothing for one not kept (any more). */\n read(id: string): { data: Uint8Array<ArrayBuffer>; name: string; type: string } | undefined;\n}\n\ndeclare module 'deictic' {\n interface ServerApis {\n voice: Clips;\n }\n interface ClientApis {\n voice: Voice;\n }\n}\n\nexport interface VoiceOptions {\n /** How many clips to keep, the latest: 50 by default. */\n keep?: number;\n /** Where they're kept, from the project's root: `.deictic/voice` by default. */\n dir?: string;\n}\n\nconst ID = /^[a-z0-9]+-[a-z0-9]+$/;\n/** What one clip may weigh: minutes of speech in Opus are well under a MB. */\nconst MAX = 25 * 1024 * 1024;\n/** The audio a browser's `MediaRecorder` makes, by the extension it's kept under. */\nconst TYPES: Record<string, string> = { webm: 'audio/webm', ogg: 'audio/ogg', mp4: 'audio/mp4' };\n\nexport function voice(options: VoiceOptions = {}) {\n const keep = options.keep ?? 50;\n let dir = '';\n let taken = 0;\n const fileOf = (id: string) => (ID.test(id) && existsSync(dir) ? readdirSync(dir).find((f) => f.startsWith(`${id}.`)) : undefined);\n const read: Clips['read'] = (id) => {\n const file = fileOf(id);\n if (file === undefined) return undefined;\n const ext = file.slice(id.length + 1);\n return { data: new Uint8Array(readFileSync(join(dir, file))), name: `voice-${file}`, type: TYPES[ext] ?? 'application/octet-stream' };\n };\n const keepClip = (data: Uint8Array, ext: string) => {\n // Sorts by when it was made, which is what pruning keeps by: the count orders two in one millisecond.\n const id = `${Date.now().toString(36).padStart(9, '0')}${(taken++ % 1296).toString(36).padStart(2, '0')}-${crypto.randomUUID().slice(0, 8)}`;\n mkdirSync(dir, { recursive: true });\n writeFileSync(join(dir, `${id}.${ext}`), data);\n const kept = readdirSync(dir).toSorted();\n for (const old of kept.slice(0, Math.max(0, kept.length - keep))) rmSync(join(dir, old));\n return id;\n };\n\n return definePlugin<never, never, never, Clips>({\n name: 'voice',\n client: 'deictic/voice/client',\n setup: ({ root }) => {\n dir = options.dir === undefined ? keptIn(root, 'voice') : resolve(root, options.dir);\n return { read };\n },\n routes: {\n // A take the page is recording, as the audio type its `MediaRecorder` makes: its start, the rest to `more`.\n add: async (req) => {\n const type = (req.headers.get('content-type') ?? '').split(';')[0]!.trim();\n const ext = Object.keys(TYPES).find((e) => TYPES[e] === type);\n if (ext === undefined) return Response.json({ problem: `send the clip as ${Object.values(TYPES).join(', ')}` }, { status: 415 });\n const body = new Uint8Array(await req.arrayBuffer());\n if (body.byteLength === 0) return Response.json({ problem: 'the clip is empty: speak for a moment longer' }, { status: 400 });\n if (body.byteLength > MAX) return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });\n return Response.json({ id: keepClip(body, ext) });\n },\n // `more/<id>`: the take goes on, and this is the next of its audio. With `?last`, and maybe nothing, it's over.\n more: async (req) => {\n const id = new URL(req.url).pathname.split('/').at(-1) ?? '';\n const file = fileOf(id);\n if (file === undefined) return Response.json({ problem: `clip ${id} isn't kept any more: record it again` }, { status: 404 });\n const body = new Uint8Array(await req.arrayBuffer());\n if (statSync(join(dir, file)).size + body.byteLength > MAX)\n return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });\n appendFileSync(join(dir, file), body);\n return Response.json({ id });\n },\n // `clip/<id>`: the audio, to play back.\n clip: (req) => {\n const found = read(new URL(req.url).pathname.split('/').at(-1) ?? '');\n if (found === undefined) return new Response('no such clip, or not kept any more', { status: 404 });\n return new Response(found.data, { headers: { 'content-type': found.type, 'cache-control': 'no-store' } });\n },\n },\n });\n}\n\nexport default voice;\n"],"mappings":";;;;;;;;;;;;AAgEA,MAAM,KAAK;;AAEX,MAAM,MAAM;;AAEZ,MAAM,QAAgC;CAAE,MAAM;CAAc,KAAK;CAAa,KAAK;AAAY;AAE/F,SAAgB,MAAM,UAAwB,CAAC,GAAG;CAChD,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,MAAM;CACV,IAAI,QAAQ;CACZ,MAAM,UAAU,OAAgB,GAAG,KAAK,EAAE,KAAK,WAAW,GAAG,IAAI,YAAY,GAAG,CAAC,CAAC,MAAM,MAAM,EAAE,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,KAAA;CACxH,MAAM,QAAuB,OAAO;EAClC,MAAM,OAAO,OAAO,EAAE;EACtB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,MAAM,MAAM,KAAK,MAAM,GAAG,SAAS,C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;IAAW,EAAE,CAAC;GAC1G;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"voice.js","names":[],"sources":["../../src/plugins/voice/index.ts"],"sourcesContent":["/**\n * `deictic/voice`: records the mic, for other plugins to attach (tasks does) or play along with\n * something (a recording does). No tab of its own. The page half asks for the mic the first time, records\n * with `MediaRecorder` and sends each take as it's spoken, its start to the `add` route and the rest to\n * `more/<id>`, so one a page load cuts short is kept up to there; the server half keeps the latest `keep`\n * clips under `.deictic/voice` and serves them at `clip/<id>`.\n */\nimport { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { definePlugin } from '#src/index.ts';\nimport { keptIn } from '#src/tools/kept.ts';\n\n/** A clip as the page knows it: its ID, where it plays from, how long it runs in milliseconds, and its type. */\nexport interface Clip {\n id: string;\n url: string;\n duration: number;\n type: string;\n}\n\n/** A take going on: `stop` ends it and answers its clip, `cancel` ends it with none (what was sent of it goes as the oldest clips do). */\nexport interface Take {\n /** When it started, as `Date.now()`. */\n started: number;\n /** The mic, while it's recorded: to show it's heard (`liveWaveform` from `deictic/client`). */\n stream: MediaStream;\n /**\n * What's kept of it by now, as the clip it would be if it ended here, or nothing before its first second is:\n * for a page that's going, with no time left to `stop` it.\n */\n soFar(): Pick<Clip, 'id' | 'duration'> | undefined;\n stop(): Promise<Clip>;\n cancel(): void;\n}\n\n/** The page's half, for other plugins' page halves. */\nexport interface Voice {\n /** Starts recording the mic, asking for it the first time: rejects when it's refused or there's none. */\n start(): Promise<Take>;\n}\n\n/** The server's half, for other plugins' server halves. */\nexport interface Clips {\n /** A clip's audio, or nothing for one not kept (any more). */\n read(id: string): { data: Uint8Array<ArrayBuffer>; name: string; type: string } | undefined;\n}\n\ndeclare module 'deictic' {\n interface ServerApis {\n voice: Clips;\n }\n interface ClientApis {\n voice: Voice;\n }\n}\n\nexport interface VoiceOptions {\n /** How many clips to keep, the latest: 50 by default. */\n keep?: number;\n /** Where they're kept, from the project's root: `.deictic/voice` by default. */\n dir?: string;\n}\n\nconst ID = /^[a-z0-9]+-[a-z0-9]+$/;\n/** What one clip may weigh: minutes of speech in Opus are well under a MB. */\nconst MAX = 25 * 1024 * 1024;\n/** The audio a browser's `MediaRecorder` makes, by the extension it's kept under. */\nconst TYPES: Record<string, string> = { webm: 'audio/webm', ogg: 'audio/ogg', mp4: 'audio/mp4' };\n\nexport function voice(options: VoiceOptions = {}) {\n const keep = options.keep ?? 50;\n let dir = '';\n let taken = 0;\n const fileOf = (id: string) => (ID.test(id) && existsSync(dir) ? readdirSync(dir).find((f) => f.startsWith(`${id}.`)) : undefined);\n const read: Clips['read'] = (id) => {\n const file = fileOf(id);\n if (file === undefined) return undefined;\n const ext = file.slice(id.length + 1);\n return { data: new Uint8Array(readFileSync(join(dir, file))), name: `voice-${file}`, type: TYPES[ext] ?? 'application/octet-stream' };\n };\n const keepClip = (data: Uint8Array, ext: string) => {\n // Sorts by when it was made, which is what pruning keeps by: the count orders two in one millisecond.\n const id = `${Date.now().toString(36).padStart(9, '0')}${(taken++ % 1296).toString(36).padStart(2, '0')}-${crypto.randomUUID().slice(0, 8)}`;\n mkdirSync(dir, { recursive: true });\n writeFileSync(join(dir, `${id}.${ext}`), data);\n const kept = readdirSync(dir).toSorted();\n for (const old of kept.slice(0, Math.max(0, kept.length - keep))) rmSync(join(dir, old));\n return id;\n };\n\n return definePlugin<never, never, never, Clips>({\n name: 'voice',\n client: 'deictic/voice/client',\n setup: ({ root }) => {\n dir = options.dir === undefined ? keptIn(root, 'voice') : resolve(root, options.dir);\n return { read };\n },\n routes: {\n // A take the page is recording, as the audio type its `MediaRecorder` makes: its start, the rest to `more`.\n add: async (req) => {\n const type = (req.headers.get('content-type') ?? '').split(';')[0]!.trim();\n const ext = Object.keys(TYPES).find((e) => TYPES[e] === type);\n if (ext === undefined) return Response.json({ problem: `send the clip as ${Object.values(TYPES).join(', ')}` }, { status: 415 });\n const body = new Uint8Array(await req.arrayBuffer());\n if (body.byteLength === 0) return Response.json({ problem: 'the clip is empty: speak for a moment longer' }, { status: 400 });\n if (body.byteLength > MAX) return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });\n return Response.json({ id: keepClip(body, ext) });\n },\n // `more/<id>`: the take goes on, and this is the next of its audio. With `?last`, and maybe nothing, it's over.\n more: async (req) => {\n const id = new URL(req.url).pathname.split('/').at(-1) ?? '';\n const file = fileOf(id);\n if (file === undefined) return Response.json({ problem: `clip ${id} isn't kept any more: record it again` }, { status: 404 });\n const body = new Uint8Array(await req.arrayBuffer());\n if (statSync(join(dir, file)).size + body.byteLength > MAX)\n return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });\n appendFileSync(join(dir, file), body);\n return Response.json({ id });\n },\n // `clip/<id>`: the audio, to play back.\n clip: (req) => {\n const found = read(new URL(req.url).pathname.split('/').at(-1) ?? '');\n if (found === undefined) return new Response('no such clip, or not kept any more', { status: 404 });\n return new Response(found.data, { headers: { 'content-type': found.type, 'cache-control': 'no-store' } });\n },\n },\n });\n}\n\nexport default voice;\n"],"mappings":";;;;;;;;;;;;AAgEA,MAAM,KAAK;;AAEX,MAAM,MAAM;;AAEZ,MAAM,QAAgC;CAAE,MAAM;CAAc,KAAK;CAAa,KAAK;AAAY;AAE/F,SAAgB,MAAM,UAAwB,CAAC,GAAG;CAChD,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,MAAM;CACV,IAAI,QAAQ;CACZ,MAAM,UAAU,OAAgB,GAAG,KAAK,EAAE,KAAK,WAAW,GAAG,IAAI,YAAY,GAAG,CAAC,CAAC,MAAM,MAAM,EAAE,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,KAAA;CACxH,MAAM,QAAuB,OAAO;EAClC,MAAM,OAAO,OAAO,EAAE;EACtB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,MAAM,MAAM,KAAK,MAAM,G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AAM,iBAAiB;IAAW,EAAE,CAAC;GAC1G;EACF;CACF,CAAC;AACH"}
@@ -0,0 +1,90 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { a as clock, u as parseArgs } from "./board.js";
4
+ import { i as voiceClips, t as ffmpeg } from "./find.js";
5
+ // src/cli/voice.ts
6
+ /**
7
+ * `deictic voice`: when something was said: the stretches of speech in voice clips, found by ffmpeg's silence
8
+ * detection. For a recording, in the recording's time, to line up with its timeline; for a task, each voice note on
9
+ * it too. `--wav` writes each clip as 16 kHz mono WAV, what speech-to-text tools take.
10
+ */
11
+ const usage = "voice <task | replay URL | recording ID | file | clip ID> [--noise -35] [--gap 0.4] [--wav dir] [--json] when speech happens";
12
+ async function run(args) {
13
+ const { values, positionals } = parseArgs(args, {
14
+ noise: {
15
+ type: "string",
16
+ default: "-35"
17
+ },
18
+ gap: {
19
+ type: "string",
20
+ default: "0.4"
21
+ },
22
+ wav: { type: "string" },
23
+ json: { type: "boolean" }
24
+ });
25
+ const noise = Number(values.noise);
26
+ const gap = Number(values.gap);
27
+ const wav = values.wav === void 0 ? void 0 : resolve(values.wav);
28
+ const results = [];
29
+ for (const c of await voiceClips(positionals[0])) {
30
+ const log = ffmpeg([
31
+ "-i",
32
+ c.file,
33
+ "-af",
34
+ `silencedetect=noise=${noise}dB:d=${gap}`,
35
+ "-f",
36
+ "null",
37
+ "-"
38
+ ]).log;
39
+ const starts = [...log.matchAll(/silence_start: (-?[\d.]+)/g)].map((m) => Number(m[1]) * 1e3);
40
+ const ends = [...log.matchAll(/silence_end: (-?[\d.]+)/g)].map((m) => Number(m[1]) * 1e3);
41
+ const times = [...log.matchAll(/time=(\d+):(\d+):([\d.]+)/g)].at(-1);
42
+ const length = times ? (Number(times[1]) * 3600 + Number(times[2]) * 60 + Number(times[3])) * 1e3 : Math.max(0, ...ends);
43
+ const speech = [];
44
+ let from = 0;
45
+ for (const [i, start] of starts.entries()) {
46
+ if (start - from > 150) speech.push([from, start]);
47
+ from = ends[i] ?? length;
48
+ }
49
+ if (length - from > 150) speech.push([from, length]);
50
+ if (wav !== void 0) {
51
+ mkdirSync(wav, { recursive: true });
52
+ ffmpeg([
53
+ "-y",
54
+ "-loglevel",
55
+ "error",
56
+ "-i",
57
+ c.file,
58
+ "-ar",
59
+ "16000",
60
+ "-ac",
61
+ "1",
62
+ "-sample_fmt",
63
+ "s16",
64
+ join(wav, `${c.id}.wav`)
65
+ ]);
66
+ }
67
+ results.push({
68
+ ...c,
69
+ length,
70
+ speech: speech.map(([a, b]) => ({
71
+ from: c.at + a,
72
+ to: c.at + b
73
+ }))
74
+ });
75
+ }
76
+ if (values.json) {
77
+ console.log(JSON.stringify(results, null, 2));
78
+ return;
79
+ }
80
+ for (const r of results) {
81
+ const where = r.recording === void 0 ? "a voice note" : `in recording ${r.recording}, from ${clock(r.at)}`;
82
+ console.log(`clip ${r.id} (${where}), ${clock(r.length)} long: ${r.file}`);
83
+ if (r.speech.length === 0) console.log(" no speech found: try a lower --noise, like -45");
84
+ for (const s of r.speech) console.log(` ${clock(s.from).padStart(6)} – ${clock(s.to).padStart(6)} speech`);
85
+ if (wav !== void 0) console.log(` wav: ${join(wav, `${r.id}.wav`)}`);
86
+ }
87
+ }
88
+ export { run, usage };
89
+
90
+ //# sourceMappingURL=voice2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice2.js","names":[],"sources":["../../src/cli/voice.ts"],"sourcesContent":["/**\n * `deictic voice`: when something was said: the stretches of speech in voice clips, found by ffmpeg's silence\n * detection. For a recording, in the recording's time, to line up with its timeline; for a task, each voice note on\n * it too. `--wav` writes each clip as 16 kHz mono WAV, what speech-to-text tools take.\n */\nimport { mkdirSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { clock, parseArgs } from './board.ts';\nimport { ffmpeg, voiceClips } from './find.ts';\n\nexport const usage =\n 'voice <task | replay URL | recording ID | file | clip ID> [--noise -35] [--gap 0.4] [--wav dir] [--json] when speech happens';\n\nexport async function run(args: string[]): Promise<void> {\n const { values, positionals } = parseArgs(args, {\n noise: { type: 'string', default: '-35' },\n gap: { type: 'string', default: '0.4' },\n wav: { type: 'string' },\n json: { type: 'boolean' },\n });\n const noise = Number(values.noise);\n const gap = Number(values.gap);\n const wav = values.wav === undefined ? undefined : resolve(values.wav);\n\n const results = [];\n for (const c of await voiceClips(positionals[0])) {\n // ffmpeg reports silence; speech is what's between. MediaRecorder's webm has no duration, so it's measured.\n const log = ffmpeg(['-i', c.file, '-af', `silencedetect=noise=${noise}dB:d=${gap}`, '-f', 'null', '-']).log;\n const starts = [...log.matchAll(/silence_start: (-?[\\d.]+)/g)].map((m) => Number(m[1]) * 1000);\n const ends = [...log.matchAll(/silence_end: (-?[\\d.]+)/g)].map((m) => Number(m[1]) * 1000);\n const times = [...log.matchAll(/time=(\\d+):(\\d+):([\\d.]+)/g)].at(-1);\n const length = times ? (Number(times[1]) * 3600 + Number(times[2]) * 60 + Number(times[3])) * 1000 : Math.max(0, ...ends);\n const speech: [number, number][] = [];\n let from = 0;\n for (const [i, start] of starts.entries()) {\n if (start - from > 150) speech.push([from, start]);\n from = ends[i] ?? length;\n }\n if (length - from > 150) speech.push([from, length]);\n if (wav !== undefined) {\n mkdirSync(wav, { recursive: true });\n ffmpeg(['-y', '-loglevel', 'error', '-i', c.file, '-ar', '16000', '-ac', '1', '-sample_fmt', 's16', join(wav, `${c.id}.wav`)]);\n }\n results.push({ ...c, length, speech: speech.map(([a, b]) => ({ from: c.at + a, to: c.at + b })) });\n }\n\n if (values.json) {\n console.log(JSON.stringify(results, null, 2));\n return;\n }\n for (const r of results) {\n const where = r.recording === undefined ? 'a voice note' : `in recording ${r.recording}, from ${clock(r.at)}`;\n console.log(`clip ${r.id} (${where}), ${clock(r.length)} long: ${r.file}`);\n if (r.speech.length === 0) console.log(' no speech found: try a lower --noise, like -45');\n for (const s of r.speech) console.log(` ${clock(s.from).padStart(6)} – ${clock(s.to).padStart(6)} speech`);\n if (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"node:readline";
3
+ import { t as watcherAt } from "./watchers.js";
4
+ import { _ as whoami, c as duration, i as boardUrl, m as vbCommand, n as answers, o as deicticDirs, p as vb, r as boardIn, u as parseArgs } from "./board.js";
5
+ // src/cli/watch.ts
6
+ /**
7
+ * `deictic watch`: the board's tasks for deictic, one line per thing to act on: the tasks ready now as it starts,
8
+ * then each new task, a reply on one, and one canceled (undone in the page, say). Made for an agent's monitor (each
9
+ * line an event). A board that goes away (the dev server restarted, and its board with it) is waited for and followed
10
+ * again from where it was left; it says so, and ends only if none comes back. It ends by itself once nothing has
11
+ * happened on the channel for `--idle` (20m): a watch nobody feeds isn't started again, so no agent watches for ever.
12
+ * With `--once` it ends at the first thing to act on, for a harness that's woken only when a command exits. It ends,
13
+ * too, when the process that started it does: nobody reads its lines then.
14
+ *
15
+ * While it runs the project's Task tab shows who watches (`watcherAt`). Replies the watcher wrote itself are left out
16
+ * where it has a name of its own (BOARD_PROFILE): with none it writes as the person. Exits 0 after `--once`'s event,
17
+ * 2 when idle, 1 when the board went away.
18
+ */
19
+ const usage = "watch [channel] [--idle 20m] [--once] [--label k=v] a line per new task, reply and cancellation";
20
+ /** How long a board that went away is waited for: a dev server's restart takes a few seconds. */
21
+ const BACK = 6e4;
22
+ /** A tail that ends sooner than this after it's started again isn't started a third time: the board isn't the trouble. */
23
+ const SOON = 1e4;
24
+ /** Each process's parent, by ID, asked of the system once: empty where it can't say. */
25
+ function parents() {
26
+ const run = process.platform === "win32" ? spawnSync("powershell", [
27
+ "-NoProfile",
28
+ "-Command",
29
+ "Get-CimInstance Win32_Process | % { \"$($_.ProcessId) $($_.ParentProcessId)\" }"
30
+ ], { encoding: "utf8" }) : spawnSync("ps", [
31
+ "-A",
32
+ "-o",
33
+ "pid=",
34
+ "-o",
35
+ "ppid="
36
+ ], { encoding: "utf8" });
37
+ const map = /* @__PURE__ */ new Map();
38
+ for (const line of (run.stdout ?? "").split("\n")) {
39
+ const [pid, ppid] = line.trim().split(/\s+/).map(Number);
40
+ if (pid !== void 0 && ppid !== void 0 && Number.isInteger(pid) && Number.isInteger(ppid)) map.set(pid, ppid);
41
+ }
42
+ return map;
43
+ }
44
+ /**
45
+ * The processes above this one's parent, the nearest `count` of them. A runner (`npx`, `pnpm exec`, and on Windows the
46
+ * shell and the bin's `.cmd` shim it runs) sits between the watch and the shell that ran it, and outlives that shell.
47
+ */
48
+ function ancestors(count) {
49
+ const of = parents();
50
+ const out = [];
51
+ for (let pid = of.get(process.ppid); pid !== void 0 && pid > 1 && out.length < count && !out.includes(pid); pid = of.get(pid)) out.push(pid);
52
+ return out;
53
+ }
54
+ /** Whether a process is gone. On Windows a dead parent's ID stays a child's `ppid`, so the system is asked. */
55
+ function gone(pid) {
56
+ try {
57
+ process.kill(pid, 0);
58
+ return false;
59
+ } catch (e) {
60
+ return e.code === "ESRCH";
61
+ }
62
+ }
63
+ function run(args) {
64
+ const { values, positionals } = parseArgs(args, {
65
+ idle: {
66
+ type: "string",
67
+ default: "20m"
68
+ },
69
+ once: { type: "boolean" },
70
+ label: {
71
+ type: "string",
72
+ multiple: true
73
+ }
74
+ });
75
+ const channel = positionals[0] ?? "deictic";
76
+ const labels = (values.label ?? []).flatMap((l) => ["--label", l]);
77
+ const idle = duration(values.idle);
78
+ const say = (line) => console.log(line.replace(/\s+/g, " ").trim());
79
+ const first = (text) => (text.split("\n---")[0] ?? "").trim().slice(0, 160);
80
+ const ready = vb([
81
+ "tasks",
82
+ channel,
83
+ "--state",
84
+ "ready",
85
+ ...labels
86
+ ]).trim();
87
+ const me = whoami();
88
+ const url = boardUrl();
89
+ const dirs = deicticDirs();
90
+ const own = dirs.filter((dir) => boardIn(dir) === url);
91
+ const unseen = watcherAt(own.length > 0 ? own : dirs, me.profile ?? me.name ?? me.handle ?? me.actor, channel);
92
+ let tail;
93
+ const end = (code) => {
94
+ unseen();
95
+ tail?.removeAllListeners("exit");
96
+ tail?.kill();
97
+ process.exit(code);
98
+ };
99
+ for (const signal of [
100
+ "SIGINT",
101
+ "SIGTERM",
102
+ "SIGHUP"
103
+ ]) process.on(signal, () => end(0));
104
+ const parent = process.ppid;
105
+ const above = ancestors(3);
106
+ const orphaned = () => process.ppid !== parent || gone(parent) || above.some(gone);
107
+ setInterval(() => orphaned() && end(0), 5e3);
108
+ say(`watching ${channel} on ${url ?? "the team's board"} as ${me.handle ?? me.actor}`);
109
+ if (me.profile === null) say(`you write as ${me.handle ?? me.actor}, the person's own identity, as nothing here says which agent you are: set BOARD_PROFILE=<your name> (claude, codex) on every command, this watch too, and start it again`);
110
+ const waiting = (ready ? ready.split("\n") : []).filter((line) => /^#\d+/.test(line));
111
+ for (const line of waiting) say(`ready: ${line}`);
112
+ if (values.once && waiting.length > 0) end(0);
113
+ /** One thing to act on: all `--once` waits for. */
114
+ const event = (line) => {
115
+ say(line);
116
+ if (values.once) end(0);
117
+ };
118
+ let quiet;
119
+ const heard = () => {
120
+ clearTimeout(quiet);
121
+ quiet = setTimeout(() => {
122
+ say(`idle: nothing on ${channel} in ${values.idle}, so the watch is over. Don't start it again by yourself: tell the person in a line that you've stopped watching, and watch again when they ask. Only if you're working a task now, start it once more when that's done.`);
123
+ end(2);
124
+ }, idle);
125
+ };
126
+ heard();
127
+ const roots = /* @__PURE__ */ new Map();
128
+ let cursor;
129
+ const heardOf = (line) => {
130
+ let e;
131
+ try {
132
+ e = JSON.parse(line);
133
+ } catch {
134
+ return;
135
+ }
136
+ if (e.cursor !== void 0) cursor = e.cursor;
137
+ heard();
138
+ const p = e.payload ?? {};
139
+ const label = (key) => p.labels?.[key];
140
+ if (e.type === "message.posted" && p.re === null && p.thread !== void 0) {
141
+ const at = label("deictic.at");
142
+ const page = label("deictic.page");
143
+ const project = label("deictic.project");
144
+ roots.set(p.thread, `"${first(p.text ?? "")}"${at ? ` at ${at}` : ""}${page ? ` on ${page}` : ""}${project ? ` in ${project}` : ""}`);
145
+ }
146
+ if (e.type === "task.created") event(`new task #${p.id}: ${roots.get(p.thread ?? -1) ?? ""}. Read it: npx deictic task ${p.id}`);
147
+ if (e.type === "message.posted" && p.re !== null && p.re !== void 0) {
148
+ if (me.profile !== null && p.by?.actor === me.actor) return;
149
+ const by = e.message?.author?.handle ?? p.by?.actor ?? "someone";
150
+ event(`reply on #${p.re} by ${by}: ${first(p.text ?? "")}`);
151
+ }
152
+ if (e.type === "task.canceled") event(`task #${p.id} canceled: ${p.reason ?? ""}. Stop work on it, and put back what you changed for it.`);
153
+ };
154
+ const over = (code) => {
155
+ say(`watch ended (vb tail exited ${code}): start it again`);
156
+ end(1);
157
+ };
158
+ /** Follows the channel, from `cursor` on where there is one, and again when the board comes back after going away. */
159
+ const follow = (again) => {
160
+ const started = Date.now();
161
+ const from = cursor === void 0 ? [] : ["--after", cursor];
162
+ const [command, argv, options] = vbCommand([
163
+ "tail",
164
+ channel,
165
+ ...labels,
166
+ ...from,
167
+ "--json"
168
+ ]);
169
+ const child = spawn(command, argv, {
170
+ env: options.env,
171
+ shell: options.shell,
172
+ stdio: [
173
+ "ignore",
174
+ "pipe",
175
+ "inherit"
176
+ ]
177
+ });
178
+ tail = child;
179
+ createInterface({ input: child.stdout }).on("line", heardOf);
180
+ child.on("exit", (code) => {
181
+ if (again && Date.now() - started < SOON) return over(code);
182
+ say(`the board went away (vb tail exited ${code}): waiting for it to come back`);
183
+ const until = Date.now() + BACK;
184
+ const tried = () => {
185
+ if (answers()) {
186
+ say(`the board is back on ${boardUrl() ?? "the team's board"}: watching ${channel} again`);
187
+ if (cursor === void 0) {
188
+ const now = vb([
189
+ "tasks",
190
+ channel,
191
+ "--state",
192
+ "ready",
193
+ ...labels
194
+ ]).trim();
195
+ for (const l of now.split("\n").filter((l) => /^#\d+/.test(l) && !waiting.includes(l))) event(`ready: ${l}`);
196
+ }
197
+ return follow(true);
198
+ }
199
+ if (Date.now() > until) return over(code);
200
+ setTimeout(tried, 2e3);
201
+ };
202
+ setTimeout(tried, 2e3);
203
+ });
204
+ };
205
+ follow(false);
206
+ }
207
+ export { run, usage };
208
+
209
+ //# sourceMappingURL=watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.js","names":[],"sources":["../../src/cli/watch.ts"],"sourcesContent":["/**\n * `deictic watch`: the board's tasks for deictic, one line per thing to act on: the tasks ready now as it starts,\n * then each new task, a reply on one, and one canceled (undone in the page, say). Made for an agent's monitor (each\n * line an event). A board that goes away (the dev server restarted, and its board with it) is waited for and followed\n * again from where it was left; it says so, and ends only if none comes back. It ends by itself once nothing has\n * happened on the channel for `--idle` (20m): a watch nobody feeds isn't started again, so no agent watches for ever.\n * With `--once` it ends at the first thing to act on, for a harness that's woken only when a command exits. It ends,\n * too, when the process that started it does: nobody reads its lines then.\n *\n * While it runs the project's Task tab shows who watches (`watcherAt`). Replies the watcher wrote itself are left out\n * where it has a name of its own (BOARD_PROFILE): with none it writes as the person. Exits 0 after `--once`'s event,\n * 2 when idle, 1 when the board went away.\n */\nimport { type ChildProcess, spawn, spawnSync } from 'node:child_process';\nimport { createInterface } from 'node:readline';\n\nimport { watcherAt } from '#src/plugins/tasks/watchers.ts';\n\nimport { answers, boardIn, boardUrl, deicticDirs, duration, parseArgs, vb, vbCommand, whoami } from './board.ts';\n\nexport const usage = 'watch [channel] [--idle 20m] [--once] [--label k=v] a line per new task, reply and cancellation';\n\n/** What `vb tail --json` prints, one per line. */\ninterface Tailed {\n type: string;\n cursor?: string;\n payload?: {\n id?: number;\n thread?: number;\n re?: number | null;\n text?: string;\n reason?: string;\n labels?: Record<string, string>;\n by?: { actor: string };\n };\n message?: { author?: { handle?: string } };\n}\n\n/** How long a board that went away is waited for: a dev server's restart takes a few seconds. */\nconst BACK = 60_000;\n/** A tail that ends sooner than this after it's started again isn't started a third time: the board isn't the trouble. */\nconst SOON = 10_000;\n\n/** Each process's parent, by ID, asked of the system once: empty where it can't say. */\nfunction parents(): Map<number, number> {\n const run =\n process.platform === 'win32'\n ? spawnSync(\n 'powershell',\n ['-NoProfile', '-Command', 'Get-CimInstance Win32_Process | % { \"$($_.ProcessId) $($_.ParentProcessId)\" }'],\n {\n encoding: 'utf8',\n },\n )\n : spawnSync('ps', ['-A', '-o', 'pid=', '-o', 'ppid='], { encoding: 'utf8' });\n const map = new Map<number, number>();\n for (const line of (run.stdout ?? '').split('\\n')) {\n const [pid, ppid] = line.trim().split(/\\s+/).map(Number);\n if (pid !== undefined && ppid !== undefined && Number.isInteger(pid) && Number.isInteger(ppid)) map.set(pid, ppid);\n }\n return map;\n}\n\n/**\n * The processes above this one's parent, the nearest `count` of them. A runner (`npx`, `pnpm exec`, and on Windows the\n * shell and the bin's `.cmd` shim it runs) sits between the watch and the shell that ran it, and outlives that shell.\n */\nfunction ancestors(count: number): number[] {\n const of = parents();\n const out: number[] = [];\n for (let pid = of.get(process.ppid); pid !== undefined && pid > 1 && out.length < count && !out.includes(pid); pid = of.get(pid))\n out.push(pid);\n return out;\n}\n\n/** Whether a process is gone. On Windows a dead parent's ID stays a child's `ppid`, so the system is asked. */\nfunction gone(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return false;\n } catch (e) {\n return (e as { code?: string }).code === 'ESRCH';\n }\n}\n\nexport function run(args: string[]): void {\n const { values, positionals } = parseArgs(args, {\n idle: { type: 'string', default: '20m' },\n once: { type: 'boolean' },\n label: { type: 'string', multiple: true },\n });\n const channel = positionals[0] ?? 'deictic';\n const labels = (values.label ?? []).flatMap((l) => ['--label', l]);\n const idle = duration(values.idle);\n const say = (line: string) => console.log(line.replace(/\\s+/g, ' ').trim());\n const first = (text: string) => (text.split('\\n---')[0] ?? '').trim().slice(0, 160);\n\n const ready = vb(['tasks', channel, '--state', 'ready', ...labels]).trim();\n const me = whoami();\n // In the `.deictic/` whose board this is, or in each one near here where the board is the environment's.\n const url = boardUrl();\n const dirs = deicticDirs();\n const own = dirs.filter((dir) => boardIn(dir) === url);\n const unseen = watcherAt(own.length > 0 ? own : dirs, me.profile ?? me.name ?? me.handle ?? me.actor, channel);\n let tail: ChildProcess | undefined;\n const end = (code: number) => {\n unseen();\n tail?.removeAllListeners('exit');\n tail?.kill();\n process.exit(code);\n };\n // Stopped by its monitor, where the system says so: the page isn't left thinking someone watches.\n for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP'] as const) process.on(signal, () => end(0));\n\n // Whoever started the watch reads its lines. With that gone (a session that ended and left the watch behind) no one\n // does, and the page mustn't go on saying an agent watches. Run through a runner, the shell is a few processes up,\n // so those are watched too: any gone, and the watch ends. A dead parent shows as another parent's ID, except on\n // Windows, where the system is asked whether it's still a process.\n const parent = process.ppid;\n const above = ancestors(3);\n const orphaned = () => process.ppid !== parent || gone(parent) || above.some(gone);\n setInterval(() => orphaned() && end(0), 5000);\n\n say(`watching ${channel} on ${url ?? \"the team's board\"} as ${me.handle ?? me.actor}`);\n // With no profile (an agent `profileOf` doesn't know), the person's replies and the watcher's own are one actor's:\n // none can be left out.\n if (me.profile === null) {\n say(\n `you write as ${me.handle ?? me.actor}, the person's own identity, as nothing here says which agent you are: set BOARD_PROFILE=<your name> (claude, codex) on every command, this watch too, and start it again`,\n );\n }\n const waiting = (ready ? ready.split('\\n') : []).filter((line) => /^#\\d+/.test(line));\n for (const line of waiting) say(`ready: ${line}`);\n if (values.once && waiting.length > 0) end(0);\n\n /** One thing to act on: all `--once` waits for. */\n const event = (line: string) => {\n say(line);\n if (values.once) end(0);\n };\n\n // Anything on the channel puts the end off, the watcher's own claims and replies too: it's being worked.\n let quiet: ReturnType<typeof setTimeout> | undefined;\n const heard = () => {\n clearTimeout(quiet);\n quiet = setTimeout(() => {\n say(\n `idle: nothing on ${channel} in ${values.idle}, so the watch is over. Don't start it again by yourself: tell the person in a line that you've stopped watching, and watch again when they ask. Only if you're working a task now, start it once more when that's done.`,\n );\n end(2);\n }, idle);\n };\n heard();\n\n // What the board says about each thread: its root's first line and where, to name it when a task is made.\n const roots = new Map<number, string>();\n // The last event heard, which a tail started again follows from: nothing left while the board was away is missed.\n let cursor: string | undefined;\n const heardOf = (line: string) => {\n let e: Tailed;\n try {\n e = JSON.parse(line) as Tailed;\n } catch {\n return;\n }\n if (e.cursor !== undefined) cursor = e.cursor;\n heard();\n const p = e.payload ?? {};\n const label = (key: string) => p.labels?.[key];\n if (e.type === 'message.posted' && p.re === null && p.thread !== undefined) {\n const at = label('deictic.at');\n const page = label('deictic.page');\n const project = label('deictic.project');\n roots.set(p.thread, `\"${first(p.text ?? '')}\"${at ? ` at ${at}` : ''}${page ? ` on ${page}` : ''}${project ? ` in ${project}` : ''}`);\n }\n if (e.type === 'task.created') event(`new task #${p.id}: ${roots.get(p.thread ?? -1) ?? ''}. Read it: npx deictic task ${p.id}`);\n if (e.type === 'message.posted' && p.re !== null && p.re !== undefined) {\n if (me.profile !== null && p.by?.actor === me.actor) return;\n const by = e.message?.author?.handle ?? p.by?.actor ?? 'someone';\n event(`reply on #${p.re} by ${by}: ${first(p.text ?? '')}`);\n }\n if (e.type === 'task.canceled')\n event(`task #${p.id} canceled: ${p.reason ?? ''}. Stop work on it, and put back what you changed for it.`);\n };\n\n const over = (code: number | null) => {\n say(`watch ended (vb tail exited ${code}): start it again`);\n end(1);\n };\n\n /** Follows the channel, from `cursor` on where there is one, and again when the board comes back after going away. */\n const follow = (again: boolean) => {\n const started = Date.now();\n const from = cursor === undefined ? [] : ['--after', cursor];\n const [command, argv, options] = vbCommand(['tail', channel, ...labels, ...from, '--json']);\n const child = spawn(command, argv, { env: options.env, shell: options.shell, stdio: ['ignore', 'pipe', 'inherit'] });\n tail = child;\n createInterface({ input: child.stdout }).on('line', heardOf);\n child.on('exit', (code) => {\n if (again && Date.now() - started < SOON) return over(code);\n say(`the board went away (vb tail exited ${code}): waiting for it to come back`);\n const until = Date.now() + BACK;\n const tried = () => {\n // Asked anew each time: a board started again may be at another URL, and the CLI gets itself a new token for it.\n if (answers()) {\n say(`the board is back on ${boardUrl() ?? \"the team's board\"}: watching ${channel} again`);\n // With nothing heard before it went, what's ready is all there is to go by.\n if (cursor === undefined) {\n const now = vb(['tasks', channel, '--state', 'ready', ...labels]).trim();\n for (const l of now.split('\\n').filter((l) => /^#\\d+/.test(l) && !waiting.includes(l))) event(`ready: ${l}`);\n }\n return follow(true);\n }\n if (Date.now() > until) return over(code);\n setTimeout(tried, 2000);\n };\n setTimeout(tried, 2000);\n });\n };\n follow(false);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAa,QAAQ;;AAmBrB,MAAM,OAAO;;AAEb,MAAM,OAAO;;AAGb,SAAS,UAA+B;CACtC,MAAM,MACJ,QAAQ,aAAa,UACjB,UACE,cACA;EAAC;EAAc;EAAY;CAA+E,GAC1G,EACE,UAAU,OACZ,CACF,IACA,UAAU,MAAM;EAAC;EAAM;EAAM;EAAQ;EAAM;CAAO,GAAG,EAAE,UAAU,OAAO,CAAC;CAC/E,MAAM,sBAAM,IAAI,IAAoB;CACpC,KAAK,MAAM,SAAS,IAAI,UAAU,GAAA,CAAI,MAAM,IAAI,GAAG;EACjD,MAAM,CAAC,KAAK,QAAQ,KAAK,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,MAAM;EACvD,IAAI,QAAQ,KAAA,KAAa,SAAS,KAAA,KAAa,OAAO,UAAU,GAAG,KAAK,OAAO,UAAU,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI;CACnH;CACA,OAAO;AACT;;;;;AAMA,SAAS,UAAU,OAAyB;CAC1C,MAAM,KAAK,QAAQ;CACnB,MAAM,MAAgB,CAAC;CACvB,KAAK,IAAI,MAAM,GAAG,IAAI,QAAQ,IAAI,GAAG,QAAQ,KAAA,KAAa,MAAM,KAAK,IAAI,SAAS,SAAS,CAAC,IAAI,SAAS,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG,GAC7H,IAAI,KAAK,GAAG;CACd,OAAO;AACT;;AAGA,SAAS,KAAK,KAAsB;CAClC,IAAI;EACF,QAAQ,KAAK,KAAK,CAAC;EACnB,OAAO;CACT,SAAS,GAAG;EACV,OAAQ,EAAwB,SAAS;CAC3C;AACF;AAEA,SAAgB,IAAI,MAAs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,MAAM,cAAc;IAElB,IAAI,QAAQ,GAAG;KACb,IAAI,wBAAwB,SAAS,KAAK,mBAAmB,aAAa,QAAQ,OAAO;KAEzF,IAAI,WAAW,KAAA,GAAW;MACxB,MAAM,MAAM,GAAG;OAAC;OAAS;OAAS;OAAW;OAAS,GAAG;MAAM,CAAC,CAAC,CAAC,KAAK;MACvE,KAAK,MAAM,KAAK,IAAI,MAAM,IAAI,CAAC,CAAC,QAAQ,MAAM,QAAQ,KAAK,CAAC,KAAK,CAAC,QAAQ,SAAS,CAAC,CAAC,GAAG,MAAM,UAAU,GAAG;KAC7G;KACA,OAAO,OAAO,IAAI;IACpB;IACA,IAAI,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,IAAI;IACxC,WAAW,OAAO,GAAI;GACxB;GACA,WAAW,OAAO,GAAI;EACxB,CAAC;CACH;CACA,OAAO,KAAK;AACd"}
@@ -0,0 +1,62 @@
1
+ import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { t as keptIn } from "./kept.js";
4
+ // src/plugins/tasks/watchers.ts
5
+ /**
6
+ * Who watches the channel for tasks. A board can't say (it knows who claimed a task, not who's listening), so a
7
+ * watch says it itself: `deictic watch` keeps a file under `.deictic/watchers` while it runs (`watcherAt`), written
8
+ * again every `BEAT`, and the Task tab shows the names, so a person knows whether a task they add is taken up.
9
+ * (An agent holding a claim is one more, which the board does say: `agentsOf`, in `index.ts`.)
10
+ */
11
+ /** How often a watch says it's still there, and so how soon the page knows of one that was killed (three missed). */
12
+ const BEAT = 2e4;
13
+ /** How old a watch's last word may be: three of its beats, as one killed says nothing more. */
14
+ const FRESH = 3 * BEAT;
15
+ /**
16
+ * A watch's file in each of `dirs` (`.deictic/` folders), written now and again every `BEAT`. Answers what takes
17
+ * it back, as the watch ends.
18
+ */
19
+ function watcherAt(dirs, name, channel) {
20
+ const files = dirs.map((dir) => join(dir, "watchers", `${process.pid}.json`));
21
+ const beat = () => {
22
+ const watcher = {
23
+ name,
24
+ channel,
25
+ pid: process.pid,
26
+ at: Date.now()
27
+ };
28
+ for (const file of files) try {
29
+ mkdirSync(dirname(file), { recursive: true });
30
+ writeFileSync(file, `${JSON.stringify(watcher)}\n`);
31
+ } catch {}
32
+ };
33
+ beat();
34
+ const timer = setInterval(beat, BEAT);
35
+ return () => {
36
+ clearInterval(timer);
37
+ for (const file of files) rmSync(file, { force: true });
38
+ };
39
+ }
40
+ /** The names watching `channel` from this project now, each once, in order. */
41
+ function watchersOf(root, channel, now = Date.now()) {
42
+ const dir = keptIn(root, "watchers");
43
+ let files;
44
+ try {
45
+ files = readdirSync(dir);
46
+ } catch {
47
+ return [];
48
+ }
49
+ const names = /* @__PURE__ */ new Set();
50
+ for (const file of files) {
51
+ const path = join(dir, file);
52
+ try {
53
+ const { name, channel: of, at } = JSON.parse(readFileSync(path, "utf8"));
54
+ if (typeof at !== "number" || now - at > FRESH) rmSync(path, { force: true });
55
+ else if (of === channel && typeof name === "string") names.add(name);
56
+ } catch {}
57
+ }
58
+ return [...names].sort();
59
+ }
60
+ export { watchersOf as n, watcherAt as t };
61
+
62
+ //# sourceMappingURL=watchers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchers.js","names":[],"sources":["../../src/plugins/tasks/watchers.ts"],"sourcesContent":["/**\n * Who watches the channel for tasks. A board can't say (it knows who claimed a task, not who's listening), so a\n * watch says it itself: `deictic watch` keeps a file under `.deictic/watchers` while it runs (`watcherAt`), written\n * again every `BEAT`, and the Task tab shows the names, so a person knows whether a task they add is taken up.\n * (An agent holding a claim is one more, which the board does say: `agentsOf`, in `index.ts`.)\n */\nimport { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\nimport { keptIn } from '#src/tools/kept.ts';\n\n/** How often a watch says it's still there, and so how soon the page knows of one that was killed (three missed). */\nexport const BEAT = 20_000;\n/** How old a watch's last word may be: three of its beats, as one killed says nothing more. */\nconst FRESH = 3 * BEAT;\n\n/** What a watch keeps in a `.deictic/watchers` while it runs: one file per process. */\nexport interface Watcher {\n name: string;\n channel: string;\n pid: number;\n at: number;\n}\n\n/**\n * A watch's file in each of `dirs` (`.deictic/` folders), written now and again every `BEAT`. Answers what takes\n * it back, as the watch ends.\n */\nexport function watcherAt(dirs: readonly string[], name: string, channel: string): () => void {\n const files = dirs.map((dir) => join(dir, 'watchers', `${process.pid}.json`));\n const beat = () => {\n const watcher: Watcher = { name, channel, pid: process.pid, at: Date.now() };\n for (const file of files) {\n try {\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, `${JSON.stringify(watcher)}\\n`);\n } catch {\n // A folder that can't be written to: the watch goes on, unseen.\n }\n }\n };\n beat();\n const timer = setInterval(beat, BEAT);\n return () => {\n clearInterval(timer);\n for (const file of files) rmSync(file, { force: true });\n };\n}\n\n/** The names watching `channel` from this project now, each once, in order. */\nexport function watchersOf(root: string, channel: string, now = Date.now()): string[] {\n const dir = keptIn(root, 'watchers');\n let files: string[];\n try {\n files = readdirSync(dir);\n } catch {\n return [];\n }\n const names = new Set<string>();\n for (const file of files) {\n const path = join(dir, file);\n try {\n const { name, channel: of, at } = JSON.parse(readFileSync(path, 'utf8')) as Partial<Watcher>;\n if (typeof at !== 'number' || now - at > FRESH) rmSync(path, { force: true });\n else if (of === channel && typeof name === 'string') names.add(name);\n } catch {\n // Half written: whole by the next read.\n }\n }\n return [...names].sort();\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,OAAO;;AAEpB,MAAM,QAAQ,IAAI;;;;;AAclB,SAAgB,UAAU,MAAyB,MAAc,SAA6B;CAC5F,MAAM,QAAQ,KAAK,KAAK,QAAQ,KAAK,KAAK,YAAY,GAAG,QAAQ,IAAI,MAAM,CAAC;CAC5E,MAAM,aAAa;EACjB,MAAM,UAAmB;GAAE;GAAM;GAAS,KAAK,QAAQ;GAAK,IAAI,KAAK,IAAI;EAAE;EAC3E,KAAK,MAAM,QAAQ,OACjB,IAAI;GACF,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;GAC5C,cAAc,MAAM,GAAG,KAAK,UAAU,OAAO,EAAE,GAAG;EACpD,QAAQ,CAER;CAEJ;CACA,KAAK;CACL,MAAM,QAAQ,YAAY,MAAM,IAAI;CACpC,aAAa;EACX,cAAc,KAAK;EACnB,KAAK,MAAM,QAAQ,OAAO,OAAO,MAAM,EAAE,OAAO,KAAK,CAAC;CACxD;AACF;;AAGA,SAAgB,WAAW,MAAc,SAAiB,MAAM,KAAK,IAAI,GAAa;CACpF,MAAM,MAAM,OAAO,MAAM,UAAU;CACnC,IAAI;CACJ,IAAI;EACF,QAAQ,YAAY,GAAG;CACzB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,KAAK,KAAK,IAAI;EAC3B,IAAI;GACF,MAAM,EAAE,MAAM,SAAS,IAAI,OAAO,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;GACvE,IAAI,OAAO,OAAO,YAAY,MAAM,KAAK,OAAO,OAAO,MAAM,EAAE,OAAO,KAAK,CAAC;QACvE,IAAI,OAAO,WAAW,OAAO,SAAS,UAAU,MAAM,IAAI,IAAI;EACrE,QAAQ,CAER;CACF;CACA,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK;AACzB"}
@@ -1,4 +1,4 @@
1
- import { n as Model, r as Op } from "../shared/index6.js";
1
+ import { n as Model, r as Op } from "../shared/index9.js";
2
2
  declare const _default: import("deictic").ClientPlugin<Model, Op, unknown>;
3
3
  export { _default as default };
4
4
  //# sourceMappingURL=client.d.ts.map
@@ -1,4 +1,4 @@
1
- import { defineClientPlugin } from "../index.js";
1
+ import { n as defineClientPlugin } from "../shared/src.js";
2
2
  // src/plugins/tailwind/client.ts
3
3
  /**
4
4
  * Tailwind's panel: the element's classes as chips, a field to add more, and Save. Every change
@@ -1,2 +1,2 @@
1
- import { a as tailwind, i as TailwindOptions, n as Model, o as Alternatives, r as Op, s as ClassInfo, t as Extra } from "../shared/index6.js";
1
+ import { a as tailwind, i as TailwindOptions, n as Model, o as Alternatives, r as Op, s as ClassInfo, t as Extra } from "../shared/index9.js";
2
2
  export { type Alternatives, type ClassInfo, Extra, Model, Op, TailwindOptions, tailwind as default, tailwind };
@@ -1,4 +1,4 @@
1
- import { Refusal, definePlugin } from "../index.js";
1
+ import { r as definePlugin, t as Refusal } from "../shared/src.js";
2
2
  import { readFileSync, statSync } from "node:fs";
3
3
  import { createRequire } from "node:module";
4
4
  import { dirname, join, resolve } from "node:path";
@@ -1,4 +1,4 @@
1
- import { n as Change, o as Model } from "../shared/index5.js";
1
+ import { n as Change, o as Model } from "../shared/index7.js";
2
2
  /** The event the page hears of each added task by, on `window`: its `detail` is a `TaskAdded`. */
3
3
  export declare const TASK_ADDED = "deictic:task";
4
4
  declare const _default: import("deictic").ClientPlugin<Model, Change, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/plugins/tasks/client.ts"],"mappings":";;qBAkQa;cAwBb,4B"}
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/plugins/tasks/client.ts"],"mappings":";;qBAyTa;cAwBb,4B"}
@@ -1,5 +1,5 @@
1
1
  import { n as liveWaveform } from "../shared/waveform.js";
2
- import { defineClientPlugin } from "../index.js";
2
+ import { n as defineClientPlugin } from "../shared/src.js";
3
3
  // src/plugins/tasks/client.ts
4
4
  /**
5
5
  * The tasks panel: the tasks already about this element and their state, and a field to add one. Each
@@ -143,16 +143,53 @@ const parentOf = (el) => {
143
143
  const root = el.getRootNode();
144
144
  return root instanceof ShadowRoot ? root.host : void 0;
145
145
  };
146
- /** How many places a chain names after the element's own. */
147
- const CHAIN = 5;
146
+ /** How many places a chain names after the element's own: who uses it, and who uses that. Further out is the app's shell. */
147
+ const CHAIN = 3;
148
+ /** React's fiber of an element it rendered, which it keeps on the element under a key of its own. */
149
+ const fiberOf = (el) => {
150
+ const key = Object.keys(el).find((k) => k.startsWith("__reactFiber$"));
151
+ return key === void 0 ? void 0 : el[key];
152
+ };
153
+ const ownerOf = (of) => of?._debugOwner ?? of?.owner ?? void 0;
154
+ /** A component's name, through `memo` and `forwardRef`, or nothing for one written without. */
155
+ function componentOf(owner) {
156
+ if (typeof owner.name === "string") return owner.name === "" ? void 0 : owner.name;
157
+ let type = owner.type;
158
+ for (let depth = 0; depth < 4 && type !== null && type !== void 0; depth++) {
159
+ const name = type.displayName ?? type.name;
160
+ if (typeof name === "string" && name !== "") return name;
161
+ type = type.render ?? type.type;
162
+ }
163
+ }
148
164
  /**
149
- * The source `el` rendered through, after its own file, nearest first, each a `file:line`: a shared component's
150
- * own line is the same wherever it's used, and what uses it is the next file out (or a component between them,
151
- * which is why there are several). Read off the marks around it, the only trace of source the page has: each
152
- * place is the nearest element the next file wrote, which is where, in that file, the one before is used.
165
+ * The source `el` rendered through, after its own place, nearest first: a shared component's own line is the same
166
+ * wherever it's used, and the change is most often in what uses it, or in what uses that.
167
+ *
168
+ * With React in development, those are the components that wrote it, each the one whose JSX has the one before:
169
+ * `Field (src/Field.tsx:20)`, its line the nearest element around `el` that the component wrote, or the name alone
170
+ * for one with no element of its own around it (it wraps what it uses only in other components), which the marks
171
+ * can't show at all. A layout component the element was only passed through isn't among them.
172
+ *
173
+ * Without (another framework, a production build) it's read off the marks around it, each a `file:line`: the
174
+ * nearest element each next file wrote.
153
175
  */
154
176
  function chainOf(el, file) {
155
177
  const found = [];
178
+ const wrote = ownerOf(fiberOf(el));
179
+ if (wrote !== void 0) {
180
+ for (let owner = ownerOf(wrote); owner !== void 0 && found.length < CHAIN; owner = ownerOf(owner)) {
181
+ const name = componentOf(owner);
182
+ let place;
183
+ for (let at = parentOf(el); at !== void 0 && place === void 0; at = parentOf(at)) {
184
+ const by = ownerOf(fiberOf(at));
185
+ if (by === void 0 || by !== owner && by !== owner.alternate) continue;
186
+ place = at.getAttribute("data-deictic")?.replace(/:\d+$/, "");
187
+ }
188
+ if (name !== void 0) found.push(place === void 0 ? name : `${name} (${place})`);
189
+ else if (place !== void 0) found.push(place);
190
+ }
191
+ if (found.length > 0) return found;
192
+ }
156
193
  let last = file;
157
194
  for (let at = parentOf(el); at !== void 0 && found.length < CHAIN; at = parentOf(at)) {
158
195
  const mark = at.getAttribute("data-deictic");
@@ -624,7 +661,7 @@ var client_default = defineClientPlugin({
624
661
  const item = element("li");
625
662
  const state = element("span", {
626
663
  className: `state ${t.state}`,
627
- title: t.state
664
+ title: t.by === void 0 ? t.state : `${t.state} by ${t.by}`
628
665
  });
629
666
  state.role = "img";
630
667
  const id = element("code", { textContent: `#${t.id}` });