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,248 @@
1
+ import { spawn, spawnSync, } from "node:child_process";
2
+ import { registerSecret, pinSecret, unregisterSecret, T3AuthError } from "./errors.js";
3
+ import { parseLocalOrigin } from "./runtime.js";
4
+ import { system32 } from "../core/sysroot.js";
5
+
6
+
7
+
8
+
9
+
10
+ const MAX_CAPTURE = 1024 * 1024; // per stream
11
+
12
+ function quoteWin(s ) {
13
+ return `"${s.replace(/"/g, '""')}"`;
14
+ }
15
+
16
+ /**
17
+ * How long win32's `taskkill /T /F` may take before it is given up. On a loaded machine, starting taskkill.exe and
18
+ * walking the tree took over 8 s (16 test suites at once on 24 cores); a 5 s budget stopped taskkill first, child.kill()
19
+ * then ended cmd.exe alone and the grandchild was left running. Only the timeout and exit paths wait for it.
20
+ */
21
+ export const TASKKILL_TIMEOUT_MS = 30_000;
22
+
23
+ /**
24
+ * Kill the child and its whole tree, synchronously (it must also work inside a process `exit` handler).
25
+ * POSIX: the child leads its own (detached) group, so the group gets SIGKILL. win32: `taskkill /T /F` must run while
26
+ * the child still exists, so child.kill() only follows it.
27
+ *
28
+ * Trade-off, on purpose: win32's spawnSync blocks this process's event loop until taskkill returns, up to
29
+ * TASKKILL_TIMEOUT_MS. That is what makes the kill work in an `exit` handler (nothing asynchronous runs there) and what
30
+ * keeps the tree from outliving a timeout. The cost: in the watcher, a notifier or `t3` call that times out blocks the
31
+ * loop for as long as taskkill takes (usually well under a second; seconds on a loaded machine), and a stop request
32
+ * arriving meanwhile is answered only afterwards (stopWatcher waits 30 s for it before it falls back to the verified pid).
33
+ */
34
+ function killTree(child ) {
35
+ if (child.exitCode !== null || child.signalCode !== null) return;
36
+ const plain = () => { try { child.kill(); } catch { /* ignore */ } };
37
+ if (child.pid === undefined) return plain();
38
+ if (process.platform !== "win32") {
39
+ try { process.kill(-child.pid, "SIGKILL"); } catch { plain(); }
40
+ return;
41
+ }
42
+ try { spawnSync(system32(process.env, "taskkill.exe"), ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: TASKKILL_TIMEOUT_MS }); } catch { /* ignore */ }
43
+ plain();
44
+ }
45
+
46
+ /** The parts of `process` the child cleanup needs (injectable for tests). */
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ const running = new Set (); // kill functions of children still running
56
+ let hooks = null;
57
+
58
+ function uninstall() {
59
+ if (!hooks) return;
60
+ const { proc, onExit, onSignal } = hooks;
61
+ hooks = null;
62
+ proc.off("exit", onExit);
63
+ proc.off("SIGINT", onSignal);
64
+ proc.off("SIGTERM", onSignal);
65
+ }
66
+
67
+ function killAll() {
68
+ const all = [...running];
69
+ running.clear();
70
+ for (const k of all) { try { k(); } catch { /* keep killing the others */ } }
71
+ uninstall();
72
+ }
73
+
74
+ /**
75
+ * Track a running child so Ctrl+C, SIGTERM or process exit cannot orphan it. Handlers are installed once, lazily, only
76
+ * while at least one child runs, and removed when the set empties. After a signal kills the children, the signal is
77
+ * re-raised on ourselves (now with no listener of ours) so the default behaviour still happens: Ctrl+C is not swallowed.
78
+ * If another SIGINT/SIGTERM listener exists it already received this signal and owns the decision, so we do not re-raise.
79
+ * Returns an idempotent untrack function.
80
+ */
81
+ export function trackChild(kill , proc = process ) {
82
+ running.add(kill);
83
+ if (!hooks) {
84
+ const onExit = () => killAll();
85
+ const onSignal = (sig ) => {
86
+ killAll();
87
+ if (proc.listenerCount(sig) === 0) proc.kill(proc.pid, sig);
88
+ };
89
+ hooks = { proc, onExit, onSignal };
90
+ proc.on("exit", onExit);
91
+ proc.on("SIGINT", onSignal);
92
+ proc.on("SIGTERM", onSignal);
93
+ }
94
+ return () => {
95
+ running.delete(kill);
96
+ if (running.size === 0) uninstall();
97
+ };
98
+ }
99
+
100
+ /**
101
+ * Runs a CLI. For .cmd/.bat (shell:true) the path travels in the child env as T3SM_CLI and the command line is
102
+ * `"%T3SM_CLI%" <quoted constant args>`: cmd expands the variable once, so `&`, `^`, `%` or spaces in the path
103
+ * can neither break nor inject anything. The timeout settles from the timer and kills the whole process tree.
104
+ */
105
+ export const defaultRunner = (file, args, opts) =>
106
+ new Promise((res) => {
107
+ let child ;
108
+ try {
109
+ child = opts.shell
110
+ ? spawn(`"%T3SM_CLI%" ${args.map(quoteWin).join(" ")}`, { shell: true, env: { ...opts.env, T3SM_CLI: file }, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] })
111
+ : spawn(file, args, { env: opts.env, windowsHide: true, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "pipe"] });
112
+ } catch {
113
+ res({ code: null, stdout: "", stderr: "spawn failed", timedOut: false });
114
+ return;
115
+ }
116
+ let stdout = "", stderr = "", done = false;
117
+ const untrack = trackChild(() => killTree(child));
118
+ const finish = (code , timedOut ) => {
119
+ if (done) return;
120
+ done = true;
121
+ clearTimeout(timer);
122
+ untrack();
123
+ res({ code, stdout, stderr, timedOut });
124
+ };
125
+ const timer = setTimeout(() => { killTree(child); finish(null, true); }, opts.timeoutMs);
126
+ child.stdout .on("data", (d ) => { if (stdout.length < MAX_CAPTURE) stdout += d.toString("utf8", 0, MAX_CAPTURE - stdout.length); });
127
+ child.stderr .on("data", (d ) => { if (stderr.length < MAX_CAPTURE) stderr += d.toString("utf8", 0, MAX_CAPTURE - stderr.length); });
128
+ child.on("error", () => finish(null, false));
129
+ child.on("close", (code) => finish(code, false));
130
+ });
131
+
132
+ /**
133
+ * Default least-privilege scopes (S1 2.1: `--scope` REPLACES the default 16-permission set). No settings:write by default:
134
+ * instance changes send an empty patch with a providerInstanceMutation, which needs providers:manage alone
135
+ * (RpcAuthorization.ts 244-250). Add "providers:manage" only for instance mutations, and "settings:write" only for a
136
+ * connection that changes one of T3 Code's own settings (`connectT3`'s writeSettings: organize's auto-settle change and
137
+ * its undo; T3 Code refuses a settings patch without it).
138
+ */
139
+ export const DEFAULT_SCOPES = ["orchestration:read", "orchestration:operate"] ;
140
+
141
+ function childEnv() {
142
+ const env = {};
143
+ for (const [k, v] of Object.entries(process.env)) {
144
+ if (v === undefined) continue;
145
+ if (k.toUpperCase() === "CLAUDE_CONFIG_DIR") continue; // never leak an account home into T3's CLI (env-inheritance incident class)
146
+ env[k] = v;
147
+ }
148
+ return env;
149
+ }
150
+
151
+ /** Shell only for .cmd/.bat on Windows; the path must be safe to put inside one pair of double quotes. */
152
+ function useShell(cli ) {
153
+ if (process.platform !== "win32" || !/\.(cmd|bat)$/i.test(cli)) return false;
154
+ if (/["\r\n\0!]/.test(cli)) throw new T3AuthError("refusing to run a CLI path containing quotes, '!' or control characters");
155
+ return true;
156
+ }
157
+
158
+ const SCOPE_RE = /^[a-z][a-z0-9]*:[a-z][A-Za-z0-9]*$/;
159
+ const SESSION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{7,79}$/;
160
+ /**
161
+ * Auth CLI failures (issue and revoke) never carry the child's stdout or stderr in any field: a failed issue may still
162
+ * print the token, and no scrubbing heuristic is reliable for every token shape. The user reruns the command to see why.
163
+ */
164
+ const FAIL_HINT = "Run `t3 auth session issue --token-only` yourself to see T3's message.";
165
+ /** The command to run by hand for a failed `t3 auth session <what>` (the revoke hint names revoke, not issue). */
166
+ const hintFor = (what , sessionId ) =>
167
+ what === "revoke" ? `Run \`t3 auth session revoke -- ${sessionId ?? "<session id>"}\` yourself to see T3's message (the session expires on its own within 1 h).` : FAIL_HINT;
168
+ const failed = (what , code , sessionId ) => {
169
+ const hint = hintFor(what, sessionId);
170
+ return new T3AuthError(`\`t3 auth session ${what}\` failed (exit ${code}). ${hint}`, { hint });
171
+ };
172
+ const timedOut = (what , sessionId ) => {
173
+ const hint = hintFor(what, sessionId);
174
+ return new T3AuthError(`\`t3 auth session ${what}\` timed out after 30 s. ${hint}`, { hint });
175
+ };
176
+
177
+
178
+
179
+
180
+ function parseIssueJson(stdout ) {
181
+ const t = stdout.trim();
182
+ try { return JSON.parse(t); } catch { /* fall through */ }
183
+ const a = t.indexOf("{"), b = t.lastIndexOf("}");
184
+ if (a >= 0 && b > a) { try { return JSON.parse(t.slice(a, b + 1)); } catch { /* fall through */ } }
185
+ return null;
186
+ }
187
+
188
+ /** `t3 auth session issue --json` -> {token, sessionId}. Caller should revokeSession(sessionId, token) when done. */
189
+ export async function issueSessionToken(cli , opts = {}) {
190
+ const run = opts.run ?? defaultRunner;
191
+ const scopes = opts.scopes ?? DEFAULT_SCOPES;
192
+ for (const s of scopes) if (!SCOPE_RE.test(s)) throw new T3AuthError("invalid scope requested");
193
+ const shell = useShell(cli);
194
+ const args = ["auth", "session", "issue", "--json", "--label", "t3sm", "--ttl", "1h", ...scopes.flatMap((s) => ["--scope", s])];
195
+ const r = await run(cli, args, { shell, timeoutMs: 30_000, env: childEnv() });
196
+ if (r.timedOut) throw timedOut("issue");
197
+ if (r.code !== 0) throw failed("issue", r.code);
198
+ const parsed = parseIssueJson(r.stdout) ;
199
+ const token = parsed && typeof parsed.token === "string" && parsed.token && !/\s/.test(parsed.token) ? parsed.token : null;
200
+ const sessionId = parsed && typeof parsed.sessionId === "string" && SESSION_ID_RE.test(parsed.sessionId) ? parsed.sessionId : null;
201
+ if (!token || !sessionId) {
202
+ // Exit 0 but unusable. A parsed token is pinned so later output cannot leak it. Without a valid session id it cannot
203
+ // be revoked: residual risk is a live token until its TTL (`--ttl 1h`) expires.
204
+ if (token) pinSecret(token);
205
+ throw new T3AuthError("T3 returned an unexpected issue response", { hint: FAIL_HINT });
206
+ }
207
+ pinSecret(token);
208
+ return { token, sessionId };
209
+ }
210
+
211
+ /** `t3 auth session revoke -- <id>`: stops sessions from accumulating. Pass the token to drop it from the redaction registry. */
212
+ export async function revokeSession(cli , sessionId , run = defaultRunner, token ) {
213
+ if (!SESSION_ID_RE.test(sessionId)) throw new T3AuthError("invalid session id");
214
+ const shell = useShell(cli);
215
+ const r = await run(cli, ["auth", "session", "revoke", "--", sessionId], { shell, timeoutMs: 30_000, env: childEnv() });
216
+ if (r.timedOut) throw timedOut("revoke", sessionId);
217
+ if (r.code !== 0) throw failed("revoke", r.code, sessionId);
218
+ if (token) unregisterSecret(token);
219
+ }
220
+
221
+ /** POST /api/auth/websocket-ticket/rpc (S1 2.3). Tickets live 5 min; mint one per connection. Local origins only; redirects are errors. */
222
+ export async function mintWsTicket(origin , token , fetchImpl = fetch) {
223
+ pinSecret(token);
224
+ const base = parseLocalOrigin(origin);
225
+ if (!base) throw new T3AuthError("refusing to send credentials to a non-local origin");
226
+ let res ;
227
+ try {
228
+ res = await fetchImpl(new URL("/api/auth/websocket-ticket/rpc", base).href, {
229
+ method: "POST",
230
+ headers: { authorization: `Bearer ${token}` },
231
+ redirect: "error",
232
+ signal: AbortSignal.timeout(10_000),
233
+ });
234
+ } catch (e) {
235
+ const timeout = e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
236
+ throw new T3AuthError(timeout ? "websocket ticket request timed out after 10 s" : "could not reach T3 Code to mint a websocket ticket");
237
+ }
238
+ if (res.status === 401 || res.status === 403) {
239
+ throw new T3AuthError(`websocket ticket refused (HTTP ${res.status}): token expired or lacks permissions`, { hint: "token expired or lacks permissions" });
240
+ }
241
+ if (!res.ok) throw new T3AuthError(`websocket ticket request failed (HTTP ${res.status})`);
242
+ let body ;
243
+ try { body = await res.json(); } catch { throw new T3AuthError("websocket ticket response was not JSON"); }
244
+ const ticket = (body )?.ticket;
245
+ if (typeof ticket !== "string" || !ticket) throw new T3AuthError("websocket ticket response had no ticket");
246
+ registerSecret(ticket);
247
+ return ticket;
248
+ }
@@ -0,0 +1,62 @@
1
+ /** T3 Code server versions t3sm was verified against (spikes S1..S6; source or live). */
2
+ export const TESTED_VERSIONS = Object.freeze([
3
+ "0.1.8-nightly.20261105.4218",
4
+ "0.1.9-nightly.20261110.4465",
5
+ "0.1.10-nightly.20261113.4630", // spike S6 + two real imports, 2026-11-14
6
+ ]);
7
+
8
+
9
+
10
+ function majorMinor(v ) {
11
+ const m = /^(\d+)\.(\d+)\.\d+/.exec(v) ?? /^(\d+)\.(\d+)$/.exec(v);
12
+ return m ? `${m[1]}.${m[2]}` : null;
13
+ }
14
+
15
+ /** exact tested -> "tested"; same major.minor as a tested version -> "same-minor"; anything else (or unparseable) -> "untested". */
16
+ export function checkCompat(version ) {
17
+ if (TESTED_VERSIONS.includes(version)) return "tested";
18
+ const mm = majorMinor(version);
19
+ if (mm !== null && TESTED_VERSIONS.some((t) => majorMinor(t) === mm)) return "same-minor";
20
+ return "untested";
21
+ }
22
+
23
+
24
+
25
+ /** The one wording every command uses for a T3 Code version not in TESTED_VERSIONS. */
26
+ export function untestedNotice(version ) {
27
+ const v = version.replace(/[\r\n]/g, " ");
28
+ return `Warning: T3 Code ${v} has not been tested with t3sm (tested: ${TESTED_VERSIONS.join(", ")}). Proceeding; every change is journaled and can be undone with t3sm rollback.`;
29
+ }
30
+
31
+ /**
32
+ * Applies the gate (owner decision 2026-11-14: t3sm works with any T3 Code version). It never throws: a version in
33
+ * TESTED_VERSIONS is silent; any other (same minor or not) emits one untested warning and proceeds, silent with
34
+ * allowUntested. What protects an unknown version is strict response decoding (decode.ts), and the one thing that
35
+ * still refuses is a server whose orchestration protocol is not 2 (checked in connectT3, T3Incompatible).
36
+ */
37
+ export function compatGate(version , opts ) {
38
+ const c = checkCompat(version);
39
+ if (c !== "tested" && !opts.allowUntested) opts.onNotice?.(untestedNotice(version));
40
+ return c;
41
+ }
42
+
43
+ /**
44
+ * Same gate for the organize commands and their undo, which connect with allowUntested so the connection stays quiet and
45
+ * this speaks once (ruling R18; identical wording, so a command that runs both prints it once). Never throws.
46
+ */
47
+ export function organizeGate(version , opts ) {
48
+ compatGate(version, opts);
49
+ }
50
+
51
+ /**
52
+ * How a rehome copy follows its original when the original grows. Spike S5 (docs/spikes/S5-merge.md): T3 only continues a
53
+ * thread from records it wrote; a merge imports a new revision and archives the old thread (proven). "refresh" (append in
54
+ * place) is right only if S7a/S7b show the same thread growing: see docs/spikes/S7-followup-and-backdate.md.
55
+ */
56
+ export const FOLLOW_MODE = "revision";
57
+
58
+ /**
59
+ * Whether `thread.settle` honours an optional `settledAt` (spike S8, docs/spikes/S7-followup-and-backdate.md).
60
+ * Unverified, so false: nothing sends `settledAt`.
61
+ */
62
+ export const SETTLE_BACKDATE = false;