@gitroll/tacitt-cli 0.0.0-stage → 0.2.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 (142) hide show
  1. package/README.md +84 -2
  2. package/bin/INDEX.md +9 -0
  3. package/bin/tacitt.cjs +16 -0
  4. package/dist/agent-setup-B8DAiQ6Z.mjs +71 -0
  5. package/dist/agent-setup-worker.mjs +56 -0
  6. package/dist/cli.mjs +1442 -0
  7. package/dist/codex-title-worker.mjs +215 -0
  8. package/dist/configured-preview-worker.mjs +133 -0
  9. package/dist/configured-session-worker.mjs +117 -0
  10. package/dist/frame-waS5FnN5.mjs +84 -0
  11. package/dist/heap-1FYhGds4.mjs +75 -0
  12. package/dist/heap-BHcvxWCw.mjs +7265 -0
  13. package/dist/inspection-worker.mjs +57 -0
  14. package/dist/job-J3NFw3MH.mjs +194 -0
  15. package/dist/locate-U3-nkird.mjs +10670 -0
  16. package/dist/messages-D3m3bhva.mjs +40 -0
  17. package/dist/model-BJdTLNjT.mjs +41 -0
  18. package/dist/operation-executor.mjs +181 -0
  19. package/dist/preview-worker.mjs +22 -0
  20. package/dist/privacy-validator.mjs +46 -0
  21. package/dist/query-BA0XCwnR.mjs +14869 -0
  22. package/dist/run-BeLHsZWb.mjs +916 -0
  23. package/dist/session-process.mjs +90 -0
  24. package/dist/src-B5SArpVY.mjs +6601 -0
  25. package/dist/src-CC95LYYp.mjs +12985 -0
  26. package/dist/src-k0Ya1Bri.mjs +16422 -0
  27. package/dist/store-database-worker.mjs +14 -0
  28. package/dist/web/THIRD_PARTY_LICENSES.md +388 -0
  29. package/dist/web/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  30. package/dist/web/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  31. package/dist/web/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  32. package/dist/web/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  33. package/dist/web/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  34. package/dist/web/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  35. package/dist/web/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  36. package/dist/web/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  37. package/dist/web/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  38. package/dist/web/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  39. package/dist/web/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  40. package/dist/web/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  41. package/dist/web/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  42. package/dist/web/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  43. package/dist/web/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  44. package/dist/web/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  45. package/dist/web/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  46. package/dist/web/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  47. package/dist/web/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  48. package/dist/web/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  49. package/dist/web/assets/ibm-plex-sans-cyrillic-400-normal-BTotfTJu.woff +0 -0
  50. package/dist/web/assets/ibm-plex-sans-cyrillic-400-normal-DZqxrq2p.woff2 +0 -0
  51. package/dist/web/assets/ibm-plex-sans-cyrillic-500-normal-ByOcLdNv.woff +0 -0
  52. package/dist/web/assets/ibm-plex-sans-cyrillic-500-normal-CocWQlwt.woff2 +0 -0
  53. package/dist/web/assets/ibm-plex-sans-cyrillic-600-normal-71GNu3SW.woff2 +0 -0
  54. package/dist/web/assets/ibm-plex-sans-cyrillic-600-normal-BGq0mW3O.woff +0 -0
  55. package/dist/web/assets/ibm-plex-sans-cyrillic-700-normal-D_uavGvn.woff2 +0 -0
  56. package/dist/web/assets/ibm-plex-sans-cyrillic-700-normal-RFb1v-CK.woff +0 -0
  57. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-400-normal-Dsrv2Tcn.woff +0 -0
  58. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-400-normal-g30qAdWV.woff2 +0 -0
  59. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-500-normal-Cs5J6C77.woff2 +0 -0
  60. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-500-normal-DB5PtV2g.woff +0 -0
  61. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-600-normal-Bz0x94Yp.woff +0 -0
  62. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-600-normal-DUMzJB7m.woff2 +0 -0
  63. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-700-normal-BmRLXWpJ.woff2 +0 -0
  64. package/dist/web/assets/ibm-plex-sans-cyrillic-ext-700-normal-DCQwxkRk.woff +0 -0
  65. package/dist/web/assets/ibm-plex-sans-greek-400-normal-D9ESIMu3.woff +0 -0
  66. package/dist/web/assets/ibm-plex-sans-greek-400-normal-_efipK4i.woff2 +0 -0
  67. package/dist/web/assets/ibm-plex-sans-greek-500-normal-CuWXN6rf.woff +0 -0
  68. package/dist/web/assets/ibm-plex-sans-greek-500-normal-JMMifIXV.woff2 +0 -0
  69. package/dist/web/assets/ibm-plex-sans-greek-600-normal-D-CqTdkO.woff +0 -0
  70. package/dist/web/assets/ibm-plex-sans-greek-600-normal-DzTrcv_p.woff2 +0 -0
  71. package/dist/web/assets/ibm-plex-sans-greek-700-normal-CkZN0sRy.woff +0 -0
  72. package/dist/web/assets/ibm-plex-sans-greek-700-normal-wyJ6jzdA.woff2 +0 -0
  73. package/dist/web/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  74. package/dist/web/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
  75. package/dist/web/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
  76. package/dist/web/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
  77. package/dist/web/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
  78. package/dist/web/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  79. package/dist/web/assets/ibm-plex-sans-latin-700-normal-Bth3BMcD.woff +0 -0
  80. package/dist/web/assets/ibm-plex-sans-latin-700-normal-Bxkt5Cjx.woff2 +0 -0
  81. package/dist/web/assets/ibm-plex-sans-latin-ext-400-normal-C5H60-Va.woff2 +0 -0
  82. package/dist/web/assets/ibm-plex-sans-latin-ext-400-normal-RBey6euL.woff +0 -0
  83. package/dist/web/assets/ibm-plex-sans-latin-ext-500-normal-D0aIdm-b.woff +0 -0
  84. package/dist/web/assets/ibm-plex-sans-latin-ext-500-normal-DakdToA3.woff2 +0 -0
  85. package/dist/web/assets/ibm-plex-sans-latin-ext-600-normal-DIrixKbi.woff +0 -0
  86. package/dist/web/assets/ibm-plex-sans-latin-ext-600-normal-DOrvGEcy.woff2 +0 -0
  87. package/dist/web/assets/ibm-plex-sans-latin-ext-700-normal-DZH6Xh-4.woff +0 -0
  88. package/dist/web/assets/ibm-plex-sans-latin-ext-700-normal-aMgXseD4.woff2 +0 -0
  89. package/dist/web/assets/ibm-plex-sans-vietnamese-400-normal-DG4YqDda.woff2 +0 -0
  90. package/dist/web/assets/ibm-plex-sans-vietnamese-400-normal-fK1oJ5dG.woff +0 -0
  91. package/dist/web/assets/ibm-plex-sans-vietnamese-500-normal-BEb3_waV.woff +0 -0
  92. package/dist/web/assets/ibm-plex-sans-vietnamese-500-normal-e4dixQRQ.woff2 +0 -0
  93. package/dist/web/assets/ibm-plex-sans-vietnamese-600-normal-DgdngZtN.woff +0 -0
  94. package/dist/web/assets/ibm-plex-sans-vietnamese-600-normal-DpPYBSTl.woff2 +0 -0
  95. package/dist/web/assets/ibm-plex-sans-vietnamese-700-normal-BV5B8Are.woff +0 -0
  96. package/dist/web/assets/ibm-plex-sans-vietnamese-700-normal-CkEo6LDy.woff2 +0 -0
  97. package/dist/web/assets/index-Bjos73wK.js +67 -0
  98. package/dist/web/assets/index-Bl4C2b2_.css +1 -0
  99. package/dist/web/index.html +14 -0
  100. package/package.json +56 -3
  101. package/skills/INDEX.md +9 -0
  102. package/skills/tacitt/INDEX.md +11 -0
  103. package/skills/tacitt/SKILL.md +44 -0
  104. package/skills/tacitt/references/INDEX.md +15 -0
  105. package/skills/tacitt/references/b-method.md +22 -0
  106. package/skills/tacitt/references/bootstrap.md +109 -0
  107. package/skills/tacitt/references/classification.md +83 -0
  108. package/skills/tacitt/references/commands.md +147 -0
  109. package/skills/tacitt/references/journey.md +54 -0
  110. package/skills/tacitt/references/parallel-review.md +64 -0
  111. package/skills/tacitt/references/send.md +30 -0
  112. package/skills/tacitt/scripts/INDEX.md +43 -0
  113. package/skills/tacitt/scripts/answer.mjs +278 -0
  114. package/skills/tacitt/scripts/describe.mjs +55 -0
  115. package/skills/tacitt/scripts/journey-card-consolidation.d.mts +17 -0
  116. package/skills/tacitt/scripts/journey-card-consolidation.mjs +209 -0
  117. package/skills/tacitt/scripts/journey-classification-metadata.d.mts +16 -0
  118. package/skills/tacitt/scripts/journey-classification-metadata.mjs +111 -0
  119. package/skills/tacitt/scripts/journey-classification-progress.mjs +195 -0
  120. package/skills/tacitt/scripts/journey-classification-tasks.d.mts +18 -0
  121. package/skills/tacitt/scripts/journey-classification-tasks.mjs +345 -0
  122. package/skills/tacitt/scripts/journey-classification-validation.d.mts +20 -0
  123. package/skills/tacitt/scripts/journey-classification-validation.mjs +240 -0
  124. package/skills/tacitt/scripts/journey-classification.mjs +145 -0
  125. package/skills/tacitt/scripts/journey-consolidation-submit.mjs +227 -0
  126. package/skills/tacitt/scripts/journey-consolidation.d.mts +14 -0
  127. package/skills/tacitt/scripts/journey-consolidation.mjs +227 -0
  128. package/skills/tacitt/scripts/journey-scan-timing.mjs +143 -0
  129. package/skills/tacitt/scripts/journey-state.d.mts +43 -0
  130. package/skills/tacitt/scripts/journey-state.mjs +294 -0
  131. package/skills/tacitt/scripts/journey-tasks.d.mts +26 -0
  132. package/skills/tacitt/scripts/journey-tasks.mjs +185 -0
  133. package/skills/tacitt/scripts/journey.d.mts +40 -0
  134. package/skills/tacitt/scripts/journey.mjs +592 -0
  135. package/skills/tacitt/scripts/local-cli.d.mts +18 -0
  136. package/skills/tacitt/scripts/local-cli.mjs +116 -0
  137. package/skills/tacitt/scripts/privacy-validator.mjs +10369 -0
  138. package/skills/tacitt/scripts/review-stream-client.d.mts +22 -0
  139. package/skills/tacitt/scripts/review-stream-client.mjs +194 -0
  140. package/skills/tacitt/scripts/review.d.mts +87 -0
  141. package/skills/tacitt/scripts/review.mjs +1610 -0
  142. package/skills/tacitt/scripts/verify-cli.mjs +10 -0
@@ -0,0 +1,215 @@
1
+ import { i as errorCode } from "./model-BJdTLNjT.mjs";
2
+ import { a as titleHintLimits, i as encodeTitleError, o as titleInputSchema, t as assertTitleHeap } from "./heap-1FYhGds4.mjs";
3
+ import { stat } from "node:fs/promises";
4
+ import { isAbsolute, join } from "node:path";
5
+ import { DatabaseSync } from "node:sqlite";
6
+ import { parentPort, workerData } from "node:worker_threads";
7
+ //#region packages/harnesses/src/metadata/codex-database/files.ts
8
+ const absent = (error) => ["ENOENT", "ENOTDIR"].includes(errorCode(error) ?? "");
9
+ async function databaseFile(path) {
10
+ try {
11
+ const value = await stat(path, { bigint: true });
12
+ if (!value.isFile() || value.size > BigInt(titleHintLimits.databaseBytes)) return null;
13
+ const wal = await stat(`${path}-wal`, { bigint: true }).catch((error) => {
14
+ if (absent(error)) return null;
15
+ throw error;
16
+ });
17
+ if (wal && (!wal.isFile() || wal.size > BigInt(titleHintLimits.databaseBytes))) return null;
18
+ return value;
19
+ } catch (error) {
20
+ if (absent(error)) return null;
21
+ throw error;
22
+ }
23
+ }
24
+ async function sameDatabase(path, before) {
25
+ const after = await databaseFile(path);
26
+ return after !== null && after.dev === before.dev && after.ino === before.ino;
27
+ }
28
+ function matches(value, source) {
29
+ const expected = source.snapshot;
30
+ return value.isFile() && value.dev.toString() === expected.dev && value.ino.toString() === expected.ino && value.size === BigInt(expected.size) && value.mtimeNs.toString() === expected.mtimeNs && value.ctimeNs.toString() === expected.ctimeNs;
31
+ }
32
+ /** Textual path equality never substitutes for the actual discovered physical snapshot. */
33
+ async function boundRollout(path, source) {
34
+ if (!isAbsolute(path)) return false;
35
+ try {
36
+ const rollout = await stat(path, { bigint: true });
37
+ for (const part of source.parts) {
38
+ if (!matches(rollout, part)) continue;
39
+ if (matches(await stat(part.path, { bigint: true }), part)) return true;
40
+ }
41
+ return false;
42
+ } catch (error) {
43
+ if (absent(error)) return false;
44
+ throw error;
45
+ }
46
+ }
47
+ //#endregion
48
+ //#region packages/harnesses/src/metadata/codex-database/rows.ts
49
+ const maximum = titleHintLimits.fieldBytes;
50
+ const bounded = (column, bytes = maximum) => `CASE WHEN typeof(${column}) = 'text' AND length(CAST(${column} AS BLOB)) <= ${bytes} THEN ${column} ELSE NULL END`;
51
+ const limited = (column) => `CASE WHEN ${column} IS NULL OR (typeof(${column}) = 'text' AND length(CAST(${column} AS BLOB)) <= ${maximum}) THEN 0 ELSE 1 END`;
52
+ function requireColumns(db, table, fields) {
53
+ const columns = db.prepare(`PRAGMA table_info(${table})`).all();
54
+ const names = new Set(columns.map((row) => row["name"]));
55
+ if (fields.some((name) => !names.has(name))) throw new Error("CODEX_TITLE_SCHEMA_UNAVAILABLE");
56
+ return names;
57
+ }
58
+ function threadQuery(db) {
59
+ const name = requireColumns(db, "threads", [
60
+ "id",
61
+ "rollout_path",
62
+ "title",
63
+ "first_user_message",
64
+ "preview"
65
+ ]).has("name") ? "name" : "NULL";
66
+ return db.prepare(`SELECT id, ${bounded("rollout_path", 16384)} AS path,
67
+ CASE WHEN ${name} IS NULL OR ${name} = '' THEN 0 ELSE 1 END AS named,
68
+ ${bounded(name)} AS name, ${bounded("title")} AS title,
69
+ substr(CAST(first_user_message AS BLOB), 1, ${maximum}) AS first,
70
+ ${limited("first_user_message")} AS firstLimited,
71
+ substr(CAST(preview AS BLOB), 1, ${maximum}) AS preview,
72
+ ${limited("preview")} AS previewLimited
73
+ FROM threads WHERE id = ? LIMIT 2`);
74
+ }
75
+ function desktopQuery(db) {
76
+ requireColumns(db, "local_thread_catalog", [
77
+ "thread_id",
78
+ "host_id",
79
+ "display_title",
80
+ "missing_candidate",
81
+ "pending_observed_title"
82
+ ]);
83
+ requireColumns(db, "local_thread_catalog_hosts", ["host_id", "host_kind"]);
84
+ return db.prepare(`SELECT ${bounded("catalog.display_title")} AS title
85
+ FROM local_thread_catalog AS catalog
86
+ JOIN local_thread_catalog_hosts AS hosts ON hosts.host_id = catalog.host_id
87
+ WHERE catalog.thread_id = ? AND hosts.host_kind = 'local'
88
+ AND catalog.missing_candidate = 0 AND catalog.pending_observed_title = 0 LIMIT 9`);
89
+ }
90
+ const normalize$1 = (value) => value.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, " ").replace(/\s+/gu, " ").trim();
91
+ function displayFallback(title, source) {
92
+ if (source === null) return false;
93
+ if (!(source instanceof Uint8Array)) return true;
94
+ let message;
95
+ try {
96
+ message = normalize$1(new TextDecoder("utf-8", { fatal: true }).decode(source));
97
+ } catch {
98
+ return true;
99
+ }
100
+ const candidate = normalize$1(title).replace(/(?:\.{3}|\u2026)$/u, "").trimEnd();
101
+ return !!message && (!candidate || message.startsWith(candidate));
102
+ }
103
+ function independentTitle(row) {
104
+ if (row["firstLimited"] !== 0 || row["previewLimited"] !== 0) return null;
105
+ const value = row["title"];
106
+ if (typeof value !== "string" || !normalize$1(value)) return null;
107
+ if (displayFallback(value, row["first"]) || displayFallback(value, row["preview"])) return null;
108
+ return value;
109
+ }
110
+ function corroborates(rows, title) {
111
+ return rows.length > 0 && rows.length <= 8 && rows.every((row) => row["title"] === title);
112
+ }
113
+ //#endregion
114
+ //#region packages/harnesses/src/metadata/codex-database/read.ts
115
+ function openDatabase(path) {
116
+ const db = new DatabaseSync(path, {
117
+ readOnly: true,
118
+ timeout: 0,
119
+ allowExtension: false
120
+ });
121
+ try {
122
+ db.exec("PRAGMA query_only = ON; PRAGMA trusted_schema = OFF; PRAGMA cache_size = -4096; BEGIN");
123
+ return db;
124
+ } catch (error) {
125
+ try {
126
+ db.close();
127
+ } catch (cleanupError) {
128
+ throw new AggregateError([error, cleanupError], "CODEX_TITLE_DATABASE_UNAVAILABLE", { cause: error });
129
+ }
130
+ throw error;
131
+ }
132
+ }
133
+ function closeDatabases(databases, failure) {
134
+ const errors = [];
135
+ for (const db of databases) {
136
+ if (!db) continue;
137
+ try {
138
+ db.exec("ROLLBACK");
139
+ db.close();
140
+ } catch (error) {
141
+ errors.push(error);
142
+ try {
143
+ db.close();
144
+ } catch (cleanupError) {
145
+ errors.push(cleanupError);
146
+ }
147
+ }
148
+ }
149
+ if (errors.length) throw new AggregateError(failure === void 0 ? errors : [failure, ...errors], "CODEX_TITLE_DATABASE_CLOSE_FAILED", failure === void 0 ? void 0 : { cause: failure });
150
+ }
151
+ /** Invoked only inside the isolated title Worker in production. */
152
+ async function readDatabaseTitles(input) {
153
+ const { home, sources } = titleInputSchema.parse(input);
154
+ const byId = new Map(sources.map((source) => [source.sourceSessionId, source]));
155
+ const primaryPath = join(home, "state_5.sqlite");
156
+ const desktopPath = join(home, "sqlite", "codex-dev.db");
157
+ const primaryFile = await databaseFile(primaryPath);
158
+ if (!primaryFile) return [];
159
+ const primary = openDatabase(primaryPath);
160
+ let desktop;
161
+ let failure;
162
+ try {
163
+ const query = threadQuery(primary);
164
+ const desktopFile = await databaseFile(desktopPath);
165
+ if (desktopFile) desktop = openDatabase(desktopPath);
166
+ const legacy = desktop ? desktopQuery(desktop) : null;
167
+ const names = [];
168
+ let bytes = 2;
169
+ for (const source of sources) {
170
+ const rows = query.all(source.sourceSessionId);
171
+ const row = rows.length === 1 ? rows[0] : void 0;
172
+ if (!row || row["id"] !== source.sourceSessionId || typeof row["path"] !== "string") continue;
173
+ if (!await boundRollout(row["path"], source)) continue;
174
+ const title = row["named"] === 1 ? typeof row["name"] === "string" ? row["name"] : "" : independentTitle(row);
175
+ if (title === null) continue;
176
+ if (row["named"] !== 1 && (!legacy || !corroborates(legacy.all(source.sourceSessionId), title))) continue;
177
+ const entry = [source.sourceSessionId, title];
178
+ const next = Buffer.byteLength(JSON.stringify(entry)) + 1;
179
+ if (bytes + next > titleHintLimits.resultBytes) break;
180
+ bytes += next;
181
+ names.push(entry);
182
+ }
183
+ if (!await sameDatabase(primaryPath, primaryFile)) return [];
184
+ if (desktopFile && !await sameDatabase(desktopPath, desktopFile)) return [];
185
+ for (const [id] of names) {
186
+ const source = byId.get(id);
187
+ const row = query.get(id);
188
+ if (!source || !row || typeof row["path"] !== "string") return [];
189
+ if (!await boundRollout(row["path"], source)) return [];
190
+ }
191
+ return names;
192
+ } catch (error) {
193
+ failure = error;
194
+ throw error;
195
+ } finally {
196
+ closeDatabases([desktop, primary], failure);
197
+ }
198
+ }
199
+ //#endregion
200
+ //#region packages/harnesses/src/metadata/codex-database/worker.ts
201
+ if (!parentPort) throw new Error("CODEX_TITLE_WORKER_REQUIRED");
202
+ try {
203
+ assertTitleHeap();
204
+ parentPort.postMessage({
205
+ kind: "result",
206
+ names: await readDatabaseTitles(workerData)
207
+ });
208
+ } catch (error) {
209
+ parentPort.postMessage({
210
+ kind: "error",
211
+ error: encodeTitleError(error)
212
+ });
213
+ }
214
+ //#endregion
215
+ export {};
@@ -0,0 +1,133 @@
1
+ import { J as createConfiguredPreviewStream } from "./src-k0Ya1Bri.mjs";
2
+ import { rn as workspaceSchema, tn as sessionSchema, yn as createStaticProcessor } from "./locate-U3-nkird.mjs";
3
+ import { l as createNativeAdapters, u as createGitNameSeedProvider } from "./src-B5SArpVY.mjs";
4
+ import { ni as effectiveTreatmentSchema } from "./src-CC95LYYp.mjs";
5
+ import { a as classifyRecord, n as assertPreviewHeap, t as runPreview } from "./run-BeLHsZWb.mjs";
6
+ import { z } from "zod";
7
+ import { parentPort, workerData } from "node:worker_threads";
8
+ //#region apps/cli/src/preview/run.ts
9
+ async function runConfiguredPreview(request, cursor, processing, signal, notify) {
10
+ const source = await createConfiguredPreviewStream(request, processing, signal, (active) => {
11
+ notify({ kind: active ? "processing-start" : "processing-end" });
12
+ });
13
+ try {
14
+ let selected = /* @__PURE__ */ new Set();
15
+ let modes = [];
16
+ let ordinal = 0;
17
+ const input = {
18
+ sourceVersion: request.sourceVersion,
19
+ async *countStream(part) {
20
+ const sourceRole = source.sourceRole(part);
21
+ for await (const { text } of source.records(part, true)) yield {
22
+ kind: "record",
23
+ value: JSON.parse(text),
24
+ bytes: Buffer.byteLength(text),
25
+ sourceRole
26
+ };
27
+ },
28
+ select(summary, ordinals) {
29
+ selected = new Set(ordinals);
30
+ modes = summary.parts.map((part) => part.mode);
31
+ },
32
+ async *stream(part) {
33
+ const sourceRole = source.sourceRole(part);
34
+ const mode = modes[request.session.parts.findIndex((item) => item.id === part.id)];
35
+ if (!mode) throw new Error("PREVIEW_WITHHELD");
36
+ let retained;
37
+ const include = (text) => {
38
+ const value = JSON.parse(text);
39
+ const boundary = classifyRecord(value, request.session.harness, sourceRole);
40
+ retained = boundary;
41
+ if (mode === "event" ? boundary.eventUser : boundary.responseUser) ordinal++;
42
+ return selected.has(ordinal);
43
+ };
44
+ for await (const { text, processed } of source.records(part, false, include)) {
45
+ const value = JSON.parse(text);
46
+ if (processed) {
47
+ const boundary = classifyRecord(value, request.session.harness, sourceRole);
48
+ if (boundary.responseUser !== retained?.responseUser || boundary.eventUser !== retained.eventUser || boundary.known !== retained.known) throw new Error("PREVIEW_ENVELOPE_CHANGED");
49
+ yield {
50
+ kind: "record",
51
+ value,
52
+ bytes: Buffer.byteLength(text),
53
+ sourceRole
54
+ };
55
+ } else yield {
56
+ kind: "boundary",
57
+ ...classifyRecord(value, request.session.harness, sourceRole),
58
+ bytes: 0
59
+ };
60
+ }
61
+ },
62
+ presentation: {
63
+ records: async (records) => JSON.stringify(records),
64
+ text: async (text) => text
65
+ },
66
+ processing: () => {
67
+ const text = source.metadata();
68
+ const metadataWithheld = Buffer.byteLength(text) > 16384;
69
+ return {
70
+ kind: "configured",
71
+ configurationId: request.treatment.id,
72
+ metadata: metadataWithheld ? null : text,
73
+ metadataWithheld
74
+ };
75
+ }
76
+ };
77
+ return await runPreview(request.session, cursor, notify, input);
78
+ } finally {
79
+ await source.close();
80
+ }
81
+ }
82
+ //#endregion
83
+ //#region apps/cli/src/preview/worker.ts
84
+ const inputSchema = z.object({
85
+ request: z.object({
86
+ session: sessionSchema,
87
+ workspace: workspaceSchema,
88
+ treatment: effectiveTreatmentSchema,
89
+ customTerms: z.object({
90
+ revision: z.string().min(1).max(64),
91
+ terms: z.array(z.string().max(1024)).max(1e5)
92
+ }).optional(),
93
+ sourceVersion: z.string().regex(/^[a-f0-9]{64}$/)
94
+ }),
95
+ cursor: z.string().max(128).nullable(),
96
+ environment: z.object({
97
+ platform: z.enum(["posix", "windows"]),
98
+ userHome: z.string().optional(),
99
+ temporaryRoots: z.array(z.string())
100
+ })
101
+ });
102
+ function notify(message) {
103
+ parentPort?.postMessage(message);
104
+ }
105
+ assertPreviewHeap();
106
+ try {
107
+ const data = workerData;
108
+ const input = inputSchema.parse(data);
109
+ const environment = {
110
+ platform: input.environment.platform,
111
+ ...input.environment.userHome === void 0 ? {} : { userHome: input.environment.userHome },
112
+ temporaryRoots: input.environment.temporaryRoots
113
+ };
114
+ const processing = {
115
+ adapters: createNativeAdapters(),
116
+ gitNames: createGitNameSeedProvider(),
117
+ processor: createStaticProcessor(),
118
+ environment,
119
+ limits: { maxUnitMs: 2e3 }
120
+ };
121
+ const signal = new AbortController().signal;
122
+ notify({
123
+ kind: "result",
124
+ page: await runConfiguredPreview(input.request, input.cursor, processing, signal, notify)
125
+ });
126
+ } catch (error) {
127
+ notify({
128
+ kind: "error",
129
+ code: error instanceof Error && error.message === "PROCESSING_PROTECTED_CUSTOM_TERM" ? "PROCESSING_PROTECTED_CUSTOM_TERM" : error instanceof Error && error.message === "INVALID_PREVIEW_CURSOR" ? "INVALID_PREVIEW_CURSOR" : error instanceof Error && error.message === "PREVIEW_ENVELOPE_CHANGED" ? "PREVIEW_ENVELOPE_CHANGED" : error instanceof Error && ["SOURCE_CHANGED", "ARTIFACT_SOURCE_CHANGED"].includes(error.message) ? "SOURCE_CHANGED" : "PREVIEW_WITHHELD"
130
+ });
131
+ }
132
+ //#endregion
133
+ export {};
@@ -0,0 +1,117 @@
1
+ import { A as runConfiguredSessionJob, Q as safeError, R as gitSeedsProvider, m as captureConfiguredSessionJob, u as runConfiguredScanJob } from "./src-k0Ya1Bri.mjs";
2
+ import { yn as createStaticProcessor } from "./locate-U3-nkird.mjs";
3
+ import { l as createNativeAdapters } from "./src-B5SArpVY.mjs";
4
+ import { i as runJourneyOutputVerifyJob, n as runJourneyOutputJob, r as runJourneyOutputShardJob } from "./job-J3NFw3MH.mjs";
5
+ import { parentPort } from "node:worker_threads";
6
+ //#region apps/cli/src/configured-session-worker.ts
7
+ const port = parentPort;
8
+ const adapters = createNativeAdapters();
9
+ const processor = createStaticProcessor();
10
+ function post(message) {
11
+ port?.postMessage(message);
12
+ }
13
+ function isCaptureRequest(value) {
14
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "capture";
15
+ }
16
+ function isRenderRequest(value) {
17
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "render";
18
+ }
19
+ function isScanRequest(value) {
20
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "scan";
21
+ }
22
+ function isJourneyOutputRequest(value) {
23
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "journey-output";
24
+ }
25
+ function isJourneyOutputShardRequest(value) {
26
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "journey-output-shard";
27
+ }
28
+ function isJourneyOutputVerifyRequest(value) {
29
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "journey-output-verify";
30
+ }
31
+ function failureSourceId(error) {
32
+ let current = error;
33
+ for (let depth = 0; depth < 8 && current instanceof Error; depth++) {
34
+ const match = /configured record source=([A-Za-z0-9]+)/.exec(current.message);
35
+ if (match) return match[1];
36
+ current = current.cause;
37
+ }
38
+ }
39
+ function reportFailure(error) {
40
+ const code = safeError(error).message;
41
+ const sourceId = failureSourceId(error);
42
+ post({
43
+ kind: "error",
44
+ code,
45
+ ...sourceId === void 0 ? {} : { sourceId }
46
+ });
47
+ }
48
+ function processingFor(job) {
49
+ return {
50
+ adapters,
51
+ processor,
52
+ ..."customTerms" in job && job.customTerms ? { customTerms: job.customTerms } : {},
53
+ environment: job.environment,
54
+ ...job.limits === void 0 ? {} : { limits: job.limits },
55
+ gitNames: gitSeedsProvider("gitSeeds" in job ? job.gitSeeds : [])
56
+ };
57
+ }
58
+ port?.on("message", async (message) => {
59
+ const signal = new AbortController().signal;
60
+ try {
61
+ if (isCaptureRequest(message)) post({
62
+ kind: "result",
63
+ result: await captureConfiguredSessionJob(message.job, signal)
64
+ });
65
+ else if (isScanRequest(message)) post({
66
+ kind: "result",
67
+ result: await runConfiguredScanJob(message.job, processingFor(message.job), signal, (bytes) => post({
68
+ kind: "source",
69
+ bytes
70
+ }), (path) => post({
71
+ kind: "spool",
72
+ path
73
+ }))
74
+ });
75
+ else if (isJourneyOutputRequest(message)) post({
76
+ kind: "result",
77
+ result: await runJourneyOutputJob(message.job, {
78
+ adapters,
79
+ processor
80
+ }, signal, (path) => post({
81
+ kind: "spool",
82
+ path
83
+ }))
84
+ });
85
+ else if (isJourneyOutputShardRequest(message)) post({
86
+ kind: "result",
87
+ result: await runJourneyOutputShardJob(message.job, {
88
+ adapters,
89
+ processor
90
+ }, signal, (path) => post({
91
+ kind: "spool",
92
+ path
93
+ }))
94
+ });
95
+ else if (isJourneyOutputVerifyRequest(message)) post({
96
+ kind: "result",
97
+ result: await runJourneyOutputVerifyJob(message.job, signal)
98
+ });
99
+ else if (isRenderRequest(message)) {
100
+ const job = message.job;
101
+ post({
102
+ kind: "result",
103
+ result: await runConfiguredSessionJob(job, processingFor(job), signal, (bytes) => post({
104
+ kind: "source",
105
+ bytes
106
+ }), (path) => post({
107
+ kind: "spool",
108
+ path
109
+ }))
110
+ });
111
+ }
112
+ } catch (error) {
113
+ reportFailure(error);
114
+ }
115
+ });
116
+ //#endregion
117
+ export {};
@@ -0,0 +1,84 @@
1
+ import { nr as ProcessingError } from "./locate-U3-nkird.mjs";
2
+ //#region packages/processing/src/compression/frame.ts
3
+ function createZstdFrameCheck(fail = () => {
4
+ throw new ProcessingError("PROCESSING_INVALID_RECORD");
5
+ }) {
6
+ let stage = "magic";
7
+ let remaining = 4;
8
+ let bytes = [];
9
+ let checksum = false;
10
+ let lastBlock = false;
11
+ let frames = 0;
12
+ function next(nextStage, size) {
13
+ stage = nextStage;
14
+ remaining = size;
15
+ bytes = [];
16
+ }
17
+ function advance() {
18
+ const value = bytes.reduce((total, byte, index) => total + byte * 256 ** index, 0);
19
+ switch (stage) {
20
+ case "magic":
21
+ if (value === 4247762216) next("descriptor", 1);
22
+ else if (value >= 407710288 && value <= 407710303) next("skip-size", 4);
23
+ else fail();
24
+ break;
25
+ case "descriptor": {
26
+ if (value & 8) fail();
27
+ const single = (value & 32) !== 0;
28
+ const contentFlag = value >>> 6;
29
+ const dictionaryFlag = value & 3;
30
+ const contentSize = contentFlag === 0 ? Number(single) : 2 ** contentFlag;
31
+ const dictionarySize = dictionaryFlag === 3 ? 4 : dictionaryFlag;
32
+ checksum = (value & 4) !== 0;
33
+ next("header", Number(!single) + contentSize + dictionarySize);
34
+ break;
35
+ }
36
+ case "header":
37
+ next("block", 3);
38
+ break;
39
+ case "block": {
40
+ const kind = value >>> 1 & 3;
41
+ const size = value >>> 3;
42
+ if (kind === 3 || size > 131072) fail();
43
+ lastBlock = (value & 1) !== 0;
44
+ next("body", kind === 1 ? 1 : size);
45
+ break;
46
+ }
47
+ case "body":
48
+ if (lastBlock) next("checksum", checksum ? 4 : 0);
49
+ else next("block", 3);
50
+ break;
51
+ case "skip-size":
52
+ next("skip-body", value);
53
+ break;
54
+ case "checksum":
55
+ case "skip-body":
56
+ frames++;
57
+ next("magic", 4);
58
+ }
59
+ }
60
+ return {
61
+ push(chunk) {
62
+ let offset = 0;
63
+ const boundaries = [];
64
+ while (offset < chunk.length || remaining === 0) {
65
+ if (remaining === 0) {
66
+ const previousFrames = frames;
67
+ advance();
68
+ if (frames !== previousFrames) boundaries.push(offset);
69
+ continue;
70
+ }
71
+ const length = Math.min(remaining, chunk.length - offset);
72
+ if (stage === "magic" || stage === "descriptor" || stage === "block" || stage === "skip-size") for (const byte of chunk.subarray(offset, offset + length)) bytes.push(byte);
73
+ offset += length;
74
+ remaining -= length;
75
+ }
76
+ return boundaries;
77
+ },
78
+ finish() {
79
+ if (stage !== "magic" || remaining !== 4 || frames === 0) fail();
80
+ }
81
+ };
82
+ }
83
+ //#endregion
84
+ export { createZstdFrameCheck as t };
@@ -0,0 +1,75 @@
1
+ import { z } from "zod";
2
+ import { getHeapStatistics } from "node:v8";
3
+ //#region packages/harnesses/src/metadata/codex-database/protocol.ts
4
+ const titleHintLimits = {
5
+ milliseconds: 1e4,
6
+ candidates: 4096,
7
+ inputBytes: 16777216,
8
+ databaseBytes: 67108864,
9
+ fieldBytes: 4096,
10
+ resultBytes: 16777216
11
+ };
12
+ const nativeId = z.string().regex(/^[A-Za-z0-9._:-]{1,128}$/u);
13
+ const snapshot = z.object({
14
+ dev: z.string().max(128),
15
+ ino: z.string().max(128),
16
+ size: z.number().int().nonnegative(),
17
+ mtimeNs: z.string().max(128),
18
+ ctimeNs: z.string().max(128)
19
+ });
20
+ const titleSourceSchema = z.object({
21
+ sourceSessionId: nativeId,
22
+ parts: z.array(z.object({
23
+ path: z.string().min(1).max(16384),
24
+ snapshot
25
+ })).min(1).max(64)
26
+ });
27
+ const titleInputSchema = z.object({
28
+ home: z.string().min(1).max(16384),
29
+ sources: z.array(titleSourceSchema).max(titleHintLimits.candidates).refine((sources) => new Set(sources.map((source) => source.sourceSessionId)).size === sources.length)
30
+ });
31
+ const errorSchema = z.lazy(() => z.object({
32
+ name: z.string().max(128),
33
+ message: z.string().max(4096),
34
+ code: z.string().max(128).nullable(),
35
+ cause: errorSchema.nullable(),
36
+ errors: z.array(errorSchema).max(4)
37
+ }));
38
+ const nativeTitle = z.string().refine((value) => Buffer.byteLength(value) <= titleHintLimits.fieldBytes);
39
+ const titleReplySchema = z.discriminatedUnion("kind", [z.object({
40
+ kind: z.literal("result"),
41
+ names: z.array(z.tuple([nativeId, nativeTitle])).max(titleHintLimits.candidates)
42
+ }), z.object({
43
+ kind: z.literal("error"),
44
+ error: errorSchema
45
+ })]);
46
+ /** Only bounded error provenance crosses this private thread boundary; no stack is sent. */
47
+ function encodeTitleError(error, depth = 0) {
48
+ const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
49
+ return {
50
+ name: error instanceof Error ? error.name.slice(0, 128) : "Error",
51
+ message: error instanceof Error ? error.message.slice(0, 4096) : "Unknown title-reader failure",
52
+ code: typeof code === "string" ? code.slice(0, 128) : null,
53
+ cause: error instanceof Error && error.cause !== void 0 && depth < 4 ? encodeTitleError(error.cause, depth + 1) : null,
54
+ errors: error instanceof AggregateError && depth < 4 ? error.errors.slice(0, 4).map((value) => encodeTitleError(value, depth + 1)) : []
55
+ };
56
+ }
57
+ function decodeTitleError(value) {
58
+ const options = value.cause === null ? void 0 : { cause: decodeTitleError(value.cause) };
59
+ const error = value.errors.length ? new AggregateError(value.errors.map(decodeTitleError), value.message, options) : new Error(value.message, options);
60
+ error.name = value.name;
61
+ if (value.code !== null) Object.assign(error, { code: value.code });
62
+ return error;
63
+ }
64
+ //#endregion
65
+ //#region packages/harnesses/src/metadata/codex-database/heap.ts
66
+ const titleHeapLimits = {
67
+ maxOldGenerationSizeMb: 128,
68
+ maxYoungGenerationSizeMb: 32
69
+ };
70
+ /** This bounds V8 allocations; SQLite's native allocations are not covered. */
71
+ function assertTitleHeap(bytes = getHeapStatistics().heap_size_limit) {
72
+ if (bytes < 128 * 1024 ** 2 || bytes > 224 * 1024 ** 2) throw new Error("CODEX_TITLE_HEAP_LIMIT_INVALID");
73
+ }
74
+ //#endregion
75
+ export { titleHintLimits as a, encodeTitleError as i, titleHeapLimits as n, titleInputSchema as o, decodeTitleError as r, titleReplySchema as s, assertTitleHeap as t };