@agimon-ai/po-task 0.0.0-alpha.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 (161) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/apiContracts.cjs +54 -0
  4. package/dist/apiContracts.cjs.map +1 -0
  5. package/dist/apiContracts.d.mts +53 -0
  6. package/dist/apiContracts.d.mts.map +1 -0
  7. package/dist/apiContracts.mjs +49 -0
  8. package/dist/apiContracts.mjs.map +1 -0
  9. package/dist/config-CFSs3iku.mjs +72 -0
  10. package/dist/config-CFSs3iku.mjs.map +1 -0
  11. package/dist/config-CdX-Bv8q.cjs +173 -0
  12. package/dist/config-CdX-Bv8q.cjs.map +1 -0
  13. package/dist/config.cjs +19 -0
  14. package/dist/config.d.mts +2 -0
  15. package/dist/config.mjs +2 -0
  16. package/dist/delegation-BiOy3_7g.mjs +7 -0
  17. package/dist/delegation-BiOy3_7g.mjs.map +1 -0
  18. package/dist/delegation-CdMqOZB4.mjs +626 -0
  19. package/dist/delegation-CdMqOZB4.mjs.map +1 -0
  20. package/dist/delegation-DsnKjMbJ.cjs +661 -0
  21. package/dist/delegation-DsnKjMbJ.cjs.map +1 -0
  22. package/dist/delegation-LDpHP2CC.cjs +12 -0
  23. package/dist/delegation-LDpHP2CC.cjs.map +1 -0
  24. package/dist/delegationManager.cjs +10 -0
  25. package/dist/delegationManager.d.mts +2 -0
  26. package/dist/delegationManager.mjs +3 -0
  27. package/dist/extensions/mcp-ui.mjs +23 -0
  28. package/dist/extensions/mcp-ui.mjs.map +1 -0
  29. package/dist/extensions/mcp.cjs +1144 -0
  30. package/dist/extensions/mcp.cjs.map +1 -0
  31. package/dist/extensions/mcp.d.mts +5 -0
  32. package/dist/extensions/mcp.d.mts.map +1 -0
  33. package/dist/extensions/mcp.mjs +1115 -0
  34. package/dist/extensions/mcp.mjs.map +1 -0
  35. package/dist/extensions/native.mjs +1175 -0
  36. package/dist/extensions/native.mjs.map +1 -0
  37. package/dist/extensions/server.cjs +569 -0
  38. package/dist/extensions/server.cjs.map +1 -0
  39. package/dist/extensions/server.d.mts +5 -0
  40. package/dist/extensions/server.d.mts.map +1 -0
  41. package/dist/extensions/server.mjs +563 -0
  42. package/dist/extensions/server.mjs.map +1 -0
  43. package/dist/extensions/web.mjs +1018 -0
  44. package/dist/extensions/web.mjs.map +1 -0
  45. package/dist/index-B-3sCF2S.d.mts +43 -0
  46. package/dist/index-B-3sCF2S.d.mts.map +1 -0
  47. package/dist/index-B1JPJdpZ.d.mts +51 -0
  48. package/dist/index-B1JPJdpZ.d.mts.map +1 -0
  49. package/dist/index-CUWCvh-E.d.mts +72 -0
  50. package/dist/index-CUWCvh-E.d.mts.map +1 -0
  51. package/dist/index-DlmXKyhQ.d.mts +34 -0
  52. package/dist/index-DlmXKyhQ.d.mts.map +1 -0
  53. package/dist/index-Dvb8X_qB.d.mts +67 -0
  54. package/dist/index-Dvb8X_qB.d.mts.map +1 -0
  55. package/dist/index-XY9VPmfm.d.mts +26 -0
  56. package/dist/index-XY9VPmfm.d.mts.map +1 -0
  57. package/dist/index-teIf67qQ.d.mts +196 -0
  58. package/dist/index-teIf67qQ.d.mts.map +1 -0
  59. package/dist/index.cjs +93 -0
  60. package/dist/index.d.mts +11 -0
  61. package/dist/index.mjs +12 -0
  62. package/dist/invariants-DhjEjBPU.cjs +79 -0
  63. package/dist/invariants-DhjEjBPU.cjs.map +1 -0
  64. package/dist/invariants-q_UamF7D.mjs +62 -0
  65. package/dist/invariants-q_UamF7D.mjs.map +1 -0
  66. package/dist/logSinkTelemetry-B23qGiP-.cjs +52 -0
  67. package/dist/logSinkTelemetry-B23qGiP-.cjs.map +1 -0
  68. package/dist/logSinkTelemetry-BMBsC54p.mjs +41 -0
  69. package/dist/logSinkTelemetry-BMBsC54p.mjs.map +1 -0
  70. package/dist/logSinkTelemetry.cjs +6 -0
  71. package/dist/logSinkTelemetry.d.mts +23 -0
  72. package/dist/logSinkTelemetry.d.mts.map +1 -0
  73. package/dist/logSinkTelemetry.mjs +3 -0
  74. package/dist/paths-CSya2l9_.cjs +308 -0
  75. package/dist/paths-CSya2l9_.cjs.map +1 -0
  76. package/dist/paths-Cah1vFGv.mjs +207 -0
  77. package/dist/paths-Cah1vFGv.mjs.map +1 -0
  78. package/dist/processLiveness-Ccd9wenT.mjs +20 -0
  79. package/dist/processLiveness-Ccd9wenT.mjs.map +1 -0
  80. package/dist/processLiveness-umpNgsPR.cjs +25 -0
  81. package/dist/processLiveness-umpNgsPR.cjs.map +1 -0
  82. package/dist/reconcile-BcD-hTbd.mjs +63 -0
  83. package/dist/reconcile-BcD-hTbd.mjs.map +1 -0
  84. package/dist/reconcile-cRL0NjDr.cjs +80 -0
  85. package/dist/reconcile-cRL0NjDr.cjs.map +1 -0
  86. package/dist/reducer-BEfJFM5L.mjs +345 -0
  87. package/dist/reducer-BEfJFM5L.mjs.map +1 -0
  88. package/dist/reducer-BV0YIZ2o.cjs +380 -0
  89. package/dist/reducer-BV0YIZ2o.cjs.map +1 -0
  90. package/dist/storeInvariants.cjs +5 -0
  91. package/dist/storeInvariants.d.mts +23 -0
  92. package/dist/storeInvariants.d.mts.map +1 -0
  93. package/dist/storeInvariants.mjs +2 -0
  94. package/dist/storePaths.cjs +14 -0
  95. package/dist/storePaths.d.mts +2 -0
  96. package/dist/storePaths.mjs +2 -0
  97. package/dist/storeProcessLiveness.cjs +3 -0
  98. package/dist/storeProcessLiveness.d.mts +11 -0
  99. package/dist/storeProcessLiveness.d.mts.map +1 -0
  100. package/dist/storeProcessLiveness.mjs +2 -0
  101. package/dist/storeReconcile.cjs +5 -0
  102. package/dist/storeReconcile.d.mts +2 -0
  103. package/dist/storeReconcile.mjs +2 -0
  104. package/dist/storeReducer.cjs +8 -0
  105. package/dist/storeReducer.d.mts +2 -0
  106. package/dist/storeReducer.mjs +2 -0
  107. package/dist/storeTaskGraph.cjs +7 -0
  108. package/dist/storeTaskGraph.d.mts +2 -0
  109. package/dist/storeTaskGraph.mjs +2 -0
  110. package/dist/storeTaskStore.cjs +3 -0
  111. package/dist/storeTaskStore.d.mts +2 -0
  112. package/dist/storeTaskStore.mjs +2 -0
  113. package/dist/storeTypes.cjs +6 -0
  114. package/dist/storeTypes.d.mts +2 -0
  115. package/dist/storeTypes.mjs +2 -0
  116. package/dist/task-CXF9VULl.cjs +49 -0
  117. package/dist/task-CXF9VULl.cjs.map +1 -0
  118. package/dist/task-DJpTteeJ.d.mts +187 -0
  119. package/dist/task-DJpTteeJ.d.mts.map +1 -0
  120. package/dist/task-DO0TwZ0z.mjs +132 -0
  121. package/dist/task-DO0TwZ0z.mjs.map +1 -0
  122. package/dist/task-Dhta7JyA.d.mts +126 -0
  123. package/dist/task-Dhta7JyA.d.mts.map +1 -0
  124. package/dist/task-UvW877Ez.cjs +227 -0
  125. package/dist/task-UvW877Ez.cjs.map +1 -0
  126. package/dist/task-giCbpKzV.mjs +26 -0
  127. package/dist/task-giCbpKzV.mjs.map +1 -0
  128. package/dist/taskGraph-BOQvT0-M.mjs +63 -0
  129. package/dist/taskGraph-BOQvT0-M.mjs.map +1 -0
  130. package/dist/taskGraph-BskRslrr.cjs +92 -0
  131. package/dist/taskGraph-BskRslrr.cjs.map +1 -0
  132. package/dist/taskGraph-D0zFHF2p.d.mts +25 -0
  133. package/dist/taskGraph-D0zFHF2p.d.mts.map +1 -0
  134. package/dist/taskResult-D2G7b4w-.cjs +224 -0
  135. package/dist/taskResult-D2G7b4w-.cjs.map +1 -0
  136. package/dist/taskResult-edBAAKSH.mjs +165 -0
  137. package/dist/taskResult-edBAAKSH.mjs.map +1 -0
  138. package/dist/taskStore-DjU60rMm.cjs +215 -0
  139. package/dist/taskStore-DjU60rMm.cjs.map +1 -0
  140. package/dist/taskStore-pAJ971Ml.mjs +208 -0
  141. package/dist/taskStore-pAJ971Ml.mjs.map +1 -0
  142. package/dist/telemetry-Ca0I3Tqo.cjs +30 -0
  143. package/dist/telemetry-Ca0I3Tqo.cjs.map +1 -0
  144. package/dist/telemetry-DyS44zAD.mjs +25 -0
  145. package/dist/telemetry-DyS44zAD.mjs.map +1 -0
  146. package/dist/telemetry-FMGRovb4.d.mts +35 -0
  147. package/dist/telemetry-FMGRovb4.d.mts.map +1 -0
  148. package/dist/toolPromptGuidelines.cjs +27 -0
  149. package/dist/toolPromptGuidelines.cjs.map +1 -0
  150. package/dist/toolPromptGuidelines.d.mts +13 -0
  151. package/dist/toolPromptGuidelines.d.mts.map +1 -0
  152. package/dist/toolPromptGuidelines.mjs +26 -0
  153. package/dist/toolPromptGuidelines.mjs.map +1 -0
  154. package/dist/toolResponseEnvelope.cjs +12 -0
  155. package/dist/toolResponseEnvelope.d.mts +2 -0
  156. package/dist/toolResponseEnvelope.mjs +2 -0
  157. package/dist/toolSchema.cjs +18 -0
  158. package/dist/toolSchema.d.mts +2 -0
  159. package/dist/toolSchema.mjs +2 -0
  160. package/package.json +223 -0
  161. package/src/types/webTasks.ts +24 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taskStore-DjU60rMm.cjs","names":["emptyDocument","canonicalizeTasks","resolveStorePath","fs","TASK_EVENT","path","tempPathFor","lockPathFor","isProcessAlive"],"sources":["../src/services/taskStore/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { emptyDocument, STORE_SCHEMA_VERSION, type Task, type TaskDocument } from '../../models/task';\nimport { TASK_EVENT, type TaskFailureReporter } from '../../types/telemetry';\nimport { canonicalizeTasks } from '../invariants';\nimport { lockPathFor, resolveStorePath, STORE_PATH_ENV, tempPathFor } from '../paths';\nimport { isProcessAlive } from '../processLiveness';\n\nconst LOCK_TIMEOUT_MS = 2000;\nconst LOCK_STALE_MS = 10_000;\nconst LOCK_RETRY_BASE_MS = 10;\nconst LOCK_RETRY_MAX_MS = 60;\nconst UTF8_ENCODING = 'utf8';\nconst MISSING_FILE_CODE = 'ENOENT';\nconst LOCK_EXISTS_CODE = 'EEXIST';\nconst STORE_PATH_ATTRIBUTE = 'store.path';\n\nexport interface TaskStoreOptions {\n cwd?: string;\n env?: Readonly<Record<string, string | undefined>>;\n storePath?: string;\n /** How long to wait for the advisory lock before proceeding lock-free. */\n lockTimeoutMs?: number;\n /** Where swallowed failures go, so silent degradation stays visible. */\n report?: TaskFailureReporter;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Coerce arbitrary parsed JSON into a valid document.\n *\n * A corrupt or truncated store must not take the session down: the worst\n * acceptable outcome is starting from an empty list, never a crash on startup.\n */\nfunction normalizeDocument(parsed: unknown): TaskDocument {\n if (!parsed || typeof parsed !== 'object') return emptyDocument();\n const candidate = parsed as Partial<TaskDocument>;\n if (!Array.isArray(candidate.tasks)) return emptyDocument();\n\n const tasks = canonicalizeTasks(\n candidate.tasks.filter(\n (task): task is Task => Boolean(task) && typeof task === 'object' && typeof (task as Task).id === 'number',\n ),\n );\n const maxId = tasks.reduce((max, task) => Math.max(max, task.id), 0);\n return {\n version: typeof candidate.version === 'number' ? candidate.version : STORE_SCHEMA_VERSION,\n rev: typeof candidate.rev === 'number' ? candidate.rev : 0,\n nextId: typeof candidate.nextId === 'number' && candidate.nextId > maxId ? candidate.nextId : maxId + 1,\n tasks,\n };\n}\n\n/**\n * File-backed task store shared by one root session and its delegated children.\n *\n * Durability model: the JSON file is the source of truth. Mutations are\n * read-modify-write under an advisory lock so concurrent delegated processes\n * cannot clobber each other, and writes land via temp-file rename so a\n * crash mid-write can never leave a partial document behind.\n */\nexport class TaskStore {\n storePath: string;\n\n private readonly cwd: string;\n private readonly env: Readonly<Record<string, string | undefined>>;\n private cached: TaskDocument = emptyDocument();\n private readonly listeners = new Set<(document: TaskDocument) => void>();\n private readonly lockTimeoutMs: number;\n private readonly report?: TaskFailureReporter;\n\n constructor(options: TaskStoreOptions = {}) {\n this.cwd = options.cwd ?? process.cwd();\n this.env = options.env ?? process.env;\n this.storePath = options.storePath ?? resolveStorePath(this.cwd, this.env);\n this.lockTimeoutMs = options.lockTimeoutMs ?? LOCK_TIMEOUT_MS;\n this.report = options.report;\n }\n\n /** Bind a default store to the current session tree before reading it. */\n configureSession(sessionKey: string): void {\n if (this.env[STORE_PATH_ENV]?.trim()) return;\n this.storePath = resolveStorePath(this.cwd, this.env, sessionKey);\n this.cached = emptyDocument();\n }\n\n /** Last document read from disk, without hitting the filesystem. */\n get snapshot(): TaskDocument {\n return this.cached;\n }\n\n read(): TaskDocument {\n try {\n const raw = fs.readFileSync(this.storePath, UTF8_ENCODING);\n this.cached = normalizeDocument(JSON.parse(raw));\n } catch (error) {\n // A missing file is the normal state before the first write. Anything\n // else means the task list just silently became empty, which is worth a\n // record: unreadable or corrupt JSON looks identical to \"no tasks yet\".\n if ((error as NodeJS.ErrnoException).code !== MISSING_FILE_CODE) {\n this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });\n }\n this.cached = emptyDocument();\n }\n return this.cached;\n }\n\n async readAsync(\n shouldApply: () => boolean = () => true,\n onReadError?: (error: unknown) => void,\n ): Promise<TaskDocument> {\n const storePath = this.storePath;\n const document = await this.readDocumentAsync(storePath, onReadError);\n if (!shouldApply()) return document;\n this.cached = document;\n return document;\n }\n\n private async readDocumentAsync(\n storePath: string = this.storePath,\n onReadError?: (error: unknown) => void,\n ): Promise<TaskDocument> {\n try {\n const raw = await fs.promises.readFile(storePath, UTF8_ENCODING);\n return normalizeDocument(JSON.parse(raw));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== MISSING_FILE_CODE) {\n this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: storePath });\n try {\n onReadError?.(error);\n } catch {\n // Diagnostic failures must not change fail-open reads.\n }\n }\n return emptyDocument();\n }\n }\n\n /**\n * Apply a mutation under the store lock.\n *\n * `mutate` receives the freshest on-disk document and returns either the next\n * document to commit or `undefined` for a read-only action (list/get), which\n * skips the write entirely so queries never bump `rev`.\n */\n async mutate<T>(\n mutate: (document: TaskDocument) => { document?: TaskDocument; value: T },\n ): Promise<{ document: TaskDocument; value: T }> {\n const release = await this.acquireLock();\n const outcome = (() => {\n try {\n const current = this.read();\n const mutation = mutate(current);\n if (!mutation.document) {\n return { result: { document: current, value: mutation.value } };\n }\n const committed = this.write(mutation.document);\n return {\n result: { document: committed, value: mutation.value },\n notification: committed,\n };\n } finally {\n release();\n }\n })();\n if (outcome.notification) {\n this.notifyCommitted(outcome.notification);\n }\n return outcome.result;\n }\n\n private notifyCommitted(committed: TaskDocument): void {\n for (const listener of this.listeners) {\n try {\n listener(committed);\n } catch (error) {\n this.report?.error(TASK_EVENT.storeListenerFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });\n }\n }\n }\n\n private write(document: TaskDocument): TaskDocument {\n const next: TaskDocument = { ...document, version: STORE_SCHEMA_VERSION, rev: document.rev + 1 };\n fs.mkdirSync(path.dirname(this.storePath), { recursive: true });\n const temp = tempPathFor(this.storePath);\n fs.writeFileSync(temp, `${JSON.stringify(next, undefined, 2)}\\n`, UTF8_ENCODING);\n fs.renameSync(temp, this.storePath);\n this.cached = next;\n return next;\n }\n\n private async acquireLock(): Promise<() => void> {\n const lockPath = lockPathFor(this.storePath);\n fs.mkdirSync(path.dirname(this.storePath), { recursive: true });\n const deadline = Date.now() + this.lockTimeoutMs;\n\n for (;;) {\n try {\n const handle = fs.openSync(lockPath, 'wx');\n fs.writeSync(handle, JSON.stringify({ pid: process.pid, time: Date.now() }));\n fs.closeSync(handle);\n return () => fs.rmSync(lockPath, { force: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== LOCK_EXISTS_CODE) throw error;\n // The deadline is checked before breaking a stale lock so a peer that\n // keeps recreating one cannot spin this loop without bound.\n if (Date.now() >= deadline) {\n // Proceeding lock-free beats stalling the agent: the rename is atomic,\n // so the worst case is a lost concurrent update, not a corrupt file.\n // Reported because a lost update here can strand a delegation.\n this.report?.warn(\n TASK_EVENT.storeLockTimeout,\n new Error(`Task store lock still held after ${this.lockTimeoutMs}ms; proceeding without it`),\n { [STORE_PATH_ATTRIBUTE]: this.storePath },\n );\n return () => {};\n }\n // Clearing a dead holder's lock still goes through the backoff. Yielding\n // on every iteration is what stops a peer that keeps recreating the\n // lock from turning this into a spin.\n this.breakStaleLock(lockPath);\n await sleep(LOCK_RETRY_BASE_MS + Math.random() * LOCK_RETRY_MAX_MS);\n }\n }\n }\n\n /** Remove a lock left behind by a dead process or one held implausibly long. */\n private breakStaleLock(lockPath: string): boolean {\n try {\n const holder = JSON.parse(fs.readFileSync(lockPath, UTF8_ENCODING)) as { pid?: number; time?: number };\n const expired = typeof holder.time === 'number' && Date.now() - holder.time > LOCK_STALE_MS;\n const dead = typeof holder.pid === 'number' && !isProcessAlive(holder.pid);\n if (!expired && !dead) return false;\n fs.unlinkSync(lockPath);\n return true;\n } catch (error) {\n // Losing the race to another breaker is normal; a persistent failure here\n // shows up as the lock timeout above, so this stays a warning.\n if ((error as NodeJS.ErrnoException).code !== MISSING_FILE_CODE) {\n this.report?.warn(TASK_EVENT.storeLockBreakFailed, error, { [STORE_PATH_ATTRIBUTE]: lockPath });\n }\n return false;\n }\n }\n\n /**\n * Listen for commits made through this store instance.\n *\n * Live cross-process updates use the owning session's direct event bus. This\n * listener publishes local commits to that bus and never watches the filesystem.\n */\n onExternalChange(listener: (document: TaskDocument) => void): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n dispose(): void {\n this.listeners.clear();\n }\n}\n"],"mappings":";;;;;;;;;;AASA,MAAM,kBAAkB;AACxB,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AACtB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,uBAAuB;AAY7B,SAAS,MAAM,IAA2B;CACxC,OAAO,IAAI,SAAS,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;;;;;;;AAQA,SA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E,IAAI,KAAK,IAAI,KAAK,UAAU;IAI1B,KAAK,QAAQ,KACXC,kBAAAA,WAAW,kCACX,IAAI,MAAM,oCAAoC,KAAK,cAAc,0BAA0B,GAC3F,GAAG,uBAAuB,KAAK,UAAU,CAC3C;IACA,aAAa,CAAC;GAChB;GAIA,KAAK,eAAe,QAAQ;GAC5B,MAAM,MAAM,qBAAqB,KAAK,OAAO,IAAI,iBAAiB;EACpE;CAEJ;;CAGA,eAAuB,UAA2B;EAChD,IAAI;GACF,MAAM,SAAS,KAAK,MAAMD,QAAAA,QAAG,aAAa,UAAU,aAAa,CAAC;GAClE,MAAM,UAAU,OAAO,OAAO,SAAS,YAAY,KAAK,IAAI,IAAI,OAAO,OAAO;GAC9E,MAAM,OAAO,OAAO,OAAO,QAAQ,YAAY,CAACK,wBAAAA,eAAe,OAAO,GAAG;GACzE,IAAI,CAAC,WAAW,CAAC,MAAM,OAAO;GAC9B,QAAA,QAAG,WAAW,QAAQ;GACtB,OAAO;EACT,SAAS,OAAO;GAGd,IAAK,MAAgC,SAAS,mBAC5C,KAAK,QAAQ,KAAKJ,kBAAAA,WAAW,sBAAsB,OAAO,GAAG,uBAAuB,SAAS,CAAC;GAEhG,OAAO;EACT;CACF;;;;;;;CAQA,iBAAiB,UAAwD;EACvE,KAAK,UAAU,IAAI,QAAQ;EAC3B,aAAa,KAAK,UAAU,OAAO,QAAQ;CAC7C;CAEA,UAAgB;EACd,KAAK,UAAU,MAAM;CACvB;AACF"}
@@ -0,0 +1,208 @@
1
+ import { t as TASK_EVENT } from "./telemetry-DyS44zAD.mjs";
2
+ import { r as emptyDocument } from "./task-giCbpKzV.mjs";
3
+ import { t as isProcessAlive } from "./processLiveness-Ccd9wenT.mjs";
4
+ import { f as tempPathFor, l as resolveStorePath, r as lockPathFor } from "./paths-Cah1vFGv.mjs";
5
+ import { n as canonicalizeTasks } from "./invariants-q_UamF7D.mjs";
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ //#region src/services/taskStore/index.ts
9
+ const LOCK_TIMEOUT_MS = 2e3;
10
+ const LOCK_STALE_MS = 1e4;
11
+ const LOCK_RETRY_BASE_MS = 10;
12
+ const LOCK_RETRY_MAX_MS = 60;
13
+ const UTF8_ENCODING = "utf8";
14
+ const MISSING_FILE_CODE = "ENOENT";
15
+ const LOCK_EXISTS_CODE = "EEXIST";
16
+ const STORE_PATH_ATTRIBUTE = "store.path";
17
+ function sleep(ms) {
18
+ return new Promise((resolve) => setTimeout(resolve, ms));
19
+ }
20
+ /**
21
+ * Coerce arbitrary parsed JSON into a valid document.
22
+ *
23
+ * A corrupt or truncated store must not take the session down: the worst
24
+ * acceptable outcome is starting from an empty list, never a crash on startup.
25
+ */
26
+ function normalizeDocument(parsed) {
27
+ if (!parsed || typeof parsed !== "object") return emptyDocument();
28
+ const candidate = parsed;
29
+ if (!Array.isArray(candidate.tasks)) return emptyDocument();
30
+ const tasks = canonicalizeTasks(candidate.tasks.filter((task) => Boolean(task) && typeof task === "object" && typeof task.id === "number"));
31
+ const maxId = tasks.reduce((max, task) => Math.max(max, task.id), 0);
32
+ return {
33
+ version: typeof candidate.version === "number" ? candidate.version : 1,
34
+ rev: typeof candidate.rev === "number" ? candidate.rev : 0,
35
+ nextId: typeof candidate.nextId === "number" && candidate.nextId > maxId ? candidate.nextId : maxId + 1,
36
+ tasks
37
+ };
38
+ }
39
+ /**
40
+ * File-backed task store shared by one root session and its delegated children.
41
+ *
42
+ * Durability model: the JSON file is the source of truth. Mutations are
43
+ * read-modify-write under an advisory lock so concurrent delegated processes
44
+ * cannot clobber each other, and writes land via temp-file rename so a
45
+ * crash mid-write can never leave a partial document behind.
46
+ */
47
+ var TaskStore = class {
48
+ storePath;
49
+ cwd;
50
+ env;
51
+ cached = emptyDocument();
52
+ listeners = /* @__PURE__ */ new Set();
53
+ lockTimeoutMs;
54
+ report;
55
+ constructor(options = {}) {
56
+ this.cwd = options.cwd ?? process.cwd();
57
+ this.env = options.env ?? process.env;
58
+ this.storePath = options.storePath ?? resolveStorePath(this.cwd, this.env);
59
+ this.lockTimeoutMs = options.lockTimeoutMs ?? LOCK_TIMEOUT_MS;
60
+ this.report = options.report;
61
+ }
62
+ /** Bind a default store to the current session tree before reading it. */
63
+ configureSession(sessionKey) {
64
+ if (this.env["DOOM_TASK_STORE"]?.trim()) return;
65
+ this.storePath = resolveStorePath(this.cwd, this.env, sessionKey);
66
+ this.cached = emptyDocument();
67
+ }
68
+ /** Last document read from disk, without hitting the filesystem. */
69
+ get snapshot() {
70
+ return this.cached;
71
+ }
72
+ read() {
73
+ try {
74
+ const raw = fs.readFileSync(this.storePath, UTF8_ENCODING);
75
+ this.cached = normalizeDocument(JSON.parse(raw));
76
+ } catch (error) {
77
+ if (error.code !== MISSING_FILE_CODE) this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });
78
+ this.cached = emptyDocument();
79
+ }
80
+ return this.cached;
81
+ }
82
+ async readAsync(shouldApply = () => true, onReadError) {
83
+ const storePath = this.storePath;
84
+ const document = await this.readDocumentAsync(storePath, onReadError);
85
+ if (!shouldApply()) return document;
86
+ this.cached = document;
87
+ return document;
88
+ }
89
+ async readDocumentAsync(storePath = this.storePath, onReadError) {
90
+ try {
91
+ const raw = await fs.promises.readFile(storePath, UTF8_ENCODING);
92
+ return normalizeDocument(JSON.parse(raw));
93
+ } catch (error) {
94
+ if (error.code !== MISSING_FILE_CODE) {
95
+ this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: storePath });
96
+ try {
97
+ onReadError?.(error);
98
+ } catch {}
99
+ }
100
+ return emptyDocument();
101
+ }
102
+ }
103
+ /**
104
+ * Apply a mutation under the store lock.
105
+ *
106
+ * `mutate` receives the freshest on-disk document and returns either the next
107
+ * document to commit or `undefined` for a read-only action (list/get), which
108
+ * skips the write entirely so queries never bump `rev`.
109
+ */
110
+ async mutate(mutate) {
111
+ const release = await this.acquireLock();
112
+ const outcome = (() => {
113
+ try {
114
+ const current = this.read();
115
+ const mutation = mutate(current);
116
+ if (!mutation.document) return { result: {
117
+ document: current,
118
+ value: mutation.value
119
+ } };
120
+ const committed = this.write(mutation.document);
121
+ return {
122
+ result: {
123
+ document: committed,
124
+ value: mutation.value
125
+ },
126
+ notification: committed
127
+ };
128
+ } finally {
129
+ release();
130
+ }
131
+ })();
132
+ if (outcome.notification) this.notifyCommitted(outcome.notification);
133
+ return outcome.result;
134
+ }
135
+ notifyCommitted(committed) {
136
+ for (const listener of this.listeners) try {
137
+ listener(committed);
138
+ } catch (error) {
139
+ this.report?.error(TASK_EVENT.storeListenerFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });
140
+ }
141
+ }
142
+ write(document) {
143
+ const next = {
144
+ ...document,
145
+ version: 1,
146
+ rev: document.rev + 1
147
+ };
148
+ fs.mkdirSync(path.dirname(this.storePath), { recursive: true });
149
+ const temp = tempPathFor(this.storePath);
150
+ fs.writeFileSync(temp, `${JSON.stringify(next, void 0, 2)}\n`, UTF8_ENCODING);
151
+ fs.renameSync(temp, this.storePath);
152
+ this.cached = next;
153
+ return next;
154
+ }
155
+ async acquireLock() {
156
+ const lockPath = lockPathFor(this.storePath);
157
+ fs.mkdirSync(path.dirname(this.storePath), { recursive: true });
158
+ const deadline = Date.now() + this.lockTimeoutMs;
159
+ for (;;) try {
160
+ const handle = fs.openSync(lockPath, "wx");
161
+ fs.writeSync(handle, JSON.stringify({
162
+ pid: process.pid,
163
+ time: Date.now()
164
+ }));
165
+ fs.closeSync(handle);
166
+ return () => fs.rmSync(lockPath, { force: true });
167
+ } catch (error) {
168
+ if (error.code !== LOCK_EXISTS_CODE) throw error;
169
+ if (Date.now() >= deadline) {
170
+ this.report?.warn(TASK_EVENT.storeLockTimeout, /* @__PURE__ */ new Error(`Task store lock still held after ${this.lockTimeoutMs}ms; proceeding without it`), { [STORE_PATH_ATTRIBUTE]: this.storePath });
171
+ return () => {};
172
+ }
173
+ this.breakStaleLock(lockPath);
174
+ await sleep(LOCK_RETRY_BASE_MS + Math.random() * LOCK_RETRY_MAX_MS);
175
+ }
176
+ }
177
+ /** Remove a lock left behind by a dead process or one held implausibly long. */
178
+ breakStaleLock(lockPath) {
179
+ try {
180
+ const holder = JSON.parse(fs.readFileSync(lockPath, UTF8_ENCODING));
181
+ const expired = typeof holder.time === "number" && Date.now() - holder.time > LOCK_STALE_MS;
182
+ const dead = typeof holder.pid === "number" && !isProcessAlive(holder.pid);
183
+ if (!expired && !dead) return false;
184
+ fs.unlinkSync(lockPath);
185
+ return true;
186
+ } catch (error) {
187
+ if (error.code !== MISSING_FILE_CODE) this.report?.warn(TASK_EVENT.storeLockBreakFailed, error, { [STORE_PATH_ATTRIBUTE]: lockPath });
188
+ return false;
189
+ }
190
+ }
191
+ /**
192
+ * Listen for commits made through this store instance.
193
+ *
194
+ * Live cross-process updates use the owning session's direct event bus. This
195
+ * listener publishes local commits to that bus and never watches the filesystem.
196
+ */
197
+ onExternalChange(listener) {
198
+ this.listeners.add(listener);
199
+ return () => this.listeners.delete(listener);
200
+ }
201
+ dispose() {
202
+ this.listeners.clear();
203
+ }
204
+ };
205
+ //#endregion
206
+ export { TaskStore as t };
207
+
208
+ //# sourceMappingURL=taskStore-pAJ971Ml.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taskStore-pAJ971Ml.mjs","names":[],"sources":["../src/services/taskStore/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { emptyDocument, STORE_SCHEMA_VERSION, type Task, type TaskDocument } from '../../models/task';\nimport { TASK_EVENT, type TaskFailureReporter } from '../../types/telemetry';\nimport { canonicalizeTasks } from '../invariants';\nimport { lockPathFor, resolveStorePath, STORE_PATH_ENV, tempPathFor } from '../paths';\nimport { isProcessAlive } from '../processLiveness';\n\nconst LOCK_TIMEOUT_MS = 2000;\nconst LOCK_STALE_MS = 10_000;\nconst LOCK_RETRY_BASE_MS = 10;\nconst LOCK_RETRY_MAX_MS = 60;\nconst UTF8_ENCODING = 'utf8';\nconst MISSING_FILE_CODE = 'ENOENT';\nconst LOCK_EXISTS_CODE = 'EEXIST';\nconst STORE_PATH_ATTRIBUTE = 'store.path';\n\nexport interface TaskStoreOptions {\n cwd?: string;\n env?: Readonly<Record<string, string | undefined>>;\n storePath?: string;\n /** How long to wait for the advisory lock before proceeding lock-free. */\n lockTimeoutMs?: number;\n /** Where swallowed failures go, so silent degradation stays visible. */\n report?: TaskFailureReporter;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Coerce arbitrary parsed JSON into a valid document.\n *\n * A corrupt or truncated store must not take the session down: the worst\n * acceptable outcome is starting from an empty list, never a crash on startup.\n */\nfunction normalizeDocument(parsed: unknown): TaskDocument {\n if (!parsed || typeof parsed !== 'object') return emptyDocument();\n const candidate = parsed as Partial<TaskDocument>;\n if (!Array.isArray(candidate.tasks)) return emptyDocument();\n\n const tasks = canonicalizeTasks(\n candidate.tasks.filter(\n (task): task is Task => Boolean(task) && typeof task === 'object' && typeof (task as Task).id === 'number',\n ),\n );\n const maxId = tasks.reduce((max, task) => Math.max(max, task.id), 0);\n return {\n version: typeof candidate.version === 'number' ? candidate.version : STORE_SCHEMA_VERSION,\n rev: typeof candidate.rev === 'number' ? candidate.rev : 0,\n nextId: typeof candidate.nextId === 'number' && candidate.nextId > maxId ? candidate.nextId : maxId + 1,\n tasks,\n };\n}\n\n/**\n * File-backed task store shared by one root session and its delegated children.\n *\n * Durability model: the JSON file is the source of truth. Mutations are\n * read-modify-write under an advisory lock so concurrent delegated processes\n * cannot clobber each other, and writes land via temp-file rename so a\n * crash mid-write can never leave a partial document behind.\n */\nexport class TaskStore {\n storePath: string;\n\n private readonly cwd: string;\n private readonly env: Readonly<Record<string, string | undefined>>;\n private cached: TaskDocument = emptyDocument();\n private readonly listeners = new Set<(document: TaskDocument) => void>();\n private readonly lockTimeoutMs: number;\n private readonly report?: TaskFailureReporter;\n\n constructor(options: TaskStoreOptions = {}) {\n this.cwd = options.cwd ?? process.cwd();\n this.env = options.env ?? process.env;\n this.storePath = options.storePath ?? resolveStorePath(this.cwd, this.env);\n this.lockTimeoutMs = options.lockTimeoutMs ?? LOCK_TIMEOUT_MS;\n this.report = options.report;\n }\n\n /** Bind a default store to the current session tree before reading it. */\n configureSession(sessionKey: string): void {\n if (this.env[STORE_PATH_ENV]?.trim()) return;\n this.storePath = resolveStorePath(this.cwd, this.env, sessionKey);\n this.cached = emptyDocument();\n }\n\n /** Last document read from disk, without hitting the filesystem. */\n get snapshot(): TaskDocument {\n return this.cached;\n }\n\n read(): TaskDocument {\n try {\n const raw = fs.readFileSync(this.storePath, UTF8_ENCODING);\n this.cached = normalizeDocument(JSON.parse(raw));\n } catch (error) {\n // A missing file is the normal state before the first write. Anything\n // else means the task list just silently became empty, which is worth a\n // record: unreadable or corrupt JSON looks identical to \"no tasks yet\".\n if ((error as NodeJS.ErrnoException).code !== MISSING_FILE_CODE) {\n this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });\n }\n this.cached = emptyDocument();\n }\n return this.cached;\n }\n\n async readAsync(\n shouldApply: () => boolean = () => true,\n onReadError?: (error: unknown) => void,\n ): Promise<TaskDocument> {\n const storePath = this.storePath;\n const document = await this.readDocumentAsync(storePath, onReadError);\n if (!shouldApply()) return document;\n this.cached = document;\n return document;\n }\n\n private async readDocumentAsync(\n storePath: string = this.storePath,\n onReadError?: (error: unknown) => void,\n ): Promise<TaskDocument> {\n try {\n const raw = await fs.promises.readFile(storePath, UTF8_ENCODING);\n return normalizeDocument(JSON.parse(raw));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== MISSING_FILE_CODE) {\n this.report?.error(TASK_EVENT.storeReadFailed, error, { [STORE_PATH_ATTRIBUTE]: storePath });\n try {\n onReadError?.(error);\n } catch {\n // Diagnostic failures must not change fail-open reads.\n }\n }\n return emptyDocument();\n }\n }\n\n /**\n * Apply a mutation under the store lock.\n *\n * `mutate` receives the freshest on-disk document and returns either the next\n * document to commit or `undefined` for a read-only action (list/get), which\n * skips the write entirely so queries never bump `rev`.\n */\n async mutate<T>(\n mutate: (document: TaskDocument) => { document?: TaskDocument; value: T },\n ): Promise<{ document: TaskDocument; value: T }> {\n const release = await this.acquireLock();\n const outcome = (() => {\n try {\n const current = this.read();\n const mutation = mutate(current);\n if (!mutation.document) {\n return { result: { document: current, value: mutation.value } };\n }\n const committed = this.write(mutation.document);\n return {\n result: { document: committed, value: mutation.value },\n notification: committed,\n };\n } finally {\n release();\n }\n })();\n if (outcome.notification) {\n this.notifyCommitted(outcome.notification);\n }\n return outcome.result;\n }\n\n private notifyCommitted(committed: TaskDocument): void {\n for (const listener of this.listeners) {\n try {\n listener(committed);\n } catch (error) {\n this.report?.error(TASK_EVENT.storeListenerFailed, error, { [STORE_PATH_ATTRIBUTE]: this.storePath });\n }\n }\n }\n\n private write(document: TaskDocument): TaskDocument {\n const next: TaskDocument = { ...document, version: STORE_SCHEMA_VERSION, rev: document.rev + 1 };\n fs.mkdirSync(path.dirname(this.storePath), { recursive: true });\n const temp = tempPathFor(this.storePath);\n fs.writeFileSync(temp, `${JSON.stringify(next, undefined, 2)}\\n`, UTF8_ENCODING);\n fs.renameSync(temp, this.storePath);\n this.cached = next;\n return next;\n }\n\n private async acquireLock(): Promise<() => void> {\n const lockPath = lockPathFor(this.storePath);\n fs.mkdirSync(path.dirname(this.storePath), { recursive: true });\n const deadline = Date.now() + this.lockTimeoutMs;\n\n for (;;) {\n try {\n const handle = fs.openSync(lockPath, 'wx');\n fs.writeSync(handle, JSON.stringify({ pid: process.pid, time: Date.now() }));\n fs.closeSync(handle);\n return () => fs.rmSync(lockPath, { force: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== LOCK_EXISTS_CODE) throw error;\n // The deadline is checked before breaking a stale lock so a peer that\n // keeps recreating one cannot spin this loop without bound.\n if (Date.now() >= deadline) {\n // Proceeding lock-free beats stalling the agent: the rename is atomic,\n // so the worst case is a lost concurrent update, not a corrupt file.\n // Reported because a lost update here can strand a delegation.\n this.report?.warn(\n TASK_EVENT.storeLockTimeout,\n new Error(`Task store lock still held after ${this.lockTimeoutMs}ms; proceeding without it`),\n { [STORE_PATH_ATTRIBUTE]: this.storePath },\n );\n return () => {};\n }\n // Clearing a dead holder's lock still goes through the backoff. Yielding\n // on every iteration is what stops a peer that keeps recreating the\n // lock from turning this into a spin.\n this.breakStaleLock(lockPath);\n await sleep(LOCK_RETRY_BASE_MS + Math.random() * LOCK_RETRY_MAX_MS);\n }\n }\n }\n\n /** Remove a lock left behind by a dead process or one held implausibly long. */\n private breakStaleLock(lockPath: string): boolean {\n try {\n const holder = JSON.parse(fs.readFileSync(lockPath, UTF8_ENCODING)) as { pid?: number; time?: number };\n const expired = typeof holder.time === 'number' && Date.now() - holder.time > LOCK_STALE_MS;\n const dead = typeof holder.pid === 'number' && !isProcessAlive(holder.pid);\n if (!expired && !dead) return false;\n fs.unlinkSync(lockPath);\n return true;\n } catch (error) {\n // Losing the race to another breaker is normal; a persistent failure here\n // shows up as the lock timeout above, so this stays a warning.\n if ((error as NodeJS.ErrnoException).code !== MISSING_FILE_CODE) {\n this.report?.warn(TASK_EVENT.storeLockBreakFailed, error, { [STORE_PATH_ATTRIBUTE]: lockPath });\n }\n return false;\n }\n }\n\n /**\n * Listen for commits made through this store instance.\n *\n * Live cross-process updates use the owning session's direct event bus. This\n * listener publishes local commits to that bus and never watches the filesystem.\n */\n onExternalChange(listener: (document: TaskDocument) => void): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n dispose(): void {\n this.listeners.clear();\n }\n}\n"],"mappings":";;;;;;;;AASA,MAAM,kBAAkB;AACxB,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AACtB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,uBAAuB;AAY7B,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AC3F,GAAG,uBAAuB,KAAK,UAAU,CAC3C;IACA,aAAa,CAAC;GAChB;GAIA,KAAK,eAAe,QAAQ;GAC5B,MAAM,MAAM,qBAAqB,KAAK,OAAO,IAAI,iBAAiB;EACpE;CAEJ;;CAGA,eAAuB,UAA2B;EAChD,IAAI;GACF,MAAM,SAAS,KAAK,MAAM,GAAG,aAAa,UAAU,aAAa,CAAC;GAClE,MAAM,UAAU,OAAO,OAAO,SAAS,YAAY,KAAK,IAAI,IAAI,OAAO,OAAO;GAC9E,MAAM,OAAO,OAAO,OAAO,QAAQ,YAAY,CAAC,eAAe,OAAO,GAAG;GACzE,IAAI,CAAC,WAAW,CAAC,MAAM,OAAO;GAC9B,GAAG,WAAW,QAAQ;GACtB,OAAO;EACT,SAAS,OAAO;GAGd,IAAK,MAAgC,SAAS,mBAC5C,KAAK,QAAQ,KAAK,WAAW,sBAAsB,OAAO,GAAG,uBAAuB,SAAS,CAAC;GAEhG,OAAO;EACT;CACF;;;;;;;CAQA,iBAAiB,UAAwD;EACvE,KAAK,UAAU,IAAI,QAAQ;EAC3B,aAAa,KAAK,UAAU,OAAO,QAAQ;CAC7C;CAEA,UAAgB;EACd,KAAK,UAAU,MAAM;CACvB;AACF"}
@@ -0,0 +1,30 @@
1
+ //#region src/types/telemetry.ts
2
+ const TASK_EVENT = {
3
+ notificationFailed: "doom_task.notification_failed",
4
+ storeReadFailed: "doom_task.store_read_failed",
5
+ storeLockTimeout: "doom_task.store_lock_timeout",
6
+ storeLockBreakFailed: "doom_task.store_lock_break_failed",
7
+ storeWatchFailed: "doom_task.store_watch_failed",
8
+ storeListenerFailed: "doom_task.store_listener_failed",
9
+ storeSweepFailed: "doom_task.store_sweep_failed",
10
+ sessionStartFailed: "doom_task.session_start_failed",
11
+ sessionStartDegraded: "doom_task.session_start_degraded",
12
+ toolFailed: "doom_task.tool_failed",
13
+ delegationRequestFailed: "doom_task.delegation_request_failed",
14
+ delegationStartFailed: "doom_task.delegation_start_failed",
15
+ delegationResponseFailed: "doom_task.delegation_response_failed",
16
+ delegationSettleFailed: "doom_task.delegation_settle_failed",
17
+ delegationTimedOut: "doom_task.delegation_timed_out",
18
+ delegationOrphaned: "doom_task.delegation_orphaned",
19
+ delegationAssigned: "doom_task.delegation_assigned",
20
+ delegationCompleted: "doom_task.delegation_completed"
21
+ };
22
+ //#endregion
23
+ Object.defineProperty(exports, "TASK_EVENT", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return TASK_EVENT;
27
+ }
28
+ });
29
+
30
+ //# sourceMappingURL=telemetry-Ca0I3Tqo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-Ca0I3Tqo.cjs","names":[],"sources":["../src/types/telemetry.ts"],"sourcesContent":["export const TASK_EVENT = {\n notificationFailed: 'doom_task.notification_failed',\n storeReadFailed: 'doom_task.store_read_failed',\n storeLockTimeout: 'doom_task.store_lock_timeout',\n storeLockBreakFailed: 'doom_task.store_lock_break_failed',\n storeWatchFailed: 'doom_task.store_watch_failed',\n storeListenerFailed: 'doom_task.store_listener_failed',\n storeSweepFailed: 'doom_task.store_sweep_failed',\n sessionStartFailed: 'doom_task.session_start_failed',\n sessionStartDegraded: 'doom_task.session_start_degraded',\n toolFailed: 'doom_task.tool_failed',\n delegationRequestFailed: 'doom_task.delegation_request_failed',\n delegationStartFailed: 'doom_task.delegation_start_failed',\n delegationResponseFailed: 'doom_task.delegation_response_failed',\n delegationSettleFailed: 'doom_task.delegation_settle_failed',\n delegationTimedOut: 'doom_task.delegation_timed_out',\n delegationOrphaned: 'doom_task.delegation_orphaned',\n // Info-level lifecycle events. These are the measurement pair: the shape of\n // the brief that went out, and the cost of the run it produced.\n delegationAssigned: 'doom_task.delegation_assigned',\n delegationCompleted: 'doom_task.delegation_completed',\n} as const;\n\nexport type TaskEventName = (typeof TASK_EVENT)[keyof typeof TASK_EVENT];\nexport type TaskErrorAttributes = Record<string, string | number | boolean>;\nexport type TaskErrorSink = (event: TaskEventName, error: unknown, attributes?: TaskErrorAttributes) => void;\nexport type TaskEventSink = (event: TaskEventName, attributes?: TaskErrorAttributes) => void;\n\n/** Host-neutral telemetry port consumed by Task services and store adapters. */\nexport interface TaskFailureReporter {\n error: TaskErrorSink;\n warn: TaskErrorSink;\n /** Info-level event sink. Required so an unwired reporter fails to compile. */\n event: TaskEventSink;\n}\n"],"mappings":";AAAA,MAAa,aAAa;CACxB,oBAAoB;CACpB,iBAAiB;CACjB,kBAAkB;CAClB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,kBAAkB;CAClB,oBAAoB;CACpB,sBAAsB;CACtB,YAAY;CACZ,yBAAyB;CACzB,uBAAuB;CACvB,0BAA0B;CAC1B,wBAAwB;CACxB,oBAAoB;CACpB,oBAAoB;CAGpB,oBAAoB;CACpB,qBAAqB;AACvB"}
@@ -0,0 +1,25 @@
1
+ //#region src/types/telemetry.ts
2
+ const TASK_EVENT = {
3
+ notificationFailed: "doom_task.notification_failed",
4
+ storeReadFailed: "doom_task.store_read_failed",
5
+ storeLockTimeout: "doom_task.store_lock_timeout",
6
+ storeLockBreakFailed: "doom_task.store_lock_break_failed",
7
+ storeWatchFailed: "doom_task.store_watch_failed",
8
+ storeListenerFailed: "doom_task.store_listener_failed",
9
+ storeSweepFailed: "doom_task.store_sweep_failed",
10
+ sessionStartFailed: "doom_task.session_start_failed",
11
+ sessionStartDegraded: "doom_task.session_start_degraded",
12
+ toolFailed: "doom_task.tool_failed",
13
+ delegationRequestFailed: "doom_task.delegation_request_failed",
14
+ delegationStartFailed: "doom_task.delegation_start_failed",
15
+ delegationResponseFailed: "doom_task.delegation_response_failed",
16
+ delegationSettleFailed: "doom_task.delegation_settle_failed",
17
+ delegationTimedOut: "doom_task.delegation_timed_out",
18
+ delegationOrphaned: "doom_task.delegation_orphaned",
19
+ delegationAssigned: "doom_task.delegation_assigned",
20
+ delegationCompleted: "doom_task.delegation_completed"
21
+ };
22
+ //#endregion
23
+ export { TASK_EVENT as t };
24
+
25
+ //# sourceMappingURL=telemetry-DyS44zAD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-DyS44zAD.mjs","names":[],"sources":["../src/types/telemetry.ts"],"sourcesContent":["export const TASK_EVENT = {\n notificationFailed: 'doom_task.notification_failed',\n storeReadFailed: 'doom_task.store_read_failed',\n storeLockTimeout: 'doom_task.store_lock_timeout',\n storeLockBreakFailed: 'doom_task.store_lock_break_failed',\n storeWatchFailed: 'doom_task.store_watch_failed',\n storeListenerFailed: 'doom_task.store_listener_failed',\n storeSweepFailed: 'doom_task.store_sweep_failed',\n sessionStartFailed: 'doom_task.session_start_failed',\n sessionStartDegraded: 'doom_task.session_start_degraded',\n toolFailed: 'doom_task.tool_failed',\n delegationRequestFailed: 'doom_task.delegation_request_failed',\n delegationStartFailed: 'doom_task.delegation_start_failed',\n delegationResponseFailed: 'doom_task.delegation_response_failed',\n delegationSettleFailed: 'doom_task.delegation_settle_failed',\n delegationTimedOut: 'doom_task.delegation_timed_out',\n delegationOrphaned: 'doom_task.delegation_orphaned',\n // Info-level lifecycle events. These are the measurement pair: the shape of\n // the brief that went out, and the cost of the run it produced.\n delegationAssigned: 'doom_task.delegation_assigned',\n delegationCompleted: 'doom_task.delegation_completed',\n} as const;\n\nexport type TaskEventName = (typeof TASK_EVENT)[keyof typeof TASK_EVENT];\nexport type TaskErrorAttributes = Record<string, string | number | boolean>;\nexport type TaskErrorSink = (event: TaskEventName, error: unknown, attributes?: TaskErrorAttributes) => void;\nexport type TaskEventSink = (event: TaskEventName, attributes?: TaskErrorAttributes) => void;\n\n/** Host-neutral telemetry port consumed by Task services and store adapters. */\nexport interface TaskFailureReporter {\n error: TaskErrorSink;\n warn: TaskErrorSink;\n /** Info-level event sink. Required so an unwired reporter fails to compile. */\n event: TaskEventSink;\n}\n"],"mappings":";AAAA,MAAa,aAAa;CACxB,oBAAoB;CACpB,iBAAiB;CACjB,kBAAkB;CAClB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,kBAAkB;CAClB,oBAAoB;CACpB,sBAAsB;CACtB,YAAY;CACZ,yBAAyB;CACzB,uBAAuB;CACvB,0BAA0B;CAC1B,wBAAwB;CACxB,oBAAoB;CACpB,oBAAoB;CAGpB,oBAAoB;CACpB,qBAAqB;AACvB"}
@@ -0,0 +1,35 @@
1
+ //#region src/types/telemetry.d.ts
2
+ declare const TASK_EVENT: {
3
+ readonly notificationFailed: 'doom_task.notification_failed';
4
+ readonly storeReadFailed: 'doom_task.store_read_failed';
5
+ readonly storeLockTimeout: 'doom_task.store_lock_timeout';
6
+ readonly storeLockBreakFailed: 'doom_task.store_lock_break_failed';
7
+ readonly storeWatchFailed: 'doom_task.store_watch_failed';
8
+ readonly storeListenerFailed: 'doom_task.store_listener_failed';
9
+ readonly storeSweepFailed: 'doom_task.store_sweep_failed';
10
+ readonly sessionStartFailed: 'doom_task.session_start_failed';
11
+ readonly sessionStartDegraded: 'doom_task.session_start_degraded';
12
+ readonly toolFailed: 'doom_task.tool_failed';
13
+ readonly delegationRequestFailed: 'doom_task.delegation_request_failed';
14
+ readonly delegationStartFailed: 'doom_task.delegation_start_failed';
15
+ readonly delegationResponseFailed: 'doom_task.delegation_response_failed';
16
+ readonly delegationSettleFailed: 'doom_task.delegation_settle_failed';
17
+ readonly delegationTimedOut: 'doom_task.delegation_timed_out';
18
+ readonly delegationOrphaned: 'doom_task.delegation_orphaned';
19
+ readonly delegationAssigned: 'doom_task.delegation_assigned';
20
+ readonly delegationCompleted: 'doom_task.delegation_completed';
21
+ };
22
+ type TaskEventName = (typeof TASK_EVENT)[keyof typeof TASK_EVENT];
23
+ type TaskErrorAttributes = Record<string, string | number | boolean>;
24
+ type TaskErrorSink = (event: TaskEventName, error: unknown, attributes?: TaskErrorAttributes) => void;
25
+ type TaskEventSink = (event: TaskEventName, attributes?: TaskErrorAttributes) => void;
26
+ /** Host-neutral telemetry port consumed by Task services and store adapters. */
27
+ interface TaskFailureReporter {
28
+ error: TaskErrorSink;
29
+ warn: TaskErrorSink;
30
+ /** Info-level event sink. Required so an unwired reporter fails to compile. */
31
+ event: TaskEventSink;
32
+ }
33
+ //#endregion
34
+ export { TaskEventSink as a, TaskEventName as i, TaskErrorAttributes as n, TaskFailureReporter as o, TaskErrorSink as r, TASK_EVENT as t };
35
+ //# sourceMappingURL=telemetry-FMGRovb4.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-FMGRovb4.d.mts","names":[],"sources":["../src/types/telemetry.ts"],"mappings":";cAAa;WACX;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WAGA;WACA;;KAGU,wBAAwB,yBAAyB;KACjD,sBAAsB;KACtB,iBAAiB,OAAO,eAAe,gBAAgB,aAAa;KACpE,iBAAiB,OAAO,eAAe,aAAa;;UAG/C;EACf,OAAO;EACP,MAAM;;EAEN,OAAO"}
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/constants/promptGuidelines.ts
3
+ /**
4
+ * Cross-call behaviour the schema cannot express.
5
+ *
6
+ * Every rule lives in exactly one surface. Argument-site mechanics belong to
7
+ * the parameter descriptions in `schemas/task.ts`, the use/do-not-use policy
8
+ * and session scoping belong to the tool description, and general delegation
9
+ * judgement belongs to the Team orchestrator prompt. What is left here is what
10
+ * none of those three can carry: how calls should be sequenced across a turn.
11
+ */
12
+ const DEFAULT_PROMPT_GUIDELINES = [
13
+ "Batch the whole plan in one upsert: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research the store\"},{\"subject\":\"Write the reducer\"}]}. Report progress one call at a time: mark a task in_progress before you start it and completed the moment it lands, never batched at the end of a turn. Keep one task in_progress for your own work; delegated tasks run in parallel and do not count.",
14
+ "Never mark a task completed while tests fail or the work is partial. Use failed, or keep it in_progress and add a task for the blocker in the same upsert.",
15
+ "When every non-deleted task is completed, review the list once and call {\"action\":\"clear\"}.",
16
+ "Status flow: pending, in_progress, completed. failed is recoverable, deleted is a tombstone. Pass activeForm (e.g. 'writing tests') when marking in_progress.",
17
+ "upsert applies each entry independently: passing entries commit and failures are reported by array index. Resend only the corrected failures, because resending an applied entry with no id creates a duplicate task.",
18
+ "Apply the session delegation criteria before choosing what to delegate, then call subagent {\"action\":\"agents\"} and use an exact discovered name. Prefer a general-purpose write-capable agent such as delegate or worker when no specialist fits, and use a focused inlineAgent only for read-only work.",
19
+ "Assign through assignments[] even for a single task: {\"action\":\"assign\",\"assignments\":[{\"id\":1,\"agent\":\"researcher\"}]}. Put independent ready tasks in one batch rather than repeated calls or multi_tool, and do not start a direct subagent run for work already on the task list. Successful entries keep running when another entry fails, so retry only the failures.",
20
+ "Fill relevantFiles only with files you actually read or located, and priorFindings only with verified facts in a few lines, not directives. A guessed path costs more than an omitted one.",
21
+ "Subject stays short and imperative. description is the durable brief handed to the subagent, extended at assign time by instructions, relevantFiles and priorFindings, so do not repeat one in the other.",
22
+ "When a delegated task completes and unblocks another, reconsider it promptly. If a child asks for a decision or an assignment fails to start, respond, rescope or retry instead of leaving it pending. Doom Task records delegated lifecycle and results on the task itself."
23
+ ];
24
+ //#endregion
25
+ exports.DEFAULT_PROMPT_GUIDELINES = DEFAULT_PROMPT_GUIDELINES;
26
+
27
+ //# sourceMappingURL=toolPromptGuidelines.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolPromptGuidelines.cjs","names":[],"sources":["../src/constants/promptGuidelines.ts"],"sourcesContent":["/**\n * Cross-call behaviour the schema cannot express.\n *\n * Every rule lives in exactly one surface. Argument-site mechanics belong to\n * the parameter descriptions in `schemas/task.ts`, the use/do-not-use policy\n * and session scoping belong to the tool description, and general delegation\n * judgement belongs to the Team orchestrator prompt. What is left here is what\n * none of those three can carry: how calls should be sequenced across a turn.\n */\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n 'Batch the whole plan in one upsert: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research the store\"},{\"subject\":\"Write the reducer\"}]}. Report progress one call at a time: mark a task in_progress before you start it and completed the moment it lands, never batched at the end of a turn. Keep one task in_progress for your own work; delegated tasks run in parallel and do not count.',\n 'Never mark a task completed while tests fail or the work is partial. Use failed, or keep it in_progress and add a task for the blocker in the same upsert.',\n 'When every non-deleted task is completed, review the list once and call {\"action\":\"clear\"}.',\n \"Status flow: pending, in_progress, completed. failed is recoverable, deleted is a tombstone. Pass activeForm (e.g. 'writing tests') when marking in_progress.\",\n 'upsert applies each entry independently: passing entries commit and failures are reported by array index. Resend only the corrected failures, because resending an applied entry with no id creates a duplicate task.',\n 'Apply the session delegation criteria before choosing what to delegate, then call subagent {\"action\":\"agents\"} and use an exact discovered name. Prefer a general-purpose write-capable agent such as delegate or worker when no specialist fits, and use a focused inlineAgent only for read-only work.',\n 'Assign through assignments[] even for a single task: {\"action\":\"assign\",\"assignments\":[{\"id\":1,\"agent\":\"researcher\"}]}. Put independent ready tasks in one batch rather than repeated calls or multi_tool, and do not start a direct subagent run for work already on the task list. Successful entries keep running when another entry fails, so retry only the failures.',\n 'Fill relevantFiles only with files you actually read or located, and priorFindings only with verified facts in a few lines, not directives. A guessed path costs more than an omitted one.',\n 'Subject stays short and imperative. description is the durable brief handed to the subagent, extended at assign time by instructions, relevantFiles and priorFindings, so do not repeat one in the other.',\n 'When a delegated task completes and unblocks another, reconsider it promptly. If a child asks for a decision or an assignment fails to start, respond, rescope or retry instead of leaving it pending. Doom Task records delegated lifecycle and results on the task itself.',\n];\n"],"mappings":";;;;;;;;;;;AASA,MAAa,4BAAsC;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,13 @@
1
+ //#region src/constants/promptGuidelines.d.ts
2
+ /**
3
+ * Cross-call behaviour the schema cannot express.
4
+ *
5
+ * Every rule lives in exactly one surface. Argument-site mechanics belong to
6
+ * the parameter descriptions in `schemas/task.ts`, the use/do-not-use policy
7
+ * and session scoping belong to the tool description, and general delegation
8
+ * judgement belongs to the Team orchestrator prompt. What is left here is what
9
+ * none of those three can carry: how calls should be sequenced across a turn.
10
+ */
11
+ export declare const DEFAULT_PROMPT_GUIDELINES: string[];
12
+ //#endregion
13
+ //# sourceMappingURL=toolPromptGuidelines.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolPromptGuidelines.d.mts","names":[],"sources":["../src/constants/promptGuidelines.ts"],"mappings":";;;;;;;;;;qBASa"}
@@ -0,0 +1,26 @@
1
+ //#region src/constants/promptGuidelines.ts
2
+ /**
3
+ * Cross-call behaviour the schema cannot express.
4
+ *
5
+ * Every rule lives in exactly one surface. Argument-site mechanics belong to
6
+ * the parameter descriptions in `schemas/task.ts`, the use/do-not-use policy
7
+ * and session scoping belong to the tool description, and general delegation
8
+ * judgement belongs to the Team orchestrator prompt. What is left here is what
9
+ * none of those three can carry: how calls should be sequenced across a turn.
10
+ */
11
+ const DEFAULT_PROMPT_GUIDELINES = [
12
+ "Batch the whole plan in one upsert: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research the store\"},{\"subject\":\"Write the reducer\"}]}. Report progress one call at a time: mark a task in_progress before you start it and completed the moment it lands, never batched at the end of a turn. Keep one task in_progress for your own work; delegated tasks run in parallel and do not count.",
13
+ "Never mark a task completed while tests fail or the work is partial. Use failed, or keep it in_progress and add a task for the blocker in the same upsert.",
14
+ "When every non-deleted task is completed, review the list once and call {\"action\":\"clear\"}.",
15
+ "Status flow: pending, in_progress, completed. failed is recoverable, deleted is a tombstone. Pass activeForm (e.g. 'writing tests') when marking in_progress.",
16
+ "upsert applies each entry independently: passing entries commit and failures are reported by array index. Resend only the corrected failures, because resending an applied entry with no id creates a duplicate task.",
17
+ "Apply the session delegation criteria before choosing what to delegate, then call subagent {\"action\":\"agents\"} and use an exact discovered name. Prefer a general-purpose write-capable agent such as delegate or worker when no specialist fits, and use a focused inlineAgent only for read-only work.",
18
+ "Assign through assignments[] even for a single task: {\"action\":\"assign\",\"assignments\":[{\"id\":1,\"agent\":\"researcher\"}]}. Put independent ready tasks in one batch rather than repeated calls or multi_tool, and do not start a direct subagent run for work already on the task list. Successful entries keep running when another entry fails, so retry only the failures.",
19
+ "Fill relevantFiles only with files you actually read or located, and priorFindings only with verified facts in a few lines, not directives. A guessed path costs more than an omitted one.",
20
+ "Subject stays short and imperative. description is the durable brief handed to the subagent, extended at assign time by instructions, relevantFiles and priorFindings, so do not repeat one in the other.",
21
+ "When a delegated task completes and unblocks another, reconsider it promptly. If a child asks for a decision or an assignment fails to start, respond, rescope or retry instead of leaving it pending. Doom Task records delegated lifecycle and results on the task itself."
22
+ ];
23
+ //#endregion
24
+ export { DEFAULT_PROMPT_GUIDELINES };
25
+
26
+ //# sourceMappingURL=toolPromptGuidelines.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolPromptGuidelines.mjs","names":[],"sources":["../src/constants/promptGuidelines.ts"],"sourcesContent":["/**\n * Cross-call behaviour the schema cannot express.\n *\n * Every rule lives in exactly one surface. Argument-site mechanics belong to\n * the parameter descriptions in `schemas/task.ts`, the use/do-not-use policy\n * and session scoping belong to the tool description, and general delegation\n * judgement belongs to the Team orchestrator prompt. What is left here is what\n * none of those three can carry: how calls should be sequenced across a turn.\n */\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n 'Batch the whole plan in one upsert: {\"action\":\"upsert\",\"tasks\":[{\"subject\":\"Research the store\"},{\"subject\":\"Write the reducer\"}]}. Report progress one call at a time: mark a task in_progress before you start it and completed the moment it lands, never batched at the end of a turn. Keep one task in_progress for your own work; delegated tasks run in parallel and do not count.',\n 'Never mark a task completed while tests fail or the work is partial. Use failed, or keep it in_progress and add a task for the blocker in the same upsert.',\n 'When every non-deleted task is completed, review the list once and call {\"action\":\"clear\"}.',\n \"Status flow: pending, in_progress, completed. failed is recoverable, deleted is a tombstone. Pass activeForm (e.g. 'writing tests') when marking in_progress.\",\n 'upsert applies each entry independently: passing entries commit and failures are reported by array index. Resend only the corrected failures, because resending an applied entry with no id creates a duplicate task.',\n 'Apply the session delegation criteria before choosing what to delegate, then call subagent {\"action\":\"agents\"} and use an exact discovered name. Prefer a general-purpose write-capable agent such as delegate or worker when no specialist fits, and use a focused inlineAgent only for read-only work.',\n 'Assign through assignments[] even for a single task: {\"action\":\"assign\",\"assignments\":[{\"id\":1,\"agent\":\"researcher\"}]}. Put independent ready tasks in one batch rather than repeated calls or multi_tool, and do not start a direct subagent run for work already on the task list. Successful entries keep running when another entry fails, so retry only the failures.',\n 'Fill relevantFiles only with files you actually read or located, and priorFindings only with verified facts in a few lines, not directives. A guessed path costs more than an omitted one.',\n 'Subject stays short and imperative. description is the durable brief handed to the subagent, extended at assign time by instructions, relevantFiles and priorFindings, so do not repeat one in the other.',\n 'When a delegated task completes and unblocks another, reconsider it promptly. If a child asks for a decision or an assignment fails to start, respond, rescope or retry instead of leaving it pending. Doom Task records delegated lifecycle and results on the task itself.',\n];\n"],"mappings":";;;;;;;;;;AASA,MAAa,4BAAsC;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_taskResult = require("./taskResult-D2G7b4w-.cjs");
3
+ exports.MSG_ALL_COMPLETE_CLEAR = require_taskResult.MSG_ALL_COMPLETE_CLEAR;
4
+ exports.MSG_ASSIGN_PARTIAL = require_taskResult.MSG_ASSIGN_PARTIAL;
5
+ exports.MSG_UPSERT_NONE_APPLIED = require_taskResult.MSG_UPSERT_NONE_APPLIED;
6
+ exports.MSG_UPSERT_PARTIAL = require_taskResult.MSG_UPSERT_PARTIAL;
7
+ exports.buildAssignmentResult = require_taskResult.buildAssignmentResult;
8
+ exports.buildTextResult = require_taskResult.buildTextResult;
9
+ exports.buildToolResult = require_taskResult.buildToolResult;
10
+ exports.formatAssignmentResults = require_taskResult.formatAssignmentResults;
11
+ exports.formatContent = require_taskResult.formatContent;
12
+ exports.formatUpsertFailureText = require_taskResult.formatUpsertFailureText;
@@ -0,0 +1,2 @@
1
+ import { a as MSG_UPSERT_PARTIAL, c as buildTextResult, d as formatContent, f as formatUpsertFailureText, i as MSG_UPSERT_NONE_APPLIED, l as buildToolResult, n as MSG_ALL_COMPLETE_CLEAR, o as ToolResult, r as MSG_ASSIGN_PARTIAL, s as buildAssignmentResult, t as AssignmentItemResult, u as formatAssignmentResults } from "./index-B1JPJdpZ.mjs";
2
+ export { AssignmentItemResult, MSG_ALL_COMPLETE_CLEAR, MSG_ASSIGN_PARTIAL, MSG_UPSERT_NONE_APPLIED, MSG_UPSERT_PARTIAL, ToolResult, buildAssignmentResult, buildTextResult, buildToolResult, formatAssignmentResults, formatContent, formatUpsertFailureText };
@@ -0,0 +1,2 @@
1
+ import { a as buildAssignmentResult, c as formatAssignmentResults, i as MSG_UPSERT_PARTIAL, l as formatContent, n as MSG_ASSIGN_PARTIAL, o as buildTextResult, r as MSG_UPSERT_NONE_APPLIED, s as buildToolResult, t as MSG_ALL_COMPLETE_CLEAR, u as formatUpsertFailureText } from "./taskResult-edBAAKSH.mjs";
2
+ export { MSG_ALL_COMPLETE_CLEAR, MSG_ASSIGN_PARTIAL, MSG_UPSERT_NONE_APPLIED, MSG_UPSERT_PARTIAL, buildAssignmentResult, buildTextResult, buildToolResult, formatAssignmentResults, formatContent, formatUpsertFailureText };
@@ -0,0 +1,18 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_task = require("./task-UvW877Ez.cjs");
3
+ exports.COMMAND_NAME = require_task.COMMAND_NAME;
4
+ exports.ERR_REQUIRES_INTERACTIVE = require_task.ERR_REQUIRES_INTERACTIVE;
5
+ exports.MSG_NO_TASKS = require_task.MSG_NO_TASKS;
6
+ exports.MSG_UPSERT_FIELD_MISPLACED = require_task.MSG_UPSERT_FIELD_MISPLACED;
7
+ exports.REMOTE_TASK_ACTIONS = require_task.REMOTE_TASK_ACTIONS;
8
+ exports.RemoteTaskParamsSchema = require_task.RemoteTaskParamsSchema;
9
+ exports.TASK_ACTIONS = require_task.TASK_ACTIONS;
10
+ exports.TASK_ACTION_FIELDS = require_task.TASK_ACTION_FIELDS;
11
+ exports.TASK_CONTEXTS = require_task.TASK_CONTEXTS;
12
+ exports.TASK_STATUSES = require_task.TASK_STATUSES;
13
+ exports.TOOL_LABEL = require_task.TOOL_LABEL;
14
+ exports.TOOL_NAME = require_task.TOOL_NAME;
15
+ exports.TaskAssignmentSchema = require_task.TaskAssignmentSchema;
16
+ exports.TaskItemSchema = require_task.TaskItemSchema;
17
+ exports.TaskParamsSchema = require_task.TaskParamsSchema;
18
+ exports.taskActionAcceptsField = require_task.taskActionAcceptsField;
@@ -0,0 +1,2 @@
1
+ import { _ as TaskParamsSchema, a as RemoteTaskParamsSchema, c as TASK_CONTEXTS, d as TOOL_NAME, f as TaskAssignmentParams, g as TaskParams, h as TaskItemSchema, i as REMOTE_TASK_ACTIONS, l as TASK_STATUSES, m as TaskItemParams, n as MSG_NO_TASKS, o as TASK_ACTIONS, p as TaskAssignmentSchema, r as MSG_UPSERT_FIELD_MISPLACED, s as TASK_ACTION_FIELDS, t as ERR_REQUIRES_INTERACTIVE, u as TOOL_LABEL, v as taskActionAcceptsField, y as COMMAND_NAME } from "./task-Dhta7JyA.mjs";
2
+ export { COMMAND_NAME, ERR_REQUIRES_INTERACTIVE, MSG_NO_TASKS, MSG_UPSERT_FIELD_MISPLACED, REMOTE_TASK_ACTIONS, RemoteTaskParamsSchema, TASK_ACTIONS, TASK_ACTION_FIELDS, TASK_CONTEXTS, TASK_STATUSES, TOOL_LABEL, TOOL_NAME, TaskAssignmentParams, TaskAssignmentSchema, TaskItemParams, TaskItemSchema, TaskParams, TaskParamsSchema, taskActionAcceptsField };
@@ -0,0 +1,2 @@
1
+ import { a as RemoteTaskParamsSchema, c as TASK_CONTEXTS, d as TOOL_NAME, f as TaskAssignmentSchema, g as COMMAND_NAME, h as taskActionAcceptsField, i as REMOTE_TASK_ACTIONS, l as TASK_STATUSES, m as TaskParamsSchema, n as MSG_NO_TASKS, o as TASK_ACTIONS, p as TaskItemSchema, r as MSG_UPSERT_FIELD_MISPLACED, s as TASK_ACTION_FIELDS, t as ERR_REQUIRES_INTERACTIVE, u as TOOL_LABEL } from "./task-DO0TwZ0z.mjs";
2
+ export { COMMAND_NAME, ERR_REQUIRES_INTERACTIVE, MSG_NO_TASKS, MSG_UPSERT_FIELD_MISPLACED, REMOTE_TASK_ACTIONS, RemoteTaskParamsSchema, TASK_ACTIONS, TASK_ACTION_FIELDS, TASK_CONTEXTS, TASK_STATUSES, TOOL_LABEL, TOOL_NAME, TaskAssignmentSchema, TaskItemSchema, TaskParamsSchema, taskActionAcceptsField };