@chinhae/atw-core 0.1.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 (220) hide show
  1. package/COPYRIGHT +14 -0
  2. package/LICENSE +77 -0
  3. package/README.md +36 -0
  4. package/dist/channel/api/assert.d.ts +3 -0
  5. package/dist/channel/api/assert.d.ts.map +1 -0
  6. package/dist/channel/api/assert.js +11 -0
  7. package/dist/channel/api/assert.js.map +1 -0
  8. package/dist/channel/api/context.d.ts +21 -0
  9. package/dist/channel/api/context.d.ts.map +1 -0
  10. package/dist/channel/api/context.js +99 -0
  11. package/dist/channel/api/context.js.map +1 -0
  12. package/dist/channel/api/create.d.ts +9 -0
  13. package/dist/channel/api/create.d.ts.map +1 -0
  14. package/dist/channel/api/create.js +104 -0
  15. package/dist/channel/api/create.js.map +1 -0
  16. package/dist/channel/api/inbox.d.ts +51 -0
  17. package/dist/channel/api/inbox.d.ts.map +1 -0
  18. package/dist/channel/api/inbox.js +176 -0
  19. package/dist/channel/api/inbox.js.map +1 -0
  20. package/dist/channel/api/interrupt.d.ts +31 -0
  21. package/dist/channel/api/interrupt.d.ts.map +1 -0
  22. package/dist/channel/api/interrupt.js +102 -0
  23. package/dist/channel/api/interrupt.js.map +1 -0
  24. package/dist/channel/api/post-thread.d.ts +14 -0
  25. package/dist/channel/api/post-thread.d.ts.map +1 -0
  26. package/dist/channel/api/post-thread.js +109 -0
  27. package/dist/channel/api/post-thread.js.map +1 -0
  28. package/dist/channel/api/read.d.ts +17 -0
  29. package/dist/channel/api/read.d.ts.map +1 -0
  30. package/dist/channel/api/read.js +44 -0
  31. package/dist/channel/api/read.js.map +1 -0
  32. package/dist/channel/api/resolve.d.ts +21 -0
  33. package/dist/channel/api/resolve.d.ts.map +1 -0
  34. package/dist/channel/api/resolve.js +28 -0
  35. package/dist/channel/api/resolve.js.map +1 -0
  36. package/dist/channel/api/runtime.d.ts +70 -0
  37. package/dist/channel/api/runtime.d.ts.map +1 -0
  38. package/dist/channel/api/runtime.js +11 -0
  39. package/dist/channel/api/runtime.js.map +1 -0
  40. package/dist/channel/api/send.d.ts +4 -0
  41. package/dist/channel/api/send.d.ts.map +1 -0
  42. package/dist/channel/api/send.js +52 -0
  43. package/dist/channel/api/send.js.map +1 -0
  44. package/dist/channel/api/spawn.d.ts +13 -0
  45. package/dist/channel/api/spawn.d.ts.map +1 -0
  46. package/dist/channel/api/spawn.js +54 -0
  47. package/dist/channel/api/spawn.js.map +1 -0
  48. package/dist/channel/api/title.d.ts +5 -0
  49. package/dist/channel/api/title.d.ts.map +1 -0
  50. package/dist/channel/api/title.js +40 -0
  51. package/dist/channel/api/title.js.map +1 -0
  52. package/dist/channel/api/types.d.ts +65 -0
  53. package/dist/channel/api/types.d.ts.map +1 -0
  54. package/dist/channel/api/types.js +2 -0
  55. package/dist/channel/api/types.js.map +1 -0
  56. package/dist/channel/api/watch-channels.d.ts +40 -0
  57. package/dist/channel/api/watch-channels.d.ts.map +1 -0
  58. package/dist/channel/api/watch-channels.js +143 -0
  59. package/dist/channel/api/watch-channels.js.map +1 -0
  60. package/dist/channel/api/watch.d.ts +11 -0
  61. package/dist/channel/api/watch.d.ts.map +1 -0
  62. package/dist/channel/api/watch.js +17 -0
  63. package/dist/channel/api/watch.js.map +1 -0
  64. package/dist/channel/api/workers.d.ts +69 -0
  65. package/dist/channel/api/workers.d.ts.map +1 -0
  66. package/dist/channel/api/workers.js +145 -0
  67. package/dist/channel/api/workers.js.map +1 -0
  68. package/dist/channel/index.d.ts +38 -0
  69. package/dist/channel/index.d.ts.map +1 -0
  70. package/dist/channel/index.js +23 -0
  71. package/dist/channel/index.js.map +1 -0
  72. package/dist/channel/internal/store/channel-metadata.d.ts +23 -0
  73. package/dist/channel/internal/store/channel-metadata.d.ts.map +1 -0
  74. package/dist/channel/internal/store/channel-metadata.js +94 -0
  75. package/dist/channel/internal/store/channel-metadata.js.map +1 -0
  76. package/dist/channel/internal/store/delivery.d.ts +27 -0
  77. package/dist/channel/internal/store/delivery.d.ts.map +1 -0
  78. package/dist/channel/internal/store/delivery.js +37 -0
  79. package/dist/channel/internal/store/delivery.js.map +1 -0
  80. package/dist/channel/internal/store/events.d.ts +215 -0
  81. package/dist/channel/internal/store/events.d.ts.map +1 -0
  82. package/dist/channel/internal/store/events.js +209 -0
  83. package/dist/channel/internal/store/events.js.map +1 -0
  84. package/dist/channel/internal/store/filter.d.ts +21 -0
  85. package/dist/channel/internal/store/filter.d.ts.map +1 -0
  86. package/dist/channel/internal/store/filter.js +75 -0
  87. package/dist/channel/internal/store/filter.js.map +1 -0
  88. package/dist/channel/internal/store/inbox.d.ts +17 -0
  89. package/dist/channel/internal/store/inbox.d.ts.map +1 -0
  90. package/dist/channel/internal/store/inbox.js +30 -0
  91. package/dist/channel/internal/store/inbox.js.map +1 -0
  92. package/dist/channel/internal/store/lock.d.ts +17 -0
  93. package/dist/channel/internal/store/lock.d.ts.map +1 -0
  94. package/dist/channel/internal/store/lock.js +88 -0
  95. package/dist/channel/internal/store/lock.js.map +1 -0
  96. package/dist/channel/internal/store/paths.d.ts +57 -0
  97. package/dist/channel/internal/store/paths.d.ts.map +1 -0
  98. package/dist/channel/internal/store/paths.js +264 -0
  99. package/dist/channel/internal/store/paths.js.map +1 -0
  100. package/dist/channel/internal/store/schema.d.ts +77 -0
  101. package/dist/channel/internal/store/schema.d.ts.map +1 -0
  102. package/dist/channel/internal/store/schema.js +127 -0
  103. package/dist/channel/internal/store/schema.js.map +1 -0
  104. package/dist/channel/internal/store/seq.d.ts +23 -0
  105. package/dist/channel/internal/store/seq.d.ts.map +1 -0
  106. package/dist/channel/internal/store/seq.js +175 -0
  107. package/dist/channel/internal/store/seq.js.map +1 -0
  108. package/dist/channel/internal/store/thread-state.d.ts +37 -0
  109. package/dist/channel/internal/store/thread-state.d.ts.map +1 -0
  110. package/dist/channel/internal/store/thread-state.js +206 -0
  111. package/dist/channel/internal/store/thread-state.js.map +1 -0
  112. package/dist/channel/internal/store/watch.d.ts +10 -0
  113. package/dist/channel/internal/store/watch.d.ts.map +1 -0
  114. package/dist/channel/internal/store/watch.js +129 -0
  115. package/dist/channel/internal/store/watch.js.map +1 -0
  116. package/dist/channel/internal/store/worker-state.d.ts +56 -0
  117. package/dist/channel/internal/store/worker-state.d.ts.map +1 -0
  118. package/dist/channel/internal/store/worker-state.js +220 -0
  119. package/dist/channel/internal/store/worker-state.js.map +1 -0
  120. package/dist/index.d.ts +3 -0
  121. package/dist/index.d.ts.map +1 -0
  122. package/dist/index.js +7 -0
  123. package/dist/index.js.map +1 -0
  124. package/dist/mem/adapters/claude.d.ts +22 -0
  125. package/dist/mem/adapters/claude.d.ts.map +1 -0
  126. package/dist/mem/adapters/claude.js +209 -0
  127. package/dist/mem/adapters/claude.js.map +1 -0
  128. package/dist/mem/adapters/codex.d.ts +55 -0
  129. package/dist/mem/adapters/codex.d.ts.map +1 -0
  130. package/dist/mem/adapters/codex.js +344 -0
  131. package/dist/mem/adapters/codex.js.map +1 -0
  132. package/dist/mem/adapters/grok.d.ts +41 -0
  133. package/dist/mem/adapters/grok.d.ts.map +1 -0
  134. package/dist/mem/adapters/grok.js +202 -0
  135. package/dist/mem/adapters/grok.js.map +1 -0
  136. package/dist/mem/adapters/opencode.d.ts +35 -0
  137. package/dist/mem/adapters/opencode.d.ts.map +1 -0
  138. package/dist/mem/adapters/opencode.js +437 -0
  139. package/dist/mem/adapters/opencode.js.map +1 -0
  140. package/dist/mem/adapters/pi.d.ts +24 -0
  141. package/dist/mem/adapters/pi.d.ts.map +1 -0
  142. package/dist/mem/adapters/pi.js +290 -0
  143. package/dist/mem/adapters/pi.js.map +1 -0
  144. package/dist/mem/adapters/zcode.d.ts +76 -0
  145. package/dist/mem/adapters/zcode.d.ts.map +1 -0
  146. package/dist/mem/adapters/zcode.js +434 -0
  147. package/dist/mem/adapters/zcode.js.map +1 -0
  148. package/dist/mem/context.d.ts +23 -0
  149. package/dist/mem/context.d.ts.map +1 -0
  150. package/dist/mem/context.js +120 -0
  151. package/dist/mem/context.js.map +1 -0
  152. package/dist/mem/dialogue.d.ts +32 -0
  153. package/dist/mem/dialogue.d.ts.map +1 -0
  154. package/dist/mem/dialogue.js +0 -0
  155. package/dist/mem/dialogue.js.map +1 -0
  156. package/dist/mem/filter.d.ts +31 -0
  157. package/dist/mem/filter.d.ts.map +1 -0
  158. package/dist/mem/filter.js +66 -0
  159. package/dist/mem/filter.js.map +1 -0
  160. package/dist/mem/index.d.ts +18 -0
  161. package/dist/mem/index.d.ts.map +1 -0
  162. package/dist/mem/index.js +17 -0
  163. package/dist/mem/index.js.map +1 -0
  164. package/dist/mem/internal/jsonl.d.ts +35 -0
  165. package/dist/mem/internal/jsonl.d.ts.map +1 -0
  166. package/dist/mem/internal/jsonl.js +125 -0
  167. package/dist/mem/internal/jsonl.js.map +1 -0
  168. package/dist/mem/internal/paths.d.ts +67 -0
  169. package/dist/mem/internal/paths.d.ts.map +1 -0
  170. package/dist/mem/internal/paths.js +194 -0
  171. package/dist/mem/internal/paths.js.map +1 -0
  172. package/dist/mem/internal/sqlite-readonly.d.ts +77 -0
  173. package/dist/mem/internal/sqlite-readonly.d.ts.map +1 -0
  174. package/dist/mem/internal/sqlite-readonly.js +797 -0
  175. package/dist/mem/internal/sqlite-readonly.js.map +1 -0
  176. package/dist/mem/phase.d.ts +45 -0
  177. package/dist/mem/phase.d.ts.map +1 -0
  178. package/dist/mem/phase.js +220 -0
  179. package/dist/mem/phase.js.map +1 -0
  180. package/dist/mem/projects.d.ts +13 -0
  181. package/dist/mem/projects.d.ts.map +1 -0
  182. package/dist/mem/projects.js +47 -0
  183. package/dist/mem/projects.js.map +1 -0
  184. package/dist/mem/search.d.ts +39 -0
  185. package/dist/mem/search.d.ts.map +1 -0
  186. package/dist/mem/search.js +133 -0
  187. package/dist/mem/search.js.map +1 -0
  188. package/dist/mem/sessions.d.ts +38 -0
  189. package/dist/mem/sessions.d.ts.map +1 -0
  190. package/dist/mem/sessions.js +318 -0
  191. package/dist/mem/sessions.js.map +1 -0
  192. package/dist/mem/types.d.ts +188 -0
  193. package/dist/mem/types.d.ts.map +1 -0
  194. package/dist/mem/types.js +10 -0
  195. package/dist/mem/types.js.map +1 -0
  196. package/dist/task/index.d.ts +9 -0
  197. package/dist/task/index.d.ts.map +1 -0
  198. package/dist/task/index.js +9 -0
  199. package/dist/task/index.js.map +1 -0
  200. package/dist/task/paths.d.ts +37 -0
  201. package/dist/task/paths.d.ts.map +1 -0
  202. package/dist/task/paths.js +49 -0
  203. package/dist/task/paths.js.map +1 -0
  204. package/dist/task/phase.d.ts +25 -0
  205. package/dist/task/phase.d.ts.map +1 -0
  206. package/dist/task/phase.js +19 -0
  207. package/dist/task/phase.js.map +1 -0
  208. package/dist/task/records.d.ts +39 -0
  209. package/dist/task/records.d.ts.map +1 -0
  210. package/dist/task/records.js +89 -0
  211. package/dist/task/records.js.map +1 -0
  212. package/dist/task/schema.d.ts +93 -0
  213. package/dist/task/schema.d.ts.map +1 -0
  214. package/dist/task/schema.js +268 -0
  215. package/dist/task/schema.js.map +1 -0
  216. package/dist/testing/index.d.ts +2 -0
  217. package/dist/testing/index.d.ts.map +1 -0
  218. package/dist/testing/index.js +4 -0
  219. package/dist/testing/index.js.map +1 -0
  220. package/package.json +84 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Task directory naming.
3
+ *
4
+ * User-created task dirs follow the `MM-DD-slug` pattern produced by
5
+ * `.atw/scripts/common/task_store.py::cmd_create`:
6
+ *
7
+ * <tasks-dir>/05-13-atw-core-sdk-package/
8
+ *
9
+ * ATW also creates system onboarding tasks during `atw init` using a
10
+ * `00-slug` prefix, such as `00-bootstrap-guidelines` and `00-join-new-developer`.
11
+ *
12
+ * `MM` is the two-digit month, `DD` is the two-digit day, and `slug` is
13
+ * a lower-kebab-case identifier composed of `[a-z0-9-]+` characters.
14
+ */
15
+ const DATED_TASK_DIR_RE = /^(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])-([a-z0-9]+(?:-[a-z0-9]+)*)$/;
16
+ const SYSTEM_TASK_DIR_RE = /^00-(bootstrap-guidelines|join-[a-z0-9]+(?:-[a-z0-9]+)*)$/;
17
+ /**
18
+ * Validate a task directory base name (no slashes). Returns the parsed
19
+ * components when valid, or `null` when the name does not match a canonical
20
+ * task dir shape.
21
+ *
22
+ * Throws `TypeError` if `name` is not a string — guards downstream code
23
+ * from accidentally validating `Buffer`, `Path`, or other inputs.
24
+ */
25
+ export function validateTaskDirName(name) {
26
+ if (typeof name !== "string") {
27
+ throw new TypeError("task directory name must be a string");
28
+ }
29
+ const dated = DATED_TASK_DIR_RE.exec(name);
30
+ if (dated) {
31
+ const [, month, day, slug] = dated;
32
+ if (month === undefined || day === undefined || slug === undefined) {
33
+ return null;
34
+ }
35
+ return { prefix: `${month}-${day}`, month, day, slug };
36
+ }
37
+ const system = SYSTEM_TASK_DIR_RE.exec(name);
38
+ if (system) {
39
+ const [, slug] = system;
40
+ if (slug === undefined)
41
+ return null;
42
+ return { prefix: "00", month: null, day: null, slug };
43
+ }
44
+ return null;
45
+ }
46
+ export function isValidTaskDirName(name) {
47
+ return validateTaskDirName(name) !== null;
48
+ }
49
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/task/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,iBAAiB,GACrB,oEAAoE,CAAC;AACvE,MAAM,kBAAkB,GACtB,2DAA2D,CAAC;AAe9D;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;QACnC,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACzD,CAAC;IAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QACxB,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,mBAAmB,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { AtwTaskRecord, AtwTaskStatus } from "./schema.js";
2
+ /**
3
+ * Coarse-grained ATW task phase derived from task status.
4
+ *
5
+ * Phase is a projection of {@link AtwTaskRecord.status} only. There is
6
+ * no separate `current_phase` field stored on disk — `inferTaskPhase`
7
+ * exists so consumers can render the workflow phase without depending on
8
+ * `.atw/workflow.md` parsing.
9
+ *
10
+ * A canonical status is its own phase; anything else is `unknown`.
11
+ */
12
+ export type AtwTaskPhase = AtwTaskStatus | "unknown";
13
+ /**
14
+ * Infer the phase of a task from either its parsed record or its raw
15
+ * status string. Accepts a record so callers that already have one don't
16
+ * need to re-pluck `status` first.
17
+ *
18
+ * The `unknown` fallback is deliberate and must stay. A parsed
19
+ * {@link AtwTaskRecord} always carries a canonical status, but the raw-string
20
+ * overload exists precisely for callers holding an unvalidated value — a
21
+ * hand-edited `task.json` read without `taskRecordSchema`. Throwing would turn
22
+ * a display helper into a crash site.
23
+ */
24
+ export declare function inferTaskPhase(recordOrStatus: AtwTaskRecord | string | null | undefined): AtwTaskPhase;
25
+ //# sourceMappingURL=phase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase.d.ts","sourceRoot":"","sources":["../../src/task/phase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGhE;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,SAAS,CAAC;AAErD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,cAAc,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GACxD,YAAY,CAMd"}
@@ -0,0 +1,19 @@
1
+ import { isAtwTaskStatus } from "./schema.js";
2
+ /**
3
+ * Infer the phase of a task from either its parsed record or its raw
4
+ * status string. Accepts a record so callers that already have one don't
5
+ * need to re-pluck `status` first.
6
+ *
7
+ * The `unknown` fallback is deliberate and must stay. A parsed
8
+ * {@link AtwTaskRecord} always carries a canonical status, but the raw-string
9
+ * overload exists precisely for callers holding an unvalidated value — a
10
+ * hand-edited `task.json` read without `taskRecordSchema`. Throwing would turn
11
+ * a display helper into a crash site.
12
+ */
13
+ export function inferTaskPhase(recordOrStatus) {
14
+ const status = typeof recordOrStatus === "string"
15
+ ? recordOrStatus
16
+ : recordOrStatus?.status;
17
+ return isAtwTaskStatus(status) ? status : "unknown";
18
+ }
19
+ //# sourceMappingURL=phase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase.js","sourceRoot":"","sources":["../../src/task/phase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAc9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,cAAyD;IAEzD,MAAM,MAAM,GACV,OAAO,cAAc,KAAK,QAAQ;QAChC,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,cAAc,EAAE,MAAM,CAAC;IAC7B,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { emptyTaskRecord, type AtwTaskRecord } from "./schema.js";
2
+ export interface LoadTaskRecordOptions {
3
+ /** Absolute or repo-relative directory containing `task.json`. */
4
+ taskDir: string;
5
+ /** Optional repo root used to resolve relative `taskDir` values. */
6
+ cwd?: string;
7
+ }
8
+ export interface WriteTaskRecordOptions {
9
+ /** Absolute or repo-relative directory containing `task.json`. */
10
+ taskDir: string;
11
+ /** Canonical record to persist. Unknown fields on disk are preserved. */
12
+ record: AtwTaskRecord;
13
+ /** Optional repo root used to resolve relative `taskDir` values. */
14
+ cwd?: string;
15
+ }
16
+ /**
17
+ * Read a task.json file and return a canonicalized record.
18
+ *
19
+ * Unknown fields on disk that are not part of the canonical 24-field
20
+ * shape are NOT returned — `loadTaskRecord` is the structured public API.
21
+ * To preserve unknown fields across a load/write cycle, callers should
22
+ * use {@link writeTaskRecord}, which merges canonical updates on top of
23
+ * the on-disk JSON object instead of overwriting it.
24
+ */
25
+ export declare function loadTaskRecord(options: LoadTaskRecordOptions): AtwTaskRecord;
26
+ /**
27
+ * Write a task.json file with canonical field ordering. Unknown fields
28
+ * already present on disk are preserved verbatim — only the canonical
29
+ * fields are overwritten by `record`. Field order: canonical fields
30
+ * first (in `TASK_RECORD_FIELD_ORDER`), then any preserved unknown
31
+ * fields in their original insertion order. If an existing `task.json` is
32
+ * present but cannot be parsed as a JSON object, the write is rejected instead
33
+ * of silently replacing potentially recoverable local data.
34
+ *
35
+ * The directory containing `task.json` is created if it does not exist.
36
+ */
37
+ export declare function writeTaskRecord(options: WriteTaskRecordOptions): void;
38
+ export { emptyTaskRecord };
39
+ //# sourceMappingURL=records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../src/task/records.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,eAAe,EAGf,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,aAAa,CAAC;IACtB,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,aAAa,CAYf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAsBrE;AAoCD,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,89 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { TASK_RECORD_FIELD_ORDER, emptyTaskRecord, isPlainObject, taskRecordSchema, } from "./schema.js";
4
+ const TASK_JSON_BASENAME = "task.json";
5
+ /**
6
+ * Read a task.json file and return a canonicalized record.
7
+ *
8
+ * Unknown fields on disk that are not part of the canonical 24-field
9
+ * shape are NOT returned — `loadTaskRecord` is the structured public API.
10
+ * To preserve unknown fields across a load/write cycle, callers should
11
+ * use {@link writeTaskRecord}, which merges canonical updates on top of
12
+ * the on-disk JSON object instead of overwriting it.
13
+ */
14
+ export function loadTaskRecord(options) {
15
+ const file = resolveTaskJsonPath(options.taskDir, options.cwd);
16
+ const raw = fs.readFileSync(file, "utf-8");
17
+ let parsed;
18
+ try {
19
+ parsed = JSON.parse(raw);
20
+ }
21
+ catch (err) {
22
+ throw new Error(`Failed to parse ${file}: ${err instanceof Error ? err.message : err}`);
23
+ }
24
+ return taskRecordSchema.parse(parsed);
25
+ }
26
+ /**
27
+ * Write a task.json file with canonical field ordering. Unknown fields
28
+ * already present on disk are preserved verbatim — only the canonical
29
+ * fields are overwritten by `record`. Field order: canonical fields
30
+ * first (in `TASK_RECORD_FIELD_ORDER`), then any preserved unknown
31
+ * fields in their original insertion order. If an existing `task.json` is
32
+ * present but cannot be parsed as a JSON object, the write is rejected instead
33
+ * of silently replacing potentially recoverable local data.
34
+ *
35
+ * The directory containing `task.json` is created if it does not exist.
36
+ */
37
+ export function writeTaskRecord(options) {
38
+ const record = taskRecordSchema.parse(options.record);
39
+ const file = resolveTaskJsonPath(options.taskDir, options.cwd);
40
+ fs.mkdirSync(path.dirname(file), { recursive: true });
41
+ const existing = readExistingObject(file);
42
+ const out = {};
43
+ const recordBag = record;
44
+ for (const field of TASK_RECORD_FIELD_ORDER) {
45
+ out[field] = recordBag[field];
46
+ }
47
+ if (existing) {
48
+ for (const key of Object.keys(existing)) {
49
+ if (!(key in out)) {
50
+ out[key] = existing[key];
51
+ }
52
+ }
53
+ }
54
+ const json = JSON.stringify(out, null, 2) + "\n";
55
+ fs.writeFileSync(file, json, "utf-8");
56
+ }
57
+ function readExistingObject(file) {
58
+ let raw;
59
+ try {
60
+ raw = fs.readFileSync(file, "utf-8");
61
+ }
62
+ catch (err) {
63
+ if (err.code === "ENOENT")
64
+ return null;
65
+ throw err;
66
+ }
67
+ let parsed;
68
+ try {
69
+ parsed = JSON.parse(raw);
70
+ }
71
+ catch (err) {
72
+ throw new Error(`Refusing to overwrite corrupt ${file}: ${err instanceof Error ? err.message : String(err)}`);
73
+ }
74
+ if (!isPlainObject(parsed)) {
75
+ throw new Error(`Refusing to overwrite non-object task record at ${file}`);
76
+ }
77
+ return parsed;
78
+ }
79
+ function resolveTaskJsonPath(taskDir, cwd) {
80
+ if (path.isAbsolute(taskDir)) {
81
+ return path.join(taskDir, TASK_JSON_BASENAME);
82
+ }
83
+ const base = cwd ?? process.cwd();
84
+ return path.join(path.resolve(base, taskDir), TASK_JSON_BASENAME);
85
+ }
86
+ // Re-exported so callers can build a starter record without hitting the
87
+ // schema module directly.
88
+ export { emptyTaskRecord };
89
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/task/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,aAAa,EACb,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AAErB,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAkBvC;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,OAA8B;IAE9B,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,mBAAmB,IAAI,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CACvE,CAAC;IACJ,CAAC;IACD,OAAO,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,OAA+B;IAC7D,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,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IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,iCAAiC,IAAI,KACnC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CACjD,EAAE,CACH,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,mDAAmD,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe,EAAE,GAAY;IACxD,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC;AACpE,CAAC;AAED,wEAAwE;AACxE,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Canonical task.json shape — single source of truth for ATW tasks.
3
+ *
4
+ * The runtime Python writer is `.atw/scripts/common/task_store.py`
5
+ * (`cmd_create`). The 24-field shape and field order below mirror that
6
+ * writer exactly so every TS and Python entry point produces structurally
7
+ * identical task.json files.
8
+ *
9
+ * Downstream consumers (CLI bootstrap, migration tooling, external Node
10
+ * services) should depend on this type instead of redefining their own
11
+ * task.json shape.
12
+ */
13
+ /**
14
+ * Canonical ATW task statuses, in workflow order.
15
+ *
16
+ * These six literals are the contract. The Python writer
17
+ * (`.atw/scripts/task.py set-status`) keeps its own copy in
18
+ * `task_store.py::STATUS_VALUES` because it cannot import TypeScript; the two
19
+ * lists are pinned to each other by a judgment, not by a shared import.
20
+ *
21
+ * The retired vocabulary (planning / in_progress / review / done) is absent on
22
+ * purpose and must stay absent — no compatibility shim.
23
+ */
24
+ export declare const TASK_STATUS_VALUES: readonly ["discover", "specify", "slice", "implement", "accept", "completed"];
25
+ /** One of the six canonical workflow stages. */
26
+ export type AtwTaskStatus = (typeof TASK_STATUS_VALUES)[number];
27
+ /** Narrow an arbitrary value to a canonical status. */
28
+ export declare function isAtwTaskStatus(value: unknown): value is AtwTaskStatus;
29
+ export interface AtwTaskRecord {
30
+ id: string;
31
+ name: string;
32
+ title: string;
33
+ description: string;
34
+ status: AtwTaskStatus;
35
+ dev_type: string | null;
36
+ scope: string | null;
37
+ package: string | null;
38
+ priority: string;
39
+ creator: string;
40
+ assignee: string;
41
+ createdAt: string;
42
+ completedAt: string | null;
43
+ branch: string | null;
44
+ base_branch: string | null;
45
+ worktree_path: string | null;
46
+ commit: string | null;
47
+ pr_url: string | null;
48
+ subtasks: string[];
49
+ children: string[];
50
+ parent: string | null;
51
+ relatedFiles: string[];
52
+ notes: string;
53
+ meta: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * Canonical task field order — matches `task_store.py::cmd_create`. Used
57
+ * by `writeTaskRecord` so the on-disk JSON layout is deterministic.
58
+ */
59
+ export declare const TASK_RECORD_FIELD_ORDER: readonly ["id", "name", "title", "description", "status", "dev_type", "scope", "package", "priority", "creator", "assignee", "createdAt", "completedAt", "branch", "base_branch", "worktree_path", "commit", "pr_url", "subtasks", "children", "parent", "relatedFiles", "notes", "meta"];
60
+ export type TaskRecordField = (typeof TASK_RECORD_FIELD_ORDER)[number];
61
+ /**
62
+ * Lightweight runtime schema for {@link AtwTaskRecord}. Zero-dep on
63
+ * purpose — `taskRecordSchema.parse(input)` returns a canonicalized
64
+ * record, throwing on shape violations; `taskRecordSchema.safeParse`
65
+ * returns a result discriminated by `success`.
66
+ *
67
+ * All canonical fields are required; older partial records are rejected rather
68
+ * than backfilled with defaults. Unknown fields on the input are intentionally
69
+ * omitted from this structured output. `writeTaskRecord` preserves unknown
70
+ * fields already present on disk by merging canonical updates over the existing
71
+ * JSON object.
72
+ */
73
+ export declare const taskRecordSchema: {
74
+ readonly parse: (input: unknown) => AtwTaskRecord;
75
+ readonly safeParse: (input: unknown) => {
76
+ success: true;
77
+ data: AtwTaskRecord;
78
+ } | {
79
+ success: false;
80
+ error: Error;
81
+ };
82
+ };
83
+ /**
84
+ * Produce a fully-populated canonical-shape {@link AtwTaskRecord}.
85
+ *
86
+ * All 24 fields are present in canonical order. `overrides` shallow-merges
87
+ * over the defaults — callers supply per-task values (id, name, title,
88
+ * assignee, createdAt, etc.) and leave null-default fields untouched
89
+ * unless they have a real value.
90
+ */
91
+ export declare function emptyTaskRecord(overrides?: Partial<AtwTaskRecord>): AtwTaskRecord;
92
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
93
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/task/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,+EAOrB,CAAC;AAEX,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAIhE,uDAAuD;AACvD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,aAAa,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rC,aAAa,CA0Cf;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAO9E"}
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Canonical task.json shape — single source of truth for ATW tasks.
3
+ *
4
+ * The runtime Python writer is `.atw/scripts/common/task_store.py`
5
+ * (`cmd_create`). The 24-field shape and field order below mirror that
6
+ * writer exactly so every TS and Python entry point produces structurally
7
+ * identical task.json files.
8
+ *
9
+ * Downstream consumers (CLI bootstrap, migration tooling, external Node
10
+ * services) should depend on this type instead of redefining their own
11
+ * task.json shape.
12
+ */
13
+ /**
14
+ * Canonical ATW task statuses, in workflow order.
15
+ *
16
+ * These six literals are the contract. The Python writer
17
+ * (`.atw/scripts/task.py set-status`) keeps its own copy in
18
+ * `task_store.py::STATUS_VALUES` because it cannot import TypeScript; the two
19
+ * lists are pinned to each other by a judgment, not by a shared import.
20
+ *
21
+ * The retired vocabulary (planning / in_progress / review / done) is absent on
22
+ * purpose and must stay absent — no compatibility shim.
23
+ */
24
+ export const TASK_STATUS_VALUES = [
25
+ "discover",
26
+ "specify",
27
+ "slice",
28
+ "implement",
29
+ "accept",
30
+ "completed",
31
+ ];
32
+ const TASK_STATUS_SET = new Set(TASK_STATUS_VALUES);
33
+ /** Narrow an arbitrary value to a canonical status. */
34
+ export function isAtwTaskStatus(value) {
35
+ return typeof value === "string" && TASK_STATUS_SET.has(value);
36
+ }
37
+ /**
38
+ * Canonical task field order — matches `task_store.py::cmd_create`. Used
39
+ * by `writeTaskRecord` so the on-disk JSON layout is deterministic.
40
+ */
41
+ export const TASK_RECORD_FIELD_ORDER = [
42
+ "id",
43
+ "name",
44
+ "title",
45
+ "description",
46
+ "status",
47
+ "dev_type",
48
+ "scope",
49
+ "package",
50
+ "priority",
51
+ "creator",
52
+ "assignee",
53
+ "createdAt",
54
+ "completedAt",
55
+ "branch",
56
+ "base_branch",
57
+ "worktree_path",
58
+ "commit",
59
+ "pr_url",
60
+ "subtasks",
61
+ "children",
62
+ "parent",
63
+ "relatedFiles",
64
+ "notes",
65
+ "meta",
66
+ ];
67
+ // `status` is deliberately absent — it is not a free-form string and gets its
68
+ // own branch in `assignField` that checks the value against the six canonical
69
+ // stages.
70
+ const STRING_FIELDS = new Set([
71
+ "id",
72
+ "name",
73
+ "title",
74
+ "description",
75
+ "priority",
76
+ "creator",
77
+ "assignee",
78
+ "createdAt",
79
+ "notes",
80
+ ]);
81
+ const NULLABLE_STRING_FIELDS = new Set([
82
+ "dev_type",
83
+ "scope",
84
+ "package",
85
+ "completedAt",
86
+ "branch",
87
+ "base_branch",
88
+ "worktree_path",
89
+ "commit",
90
+ "pr_url",
91
+ "parent",
92
+ ]);
93
+ const STRING_ARRAY_FIELDS = new Set([
94
+ "subtasks",
95
+ "children",
96
+ "relatedFiles",
97
+ ]);
98
+ /**
99
+ * Lightweight runtime schema for {@link AtwTaskRecord}. Zero-dep on
100
+ * purpose — `taskRecordSchema.parse(input)` returns a canonicalized
101
+ * record, throwing on shape violations; `taskRecordSchema.safeParse`
102
+ * returns a result discriminated by `success`.
103
+ *
104
+ * All canonical fields are required; older partial records are rejected rather
105
+ * than backfilled with defaults. Unknown fields on the input are intentionally
106
+ * omitted from this structured output. `writeTaskRecord` preserves unknown
107
+ * fields already present on disk by merging canonical updates over the existing
108
+ * JSON object.
109
+ */
110
+ export const taskRecordSchema = {
111
+ parse(input) {
112
+ return parseTaskRecord(input);
113
+ },
114
+ safeParse(input) {
115
+ try {
116
+ return { success: true, data: parseTaskRecord(input) };
117
+ }
118
+ catch (err) {
119
+ return {
120
+ success: false,
121
+ error: err instanceof Error ? err : new Error(String(err)),
122
+ };
123
+ }
124
+ },
125
+ };
126
+ function parseTaskRecord(input) {
127
+ if (!isPlainObject(input)) {
128
+ throw new Error("task record must be a JSON object");
129
+ }
130
+ const out = emptyTaskRecord();
131
+ for (const field of TASK_RECORD_FIELD_ORDER) {
132
+ if (!(field in input)) {
133
+ throw new Error(`task.${field} is required`);
134
+ }
135
+ const value = input[field];
136
+ assignField(out, field, value);
137
+ }
138
+ return out;
139
+ }
140
+ function assignField(record, field, value) {
141
+ const bag = record;
142
+ if (field === "status") {
143
+ // A retired value (planning / in_progress / review / done) is rejected here
144
+ // like any other typo. Accepting it would be the old vocabulary still in
145
+ // production, just undocumented — mirrors `task_store.py::cmd_set_status`.
146
+ if (!isAtwTaskStatus(value)) {
147
+ throw new Error(`task.status must be one of: ${TASK_STATUS_VALUES.join(", ")}`);
148
+ }
149
+ record.status = value;
150
+ return;
151
+ }
152
+ if (STRING_FIELDS.has(field)) {
153
+ if (typeof value !== "string") {
154
+ throw new Error(`task.${field} must be a string`);
155
+ }
156
+ bag[field] = value;
157
+ return;
158
+ }
159
+ if (NULLABLE_STRING_FIELDS.has(field)) {
160
+ if (value !== null && typeof value !== "string") {
161
+ throw new Error(`task.${field} must be a string or null`);
162
+ }
163
+ bag[field] = value;
164
+ return;
165
+ }
166
+ if (STRING_ARRAY_FIELDS.has(field)) {
167
+ if (!Array.isArray(value) || value.some((v) => typeof v !== "string")) {
168
+ throw new Error(`task.${field} must be an array of strings`);
169
+ }
170
+ bag[field] = [...value];
171
+ return;
172
+ }
173
+ if (field === "meta") {
174
+ if (!isPlainObject(value)) {
175
+ throw new Error("task.meta must be a JSON object");
176
+ }
177
+ record.meta = cloneJsonObject(value, "task.meta");
178
+ return;
179
+ }
180
+ // Should be unreachable given the field sets cover every canonical field.
181
+ /* c8 ignore next */
182
+ throw new Error(`unknown canonical task field: ${field}`);
183
+ }
184
+ /**
185
+ * Produce a fully-populated canonical-shape {@link AtwTaskRecord}.
186
+ *
187
+ * All 24 fields are present in canonical order. `overrides` shallow-merges
188
+ * over the defaults — callers supply per-task values (id, name, title,
189
+ * assignee, createdAt, etc.) and leave null-default fields untouched
190
+ * unless they have a real value.
191
+ */
192
+ export function emptyTaskRecord(overrides = {}) {
193
+ const today = new Date().toISOString().split("T")[0] ?? "";
194
+ const base = {
195
+ id: "",
196
+ name: "",
197
+ title: "",
198
+ description: "",
199
+ status: "discover",
200
+ dev_type: null,
201
+ scope: null,
202
+ package: null,
203
+ priority: "P2",
204
+ creator: "",
205
+ assignee: "",
206
+ createdAt: today,
207
+ completedAt: null,
208
+ branch: null,
209
+ base_branch: null,
210
+ worktree_path: null,
211
+ commit: null,
212
+ pr_url: null,
213
+ subtasks: [],
214
+ children: [],
215
+ parent: null,
216
+ relatedFiles: [],
217
+ notes: "",
218
+ meta: {},
219
+ };
220
+ const record = { ...base, ...overrides };
221
+ if (overrides.subtasks !== undefined) {
222
+ record.subtasks = [...overrides.subtasks];
223
+ }
224
+ if (overrides.children !== undefined) {
225
+ record.children = [...overrides.children];
226
+ }
227
+ if (overrides.relatedFiles !== undefined) {
228
+ record.relatedFiles = [...overrides.relatedFiles];
229
+ }
230
+ if (overrides.meta !== undefined) {
231
+ record.meta = cloneJsonObject(overrides.meta, "task.meta");
232
+ }
233
+ return record;
234
+ }
235
+ export function isPlainObject(value) {
236
+ return (typeof value === "object" &&
237
+ value !== null &&
238
+ !Array.isArray(value) &&
239
+ Object.getPrototypeOf(value) === Object.prototype);
240
+ }
241
+ function cloneJsonObject(value, path) {
242
+ const out = {};
243
+ for (const [key, child] of Object.entries(value)) {
244
+ out[key] = cloneJsonValue(child, `${path}.${key}`);
245
+ }
246
+ return out;
247
+ }
248
+ function cloneJsonValue(value, path) {
249
+ if (value === null ||
250
+ typeof value === "string" ||
251
+ typeof value === "boolean") {
252
+ return value;
253
+ }
254
+ if (typeof value === "number") {
255
+ if (!Number.isFinite(value)) {
256
+ throw new Error(`${path} must be a finite JSON number`);
257
+ }
258
+ return value;
259
+ }
260
+ if (Array.isArray(value)) {
261
+ return value.map((item, index) => cloneJsonValue(item, `${path}[${index}]`));
262
+ }
263
+ if (isPlainObject(value)) {
264
+ return cloneJsonObject(value, path);
265
+ }
266
+ throw new Error(`${path} must contain only JSON values`);
267
+ }
268
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/task/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU;IACV,SAAS;IACT,OAAO;IACP,WAAW;IACX,QAAQ;IACR,WAAW;CACH,CAAC;AAKX,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEzE,uDAAuD;AACvD,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AA6BD;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,IAAI;IACJ,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;IACR,UAAU;IACV,OAAO;IACP,SAAS;IACT,UAAU;IACV,SAAS;IACT,UAAU;IACV,WAAW;IACX,aAAa;IACb,QAAQ;IACR,aAAa;IACb,eAAe;IACf,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,UAAU;IACV,QAAQ;IACR,cAAc;IACd,OAAO;IACP,MAAM;CAC6C,CAAC;AAItD,8EAA8E;AAC9E,8EAA8E;AAC9E,UAAU;AACV,MAAM,aAAa,GAAiC,IAAI,GAAG,CAAC;IAC1D,IAAI;IACJ,MAAM;IACN,OAAO;IACP,aAAa;IACb,UAAU;IACV,SAAS;IACT,UAAU;IACV,WAAW;IACX,OAAO;CACR,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAiC,IAAI,GAAG,CAAC;IACnE,UAAU;IACV,OAAO;IACP,SAAS;IACT,aAAa;IACb,QAAQ;IACR,aAAa;IACb,eAAe;IACf,QAAQ;IACR,QAAQ;IACR,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAiC,IAAI,GAAG,CAAC;IAChE,UAAU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;QACzB,OAAO,KAAK,KAAK,SAAS,EAC1B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,gCAAgC,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Testing helpers placeholder. Exposes nothing in P0; reserved for the
2
+ // public testing surface in later phases.
3
+ export {};
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0CAA0C"}