t3code-session-manager 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/.claude-plugin/marketplace.json +21 -0
  2. package/.claude-plugin/plugin.json +19 -0
  3. package/CHANGELOG.md +149 -0
  4. package/LICENSE +21 -0
  5. package/README.md +661 -2
  6. package/README.pt.md +617 -0
  7. package/bin/entry.d.mts +2 -0
  8. package/bin/entry.mjs +19 -0
  9. package/bin/t3sm.mjs +44 -0
  10. package/commands/import.md +30 -0
  11. package/commands/organize.md +36 -0
  12. package/commands/status.md +24 -0
  13. package/commands/sync.md +26 -0
  14. package/dist/apply/apply.js +993 -0
  15. package/dist/apply/claudeWriter.js +168 -0
  16. package/dist/apply/copyTranscript.js +116 -0
  17. package/dist/apply/importer.js +697 -0
  18. package/dist/apply/materialize.js +335 -0
  19. package/dist/apply/waves.js +108 -0
  20. package/dist/assistant/core.js +295 -0
  21. package/dist/assistant/deps.js +256 -0
  22. package/dist/assistant/i18n.js +38 -0
  23. package/dist/assistant/messages.en.js +494 -0
  24. package/dist/assistant/messages.pt.js +495 -0
  25. package/dist/assistant/runner.js +64 -0
  26. package/dist/assistant/steps.js +1362 -0
  27. package/dist/build.json +1 -0
  28. package/dist/cli/applyScreen.js +158 -0
  29. package/dist/cli/commands/accounts.js +254 -0
  30. package/dist/cli/commands/apply.js +199 -0
  31. package/dist/cli/commands/changelog.js +61 -0
  32. package/dist/cli/commands/doctor.js +105 -0
  33. package/dist/cli/commands/help.js +158 -0
  34. package/dist/cli/commands/merge.js +224 -0
  35. package/dist/cli/commands/organize.js +872 -0
  36. package/dist/cli/commands/plan.js +161 -0
  37. package/dist/cli/commands/projects.js +430 -0
  38. package/dist/cli/commands/quarantine.js +203 -0
  39. package/dist/cli/commands/recover.js +230 -0
  40. package/dist/cli/commands/rollback.js +281 -0
  41. package/dist/cli/commands/scan.js +117 -0
  42. package/dist/cli/commands/schedule.js +288 -0
  43. package/dist/cli/commands/start.js +45 -0
  44. package/dist/cli/commands/status.js +615 -0
  45. package/dist/cli/commands/sync.js +336 -0
  46. package/dist/cli/commands/update.js +398 -0
  47. package/dist/cli/errors.js +53 -0
  48. package/dist/cli/failures.js +91 -0
  49. package/dist/cli/flags.js +53 -0
  50. package/dist/cli/help.en.js +549 -0
  51. package/dist/cli/help.pt.js +566 -0
  52. package/dist/cli/helpText.js +211 -0
  53. package/dist/cli/helpTopics.js +58 -0
  54. package/dist/cli/locked.js +12 -0
  55. package/dist/cli/main.js +155 -0
  56. package/dist/cli/screen.js +3 -0
  57. package/dist/cli/ui.js +111 -0
  58. package/dist/cli/words.js +2 -0
  59. package/dist/core/activity.js +16 -0
  60. package/dist/core/changelog.js +47 -0
  61. package/dist/core/config.js +530 -0
  62. package/dist/core/fsutil.js +171 -0
  63. package/dist/core/glob.js +34 -0
  64. package/dist/core/history.js +32 -0
  65. package/dist/core/journal.js +274 -0
  66. package/dist/core/lock.js +337 -0
  67. package/dist/core/mask.js +31 -0
  68. package/dist/core/paths.js +68 -0
  69. package/dist/core/pid.js +101 -0
  70. package/dist/core/run.js +4 -0
  71. package/dist/core/semver.js +18 -0
  72. package/dist/core/sysroot.js +29 -0
  73. package/dist/core/types.js +229 -0
  74. package/dist/core/uuid.js +29 -0
  75. package/dist/core/version.js +72 -0
  76. package/dist/help/convert.md +20 -0
  77. package/dist/help/convert.pt.md +21 -0
  78. package/dist/help/cwd-unreadable.md +22 -0
  79. package/dist/help/cwd-unreadable.pt.md +22 -0
  80. package/dist/help/decisions.md +20 -0
  81. package/dist/help/decisions.pt.md +20 -0
  82. package/dist/help/errors.md +20 -0
  83. package/dist/help/errors.pt.md +22 -0
  84. package/dist/help/held.md +20 -0
  85. package/dist/help/held.pt.md +20 -0
  86. package/dist/help/history.md +27 -0
  87. package/dist/help/history.pt.md +29 -0
  88. package/dist/help/instance-unavailable.md +18 -0
  89. package/dist/help/instance-unavailable.pt.md +19 -0
  90. package/dist/help/not-imported.md +19 -0
  91. package/dist/help/not-imported.pt.md +19 -0
  92. package/dist/help/orphaned.md +19 -0
  93. package/dist/help/orphaned.pt.md +19 -0
  94. package/dist/help/project-mismatch.md +15 -0
  95. package/dist/help/project-mismatch.pt.md +15 -0
  96. package/dist/help/t3-native.md +22 -0
  97. package/dist/help/t3-native.pt.md +22 -0
  98. package/dist/help/updates.md +26 -0
  99. package/dist/help/updates.pt.md +28 -0
  100. package/dist/help/watcher.md +24 -0
  101. package/dist/help/watcher.pt.md +25 -0
  102. package/dist/i18n/cli.js +41 -0
  103. package/dist/i18n/lang.js +55 -0
  104. package/dist/i18n/messages.en.js +1140 -0
  105. package/dist/i18n/messages.pt.js +1149 -0
  106. package/dist/i18n/words.js +12 -0
  107. package/dist/ops/accounts.js +170 -0
  108. package/dist/ops/autoUpdate.js +223 -0
  109. package/dist/ops/discoverAccounts.js +343 -0
  110. package/dist/ops/doctor.js +811 -0
  111. package/dist/ops/elevated.js +47 -0
  112. package/dist/ops/errorCodes.js +39 -0
  113. package/dist/ops/follow.js +558 -0
  114. package/dist/ops/merge.js +830 -0
  115. package/dist/ops/notify.js +249 -0
  116. package/dist/ops/plugin.js +92 -0
  117. package/dist/ops/projects.js +113 -0
  118. package/dist/ops/quarantine.js +415 -0
  119. package/dist/ops/rollback.js +868 -0
  120. package/dist/ops/schedule.js +464 -0
  121. package/dist/ops/successor.js +51 -0
  122. package/dist/ops/sync.js +859 -0
  123. package/dist/ops/syncStatus.js +290 -0
  124. package/dist/ops/update.js +273 -0
  125. package/dist/ops/updater.js +641 -0
  126. package/dist/ops/watch.js +676 -0
  127. package/dist/ops/watcherControl.js +212 -0
  128. package/dist/ops/watcherHealth.js +75 -0
  129. package/dist/organize/apply.js +495 -0
  130. package/dist/organize/history.js +192 -0
  131. package/dist/organize/plan.js +283 -0
  132. package/dist/organize/rename.js +58 -0
  133. package/dist/organize/sessions.js +100 -0
  134. package/dist/organize/titles.js +70 -0
  135. package/dist/organize/types.js +73 -0
  136. package/dist/plan/categories.js +104 -0
  137. package/dist/plan/dedupe.js +137 -0
  138. package/dist/plan/folders.js +82 -0
  139. package/dist/plan/names.js +93 -0
  140. package/dist/plan/ownership.js +316 -0
  141. package/dist/plan/planner.js +669 -0
  142. package/dist/plan/rehome.js +101 -0
  143. package/dist/plan/report.js +407 -0
  144. package/dist/sources/cache.js +89 -0
  145. package/dist/sources/claude.js +297 -0
  146. package/dist/sources/codex.js +496 -0
  147. package/dist/sources/flatten.js +23 -0
  148. package/dist/sources/jsonl.js +169 -0
  149. package/dist/sources/native.js +233 -0
  150. package/dist/sources/opencode.js +483 -0
  151. package/dist/sources/pi.js +133 -0
  152. package/dist/sources/registry.js +67 -0
  153. package/dist/sources/types.js +80 -0
  154. package/dist/t3/api.js +492 -0
  155. package/dist/t3/auth.js +248 -0
  156. package/dist/t3/compat.js +62 -0
  157. package/dist/t3/decode.js +408 -0
  158. package/dist/t3/errors.js +185 -0
  159. package/dist/t3/rpc.js +185 -0
  160. package/dist/t3/runtime.js +80 -0
  161. package/dist/ui/caps.js +56 -0
  162. package/dist/ui/components.js +202 -0
  163. package/dist/ui/layout.js +205 -0
  164. package/dist/ui/list.js +423 -0
  165. package/dist/ui/locale.js +73 -0
  166. package/dist/ui/organizePreview.js +72 -0
  167. package/dist/ui/progress.js +237 -0
  168. package/dist/ui/style.js +32 -0
  169. package/dist/ui/terminal.js +126 -0
  170. package/dist/ui/text.js +186 -0
  171. package/package.json +58 -4
  172. package/skills/t3code-sessions/SKILL.md +183 -0
@@ -0,0 +1,408 @@
1
+ // Strict, hand-written decoders for every T3 Code response t3sm reads (wire truth: docs/spikes/S1, S2, S4).
2
+ // Rules: each decoder is `(u: unknown) => T` and throws ShapeError{endpoint, path, expected} on a missing or mistyped
3
+ // required field; unknown extra fields are allowed; values are never coerced ("2" is not 2); arrays are checked
4
+ // element by element. A nightly that changes a shape therefore stops t3sm (exit 4) before it acts on it.
5
+
6
+ import { ShapeError } from "./errors.js";
7
+
8
+
9
+
10
+ const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
11
+ const key = (p , k ) => (IDENT.test(k) ? `${p}.${k}` : `${p}[${JSON.stringify(k)}]`);
12
+ const idx = (p , i ) => `${p}[${i}]`;
13
+
14
+ const isObj = (u ) => typeof u === "object" && u !== null && !Array.isArray(u);
15
+
16
+ class D {
17
+ ep ;
18
+ constructor(endpoint ) { this.ep = endpoint; }
19
+ fail(path , expected ) { throw new ShapeError(this.ep, path, expected); }
20
+ obj(u , path ) { return isObj(u) ? u : this.fail(path, "object"); }
21
+ /** Required key (must be present) holding a string. */
22
+ str(o , k , path ) {
23
+ const v = o[k];
24
+ return typeof v === "string" ? v : this.fail(key(path, k), "string");
25
+ }
26
+ /** Required key holding string or null. */
27
+ strOrNull(o , k , path ) {
28
+ if (!(k in o)) this.fail(key(path, k), "string or null");
29
+ const v = o[k];
30
+ return v === null || typeof v === "string" ? v : this.fail(key(path, k), "string or null");
31
+ }
32
+ /** Optional key: absent -> undefined; present must be string (or null when nullable). */
33
+ optStr(o , k , path , nullable = false) {
34
+ if (!(k in o) || o[k] === undefined) return undefined;
35
+ const v = o[k];
36
+ if (typeof v === "string") return v;
37
+ if (nullable && v === null) return null;
38
+ return this.fail(key(path, k), nullable ? "string or null" : "string");
39
+ }
40
+ /**
41
+ * Optional auto-settle days (SidebarAutoSettleAfterDays): an integer 1..90, or null (off); absent -> undefined. An integer outside 1..90 (a newer T3 Code's range) is "unknown":
42
+ * the other commands go on, organize leaves the setting alone. Any other type is a shape change.
43
+ */
44
+ optAutoSettleDays(o , k , path ) {
45
+ if (!(k in o) || o[k] === undefined) return undefined;
46
+ const v = o[k];
47
+ if (v === null) return null;
48
+ if (typeof v !== "number" || !Number.isInteger(v)) return this.fail(key(path, k), "integer 1..90 or null");
49
+ return v >= 1 && v <= 90 ? v : "unknown";
50
+ }
51
+ /**
52
+ * Optional key holding one of the given strings or null; absent -> null. Another string (a value a newer T3 Code
53
+ * added) -> "unknown"; any other type is a shape change.
54
+ */
55
+ optEnumOrUnknown (o , k , path , allowed ) {
56
+ if (!(k in o) || o[k] === undefined || o[k] === null) return null;
57
+ const v = o[k];
58
+ if (typeof v !== "string") return this.fail(key(path, k), `one of ${allowed.join(", ")}, another string or null`);
59
+ return (allowed ).includes(v) ? (v ) : "unknown";
60
+ }
61
+ bool(o , k , path ) {
62
+ const v = o[k];
63
+ return typeof v === "boolean" ? v : this.fail(key(path, k), "boolean");
64
+ }
65
+ optBool(o , k , path ) {
66
+ if (!(k in o) || o[k] === undefined) return undefined;
67
+ return this.bool(o, k, path);
68
+ }
69
+ /** Non-negative integer. */
70
+ count(o , k , path ) {
71
+ const v = o[k];
72
+ return typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : this.fail(key(path, k), "non-negative integer");
73
+ }
74
+ arr (o , k , path , el ) {
75
+ const v = o[k];
76
+ const p = key(path, k);
77
+ if (!Array.isArray(v)) return this.fail(p, "array");
78
+ return v.map((x, i) => el(x, idx(p, i)));
79
+ }
80
+ }
81
+
82
+ // ---------- environment ----------
83
+
84
+
85
+
86
+ /** GET /.well-known/t3/environment (S1 §1). */
87
+ export function decodeEnvironment(u ) {
88
+ const d = new D("GET /.well-known/t3/environment");
89
+ const o = d.obj(u, "$");
90
+ const serverVersion = d.str(o, "serverVersion", "$");
91
+ const v = o.orchestrationProtocolVersion;
92
+ if (typeof v !== "number" || !Number.isInteger(v)) return d.fail("$.orchestrationProtocolVersion", "integer");
93
+ return { serverVersion, orchestrationProtocolVersion: v };
94
+ }
95
+
96
+ // ---------- projects ----------
97
+
98
+ /** `{instanceId, model, options?}` on the wire; legacy `{provider, model}` is accepted too (S1 §6). Returned untouched. */
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ function modelSelection(d , u , path ) {
110
+ const o = d.obj(u, path);
111
+ d.str(o, "model", path);
112
+ if ("instanceId" in o) d.str(o, "instanceId", path);
113
+ else d.str(o, "provider", path);
114
+ return o ;
115
+ }
116
+
117
+ function project(d , u , path ) {
118
+ const o = d.obj(u, path);
119
+ const id = d.str(o, "id", path);
120
+ const title = d.str(o, "title", path);
121
+ const workspaceRoot = d.str(o, "workspaceRoot", path);
122
+ if (!("defaultModelSelection" in o)) d.fail(key(path, "defaultModelSelection"), "model selection or null");
123
+ const sel = o.defaultModelSelection;
124
+ if (sel !== null && !isObj(sel)) d.fail(key(path, "defaultModelSelection"), "model selection or null");
125
+ const defaultModelSelection = sel === null ? null : modelSelection(d, sel, key(path, "defaultModelSelection"));
126
+ const archivedAt = d.optStr(o, "archivedAt", path, true) ?? null;
127
+ const deletedAt = d.optStr(o, "deletedAt", path, true) ?? null;
128
+ const pinnedAt = d.optStr(o, "pinnedAt", path, true) ?? null;
129
+ const createdAt = d.optStr(o, "createdAt", path, true) ?? null;
130
+ return { id, title, workspaceRoot, defaultModelSelection, archived: archivedAt !== null, deleted: deletedAt !== null, pinned: pinnedAt !== null, createdAt };
131
+ }
132
+
133
+ /** GET /api/projects -> `{projects: Project[], updatedAt}`. */
134
+ export function decodeProjects(u ) {
135
+ const d = new D("GET /api/projects");
136
+ const o = d.obj(u, "$");
137
+ return d.arr(o, "projects", "$", (x, p) => project(d, x, p));
138
+ }
139
+
140
+ /** One `Project` (POST /api/projects/mutate success). */
141
+ export function decodeProject(u , endpoint = "POST /api/projects/mutate") {
142
+ return project(new D(endpoint), u, "$");
143
+ }
144
+
145
+ // ---------- shell ----------
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ const NATIVE_THREAD_RE = /:native-thread:(.+)$/s;
180
+
181
+ function shellThread(d , u , path , inArchived ) {
182
+ const o = d.obj(u, path);
183
+ const id = d.str(o, "id", path);
184
+ const projectId = d.str(o, "projectId", path);
185
+ const title = d.str(o, "title", path);
186
+ const instanceId = d.str(o, "providerInstanceId", path); // ProviderInstanceId: never null in OrchestrationV2ThreadShell
187
+ const archivedAt = d.strOrNull(o, "archivedAt", path);
188
+ const ref = d.optStr(o, "activeProviderThreadId", path, true);
189
+ const nativeSessionId = typeof ref === "string" ? (NATIVE_THREAD_RE.exec(ref)?.[1] ?? null) : null;
190
+ const latestUserMessageAt = d.optStr(o, "latestUserMessageAt", path, true) ?? null;
191
+ const settledOverride = d.optEnumOrUnknown(o, "settledOverride", path, ["settled", "active"] );
192
+ const settledAt = d.optStr(o, "settledAt", path, true) ?? null;
193
+ const unsettledAt = d.optStr(o, "unsettledAt", path, true) ?? null;
194
+ const pinnedAt = d.optStr(o, "pinnedAt", path, true) ?? null;
195
+ const latestRunRequestedAt = d.optStr(o, "latestRunRequestedAt", path, true);
196
+ const latestRunStartedAt = d.optStr(o, "latestRunStartedAt", path, true);
197
+ const latestRunCompletedAt = d.optStr(o, "latestRunCompletedAt", path, true);
198
+ const createdAt = d.optStr(o, "createdAt", path, true);
199
+ return {
200
+ id, projectId, instanceId, archived: inArchived || archivedAt !== null, title, nativeSessionId, latestUserMessageAt, settledOverride, settledAt, unsettledAt, pinnedAt,
201
+ latestRunRequestedAt, latestRunStartedAt, latestRunCompletedAt, createdAt,
202
+ };
203
+ }
204
+
205
+ /**
206
+ * GET /api/orchestration/shell (protocol 2). The server hard-codes `archivedThreads: []` here (ShellStream.ts), so this
207
+ * yields active threads only; archived ones come from decodeArchivedShell.
208
+ */
209
+ /**
210
+ * Paging fields a thread list could grow. t3sm reads both thread lists as complete (a session T3 holds no thread of
211
+ * is "orphaned" and copied back), so a list that says it continues elsewhere is an unknown shape, never a partial read.
212
+ */
213
+ const PAGING_FIELDS = ["hasMore", "nextCursor", "nextPageToken", "pageToken", "continuationToken", "truncated", "pageInfo"] ;
214
+ function completeList(d , o ) {
215
+ for (const k of PAGING_FIELDS) {
216
+ const v = o[k];
217
+ if (v !== undefined && v !== null && v !== false) d.fail(`$.${k}`, "absent (t3sm reads the thread list as one complete page)");
218
+ }
219
+ }
220
+
221
+ export function decodeShell(u ) {
222
+ const d = new D("GET /api/orchestration/shell");
223
+ const o = d.obj(u, "$");
224
+ if (o.schemaVersion !== 2) d.fail("$.schemaVersion", "2");
225
+ completeList(d, o);
226
+ const active = d.arr(o, "threads", "$", (x, p) => shellThread(d, x, p, false));
227
+ const archived = d.arr(o, "archivedThreads", "$", (x, p) => shellThread(d, x, p, true));
228
+ return [...active, ...archived];
229
+ }
230
+
231
+ /** orchestration.getArchivedShellSnapshot -> `{schemaVersion, snapshotSequence, projects, threads}`; every thread is archived. */
232
+ export function decodeArchivedShell(u ) {
233
+ const d = new D("orchestration.getArchivedShellSnapshot");
234
+ const o = d.obj(u, "$");
235
+ if (o.schemaVersion !== 2) d.fail("$.schemaVersion", "2");
236
+ completeList(d, o);
237
+ d.count(o, "snapshotSequence", "$");
238
+ return d.arr(o, "threads", "$", (x, p) => shellThread(d, x, p, true));
239
+ }
240
+
241
+ // ---------- server config / settings ----------
242
+
243
+
244
+ /** A `settings.providerInstances` entry, returned as the raw object (extra fields kept) after validation. */
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+ function instanceEntry(d , u , path ) {
274
+ const o = d.obj(u, path);
275
+ d.str(o, "driver", path);
276
+ d.optStr(o, "displayName", path);
277
+ d.optStr(o, "accentColor", path);
278
+ d.optBool(o, "enabled", path);
279
+ if ("environment" in o && o.environment !== undefined) {
280
+ d.arr(o, "environment", path, (x, p) => {
281
+ const e = d.obj(x, p);
282
+ d.str(e, "name", p);
283
+ if (!("value" in e)) d.fail(key(p, "value"), "string or secret reference");
284
+ d.bool(e, "sensitive", p);
285
+ return e;
286
+ });
287
+ }
288
+ return o ;
289
+ }
290
+
291
+ function instanceMap(d , o , path ) {
292
+ const m = o.providerInstances;
293
+ const p = key(path, "providerInstances");
294
+ if (!isObj(m)) return d.fail(p, "object map");
295
+ for (const [k, v] of Object.entries(m)) instanceEntry(d, v, key(p, k));
296
+ return m ;
297
+ }
298
+
299
+ function provider(d , u , path ) {
300
+ // Field optionality follows ServerProvider (packages/contracts/src/server.ts); a valid but degraded state
301
+ // (unavailable instance, no continuation, no displayName) must never stop t3sm.
302
+ const o = d.obj(u, path);
303
+ const instanceId = d.str(o, "instanceId", path);
304
+ const driver = d.str(o, "driver", path);
305
+ const displayName = (d.optStr(o, "displayName", path) ) ?? null;
306
+ const enabled = d.bool(o, "enabled", path);
307
+ const accentColor = d.optStr(o, "accentColor", path, true) ?? null;
308
+ let availability = "available";
309
+ if ("availability" in o && o.availability !== undefined) {
310
+ if (o.availability !== "available" && o.availability !== "unavailable") d.fail(key(path, "availability"), '"available" or "unavailable"');
311
+ availability = o.availability;
312
+ }
313
+ let continuation = null;
314
+ if ("continuation" in o && o.continuation !== undefined) {
315
+ const c = d.obj(o.continuation, key(path, "continuation"));
316
+ continuation = { groupKey: d.str(c, "groupKey", key(path, "continuation")) };
317
+ }
318
+ let runtimeHomePath = null;
319
+ if ("runtimePaths" in o && o.runtimePaths !== undefined) {
320
+ const r = d.obj(o.runtimePaths, key(path, "runtimePaths"));
321
+ runtimeHomePath = d.str(r, "homePath", key(path, "runtimePaths"));
322
+ }
323
+ const a = d.obj(o.auth, key(path, "auth"));
324
+ const auth = { status: d.str(a, "status", key(path, "auth")), email: d.optStr(a, "email", key(path, "auth"), true) ?? null };
325
+ const models = d.arr(o, "models", path, (x, p) => {
326
+ const m = d.obj(x, p);
327
+ return { slug: d.str(m, "slug", p), isDefault: d.optBool(m, "isDefault", p) ?? false };
328
+ });
329
+ return { instanceId, driver, displayName, enabled, accentColor, availability, continuation, runtimeHomePath, auth, models };
330
+ }
331
+
332
+ /** server.getConfig success value (S1 §5). Only the parts t3sm reads are checked; `settings.providerInstances` entries stay raw. */
333
+ export function decodeConfig(u ) {
334
+ const d = new D("server.getConfig");
335
+ const o = d.obj(u, "$");
336
+ const s = d.obj(o.settings, "$.settings");
337
+ const providerInstances = instanceMap(d, s, "$.settings");
338
+ const settings = { providerInstances };
339
+ const days = d.optAutoSettleDays(s, "sidebarAutoSettleAfterDays", "$.settings");
340
+ if (days === "unknown") settings.sidebarAutoSettleUnknown = true;
341
+ else if (days !== undefined) settings.sidebarAutoSettleAfterDays = days;
342
+ if ("defaultModelSelection" in s && s.defaultModelSelection !== undefined) {
343
+ settings.defaultModelSelection = s.defaultModelSelection === null ? null : modelSelection(d, s.defaultModelSelection, "$.settings.defaultModelSelection");
344
+ }
345
+ const providers = d.arr(o, "providers", "$", (x, p) => provider(d, x, p));
346
+ return { settings, providers };
347
+ }
348
+
349
+ /** server.updateSettings success value: the full ServerSettings; t3sm checks `providerInstances` (S4 §1). */
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+ export function decodeServerSettings(u ) {
358
+ const d = new D("server.updateSettings");
359
+ const o = d.obj(u, "$");
360
+ const out = { providerInstances: instanceMap(d, o, "$") };
361
+ const days = d.optAutoSettleDays(o, "sidebarAutoSettleAfterDays", "$");
362
+ if (days === "unknown") out.sidebarAutoSettleUnknown = true;
363
+ else if (days !== undefined) out.sidebarAutoSettleAfterDays = days;
364
+ return out;
365
+ }
366
+
367
+ // ---------- agentSessions ----------
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+ /** agentSessions.scan -> `{candidates, scannedAt, truncated?: true}` (S1 §5). */
376
+ export function decodeScan(u ) {
377
+ const d = new D("agentSessions.scan");
378
+ const o = d.obj(u, "$");
379
+ const candidates = d.arr(o, "candidates", "$", (x, p) => {
380
+ const c = d.obj(x, p);
381
+ return {
382
+ path: d.str(c, "path", p),
383
+ title: d.str(c, "title", p),
384
+ projectId: (d.optStr(c, "projectId", p) ) ?? null,
385
+ sources: d.arr(c, "sources", p, (s, sp) => (typeof s === "string" ? s : d.fail(sp, "string"))),
386
+ threadCount: d.count(c, "threadCount", p),
387
+ lastActiveAt: d.strOrNull(c, "lastActiveAt", p),
388
+ alreadyImported: d.bool(c, "alreadyImported", p),
389
+ };
390
+ });
391
+ const scannedAt = d.str(o, "scannedAt", "$");
392
+ const truncated = d.optBool(o, "truncated", "$") ?? false;
393
+ return { candidates, scannedAt, truncated };
394
+ }
395
+
396
+ /** agentSessions.import -> `{importedCount, skippedCount}` (non-negative integers). */
397
+ export function decodeImport(u ) {
398
+ const d = new D("agentSessions.import");
399
+ const o = d.obj(u, "$");
400
+ return { importedCount: d.count(o, "importedCount", "$"), skippedCount: d.count(o, "skippedCount", "$") };
401
+ }
402
+
403
+ /** orchestration.dispatchCommand -> `{sequence}` (S1 addendum). */
404
+ export function decodeDispatch(u ) {
405
+ const d = new D("orchestration.dispatchCommand");
406
+ const o = d.obj(u, "$");
407
+ return { sequence: d.count(o, "sequence", "$") };
408
+ }
@@ -0,0 +1,185 @@
1
+ // Typed errors for everything that talks to T3 Code. Messages never carry tokens or tickets.
2
+
3
+ const MAX_SECRETS = 64;
4
+ const MAX_TEXT = 8192;
5
+ /**
6
+ * The exact-value pass (split/join per registered secret) is O(input x secrets). Its input is cut to 1 MiB first so a huge
7
+ * WebSocket failure payload stays cheap. Output is truncated to MAX_TEXT anyway, so nothing past 1 MiB is ever shown.
8
+ */
9
+ export const MAX_EXACT_SCAN = 1024 * 1024;
10
+ const secrets = new Map (); // LRU, insertion-ordered: oldest evicted first (tickets, misc)
11
+ const pinned = new Set (); // active session tokens: never evicted until unregisterSecret
12
+
13
+ /** Register an exact secret value so redact() removes it wherever it appears. Tickets and the like live in a 64-entry LRU. */
14
+ export function registerSecret(s ) {
15
+ if (typeof s !== "string" || s.length < 8 || pinned.has(s)) return;
16
+ secrets.delete(s);
17
+ secrets.set(s, true);
18
+ while (secrets.size > MAX_SECRETS) secrets.delete(secrets.keys().next().value );
19
+ }
20
+
21
+ /** Pin a session token: it is redacted until unregisterSecret, whatever else is registered meanwhile. */
22
+ export function pinSecret(s ) {
23
+ if (typeof s !== "string" || s.length < 8) return;
24
+ secrets.delete(s);
25
+ pinned.add(s);
26
+ }
27
+
28
+ export function unregisterSecret(s ) {
29
+ secrets.delete(s);
30
+ pinned.delete(s);
31
+ }
32
+
33
+ // Narrow, linear patterns: safe for structured data too.
34
+ const NARROW = [
35
+ /Bearer\s+\S+/gi,
36
+ /wsTicket=[^&\s]+/g,
37
+ /token["']?\s*[:=]\s*["']?[A-Za-z0-9._~+/=-]{16,}/gi,
38
+ /eyJ[A-Za-z0-9_\-.]{8,}/g,
39
+ ];
40
+ const LONG_RUN = /[A-Za-z0-9_-]{32,}/g;
41
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
42
+
43
+ function strip(s ) {
44
+ let out = s.length > MAX_EXACT_SCAN ? s.slice(0, MAX_EXACT_SCAN) : s;
45
+ // exact values first, before the MAX_TEXT cut (on up to MAX_EXACT_SCAN chars), so a secret straddling the cut cannot survive
46
+ for (const v of pinned) if (out.includes(v)) out = out.split(v).join("<redacted>");
47
+ for (const v of secrets.keys()) if (out.includes(v)) out = out.split(v).join("<redacted>");
48
+ if (out.length > MAX_TEXT) out = `${out.slice(0, MAX_TEXT)}...`;
49
+ for (const p of NARROW) out = out.replace(p, "<redacted>");
50
+ return out;
51
+ }
52
+
53
+ /** Free-text redaction (messages, stderr): registered values, narrow patterns, and long token-like runs that contain a digit and are not UUIDs. */
54
+ export function redact(s ) {
55
+ return strip(s).replace(LONG_RUN, (m) => (/\d/.test(m) && !UUID.test(m) ? "<redacted>" : m));
56
+ }
57
+
58
+ /** Structured-data redaction (RpcError.cause): registered values and narrow patterns only, so ids and file names survive. */
59
+ export function redactStructured(s ) {
60
+ return strip(s);
61
+ }
62
+
63
+ function errorTagOf(cause ) {
64
+ if (cause && typeof cause === "object" && typeof (cause )._tag === "string") return (cause )._tag;
65
+ return null;
66
+ }
67
+
68
+ function causeMessage(cause ) {
69
+ if (typeof cause === "string") return cause;
70
+ if (cause && typeof cause === "object") {
71
+ const o = cause ;
72
+ if (typeof o.message === "string") return o.message;
73
+ if (typeof o.defect === "string") return o.defect;
74
+ if (o.defect && typeof o.defect === "object" && typeof (o.defect ).message === "string") return (o.defect ).message;
75
+ }
76
+ return "";
77
+ }
78
+
79
+ export class T3AuthError extends Error {
80
+ hint ;
81
+ /** No `detail`: auth CLI failures never carry child stdout/stderr in any field. */
82
+ constructor(message , opts = {}) {
83
+ super(redact(message));
84
+ this.name = "T3AuthError";
85
+ this.hint = opts.hint ?? null;
86
+ }
87
+ }
88
+
89
+ export class T3NotRunning extends Error {
90
+ constructor(message = "T3 Code is not running") {
91
+ super(message);
92
+ this.name = "T3NotRunning";
93
+ }
94
+ }
95
+
96
+ /** The server answered a call with a failure. `cause` is the typed error (or defect) from the wire. */
97
+ export class RpcError extends Error {
98
+ tag ;
99
+
100
+ constructor(tag , cause ) {
101
+ const et = errorTagOf(cause);
102
+ const m = causeMessage(cause);
103
+ super(redact(`${tag} failed${et ? `: ${et}` : ""}${m ? `: ${m}` : ""}`));
104
+ this.name = "RpcError";
105
+ this.tag = tag;
106
+ this.cause = redactDeep(cause);
107
+ }
108
+ get errorTag() { return errorTagOf(this.cause); }
109
+ }
110
+
111
+ export class RpcTimeout extends Error {
112
+ tag ;
113
+ timeoutMs ;
114
+ constructor(tag , timeoutMs ) {
115
+ super(`${tag} timed out after ${timeoutMs} ms`);
116
+ this.name = "RpcTimeout";
117
+ this.tag = tag;
118
+ this.timeoutMs = timeoutMs;
119
+ }
120
+ }
121
+
122
+ export class RpcClosed extends Error {
123
+ constructor(message = "connection to T3 Code closed") {
124
+ super(redact(message));
125
+ this.name = "RpcClosed";
126
+ }
127
+ }
128
+
129
+ function redactDeep(v , depth = 0) {
130
+ if (typeof v === "string") return redactStructured(v);
131
+ if (v === null || typeof v !== "object") return typeof v === "function" ? undefined : v;
132
+ if (depth > 12) return "<truncated>";
133
+ if (Array.isArray(v)) return v.map((x) => redactDeep(x, depth + 1));
134
+ const out = {};
135
+ for (const [k, x] of Object.entries(v)) out[k] = redactDeep(x, depth + 1);
136
+ return out;
137
+ }
138
+
139
+ /**
140
+ * A T3 response did not have the shape t3sm was built against (a nightly changed it). Exit 4, before any write.
141
+ * The message names endpoint, JSON path and expected type only: never the offending value.
142
+ */
143
+ export class ShapeError extends Error {
144
+ exitCode = 4;
145
+ endpoint ;
146
+ path ;
147
+ expected ;
148
+ constructor(endpoint , path , expected ) {
149
+ super(`unexpected T3 Code response shape from ${endpoint} at ${path}: expected ${expected}`);
150
+ this.name = "ShapeError";
151
+ this.endpoint = endpoint;
152
+ this.path = path;
153
+ this.expected = expected;
154
+ }
155
+ }
156
+
157
+ /** The running T3 Code speaks another orchestration protocol (an untested version only warns). Exit 4. */
158
+ export class T3Incompatible extends Error {
159
+ exitCode = 4;
160
+ version ;
161
+ constructor(version , message ) {
162
+ super(redact(message));
163
+ this.name = "T3Incompatible";
164
+ this.version = version;
165
+ }
166
+ }
167
+
168
+ /** An HTTP call to T3 Code failed: non-2xx (`status`) or no response at all (`status` null). Carries T3's error tag/code/reason, never the token. */
169
+ export class T3HttpError extends Error {
170
+ endpoint ;
171
+ status ;
172
+ errorTag ;
173
+ code ;
174
+ reason ;
175
+ constructor(endpoint , status , detail = {}) {
176
+ const bits = [detail.errorTag, detail.code, detail.reason].filter((x) => typeof x === "string" && x !== "");
177
+ super(redact(`${endpoint} ${status === null ? `failed: ${detail.message ?? "no response"}` : `returned HTTP ${status}`}${bits.length ? ` (${bits.join(", ")})` : ""}`));
178
+ this.name = "T3HttpError";
179
+ this.endpoint = endpoint;
180
+ this.status = status;
181
+ this.errorTag = detail.errorTag ?? null;
182
+ this.code = detail.code ?? null;
183
+ this.reason = detail.reason ?? null;
184
+ }
185
+ }