t3code-session-manager 0.0.0-stage → 0.4.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 (172) hide show
  1. package/.claude-plugin/marketplace.json +21 -0
  2. package/.claude-plugin/plugin.json +19 -0
  3. package/CHANGELOG.md +138 -0
  4. package/LICENSE +21 -0
  5. package/README.md +660 -2
  6. package/README.pt.md +616 -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,316 @@
1
+ // Which subscription owns a copy or a project (spec §4.3): content comparison between copies of one session,
2
+ // and the project-account rule route -> .vscode pin -> most recent activity -> default.
3
+
4
+ import { createReadStream } from "node:fs";
5
+ import { readFile } from "node:fs/promises";
6
+ import { homedir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { createInterface } from "node:readline";
9
+
10
+ import { expandHome, normalizeCwd, sameCwd } from "../core/paths.js";
11
+ import { routeAccount } from "../core/config.js";
12
+
13
+
14
+
15
+ // The /vscode-account skill rewrites the drive letter in `cwd` when it mirrors a session (spec §4.3); one real mirror
16
+ // also differs in the case of a path segment. On case-insensitive platforms (win32, darwin) `cwd` values are compared
17
+ // case-insensitively; on linux they are compared exactly (two spellings are two different directories there).
18
+ const CWD_VALUE_RE = /("cwd"\s*:\s*")((?:[^"\\]|\\.)*)(")/g;
19
+
20
+ const foldsCase = (platform ) => platform === "win32" || platform === "darwin";
21
+
22
+ function normLine(l , fold ) {
23
+ if (!fold || l.indexOf('"cwd"') === -1) return l;
24
+ return l.replace(CWD_VALUE_RE, (_m, a , v , c ) => a + v.toLowerCase() + c);
25
+ }
26
+
27
+ /**
28
+ * Bookkeeping records Claude Code writes beside the conversation (titles, queue, last prompt, mode). Measured
29
+ * 2026-11-11: a mirror and its continuation differ in these at the top of the file while the conversation is a
30
+ * strict prefix, so they are not compared.
31
+ */
32
+ const METADATA_TYPES = new Set([
33
+ "queue-operation", "ai-title", "custom-title", "last-prompt", "mode", "permission-mode", "summary", "agent-name", "tag",
34
+ ]);
35
+ const METADATA_HINT_RE = /"type"\s*:\s*"(queue-operation|ai-title|custom-title|last-prompt|mode|permission-mode|summary|agent-name|tag)"/;
36
+ const METADATA_MAX_LINE = 65_536;
37
+
38
+ function isMetadata(l ) {
39
+ if (l.length > METADATA_MAX_LINE || !METADATA_HINT_RE.test(l)) return false;
40
+ try {
41
+ const o = JSON.parse(l) ;
42
+ return typeof o === "object" && o !== null && METADATA_TYPES.has((o ).type );
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+
48
+ function parses(l ) {
49
+ try {
50
+ JSON.parse(l);
51
+ return true;
52
+ } catch {
53
+ return false;
54
+ }
55
+ }
56
+
57
+ // Takes the readline iterator, created synchronously with the interface: lines emitted before an iterator is attached
58
+ // are lost, so it must never be created lazily inside the generator.
59
+ async function* conversationLines(it ) {
60
+ for (let r = await it.next(); !r.done; r = await it.next()) if (!isMetadata(r.value)) yield r.value;
61
+ }
62
+
63
+ /**
64
+ * Compares two copies of one transcript line by line, streaming (never loads a file whole). CRLF equals LF, metadata
65
+ * records (METADATA_TYPES) are skipped, and `cwd` case is ignored on win32/darwin. A partial (unparseable) last line
66
+ * counts only when it is a prefix of the other copy's line at the same position; when the only extra content of the
67
+ * longer copy is such a partial line, the copies are identical. Rejects on I/O errors (ENOENT, EBUSY, EISDIR).
68
+ */
69
+ export async function compareCopies(a , b , platform = process.platform) {
70
+ const fold = foldsCase(platform);
71
+ const sa = createReadStream(a);
72
+ const sb = createReadStream(b);
73
+ const ra = createInterface({ input: sa, crlfDelay: Infinity });
74
+ const rb = createInterface({ input: sb, crlfDelay: Infinity });
75
+ const ia = conversationLines(ra[Symbol.asyncIterator]());
76
+ const ib = conversationLines(rb[Symbol.asyncIterator]());
77
+ // Readline does not surface stream errors to its iterator in every Node version; race them in explicitly.
78
+ let fail = null;
79
+ const failed = new Promise ((_r, rej) => { fail = rej; });
80
+ failed.catch(() => {});
81
+ sa.on("error", (e) => fail (e));
82
+ sb.on("error", (e) => fail (e));
83
+ const next = (it ) => Promise.race([it.next(), failed]);
84
+ /** The other copy ran out: its remaining content is one garbage partial line -> identical, else it extends. */
85
+ const tail = async (it , line , ext ) => {
86
+ const after = await next(it);
87
+ return after.done === true && !parses(line) ? "identical" : ext;
88
+ };
89
+ try {
90
+ let na = await next(ia);
91
+ let nb = await next(ib);
92
+ for (;;) {
93
+ if (na.done && nb.done) return "identical";
94
+ if (na.done) return await tail(ib, nb.value , "b-extends-a");
95
+ if (nb.done) return await tail(ia, na.value , "a-extends-b");
96
+ const la = na.value ;
97
+ const lb = nb.value ;
98
+ const nextA = await next(ia);
99
+ const nextB = await next(ib);
100
+ if (la !== lb) {
101
+ const xa = normLine(la, fold);
102
+ const xb = normLine(lb, fold);
103
+ if (xa !== xb) {
104
+ const aPartial = nextA.done === true && !parses(la);
105
+ const bPartial = nextB.done === true && !parses(lb);
106
+ if (aPartial && xb.startsWith(xa)) return "b-extends-a";
107
+ if (bPartial && xa.startsWith(xb)) return "a-extends-b";
108
+ return "diverged";
109
+ }
110
+ }
111
+ na = nextA;
112
+ nb = nextB;
113
+ }
114
+ } finally {
115
+ // Every return above awaits inside the try: the streams are closed only after the last read finished.
116
+ ra.close();
117
+ rb.close();
118
+ sa.destroy();
119
+ sb.destroy();
120
+ }
121
+ }
122
+
123
+ const LABEL_HINT_RE = /"type"\s*:\s*"(custom-title|tag)"/;
124
+
125
+ /**
126
+ * User-set labels in a transcript (`custom-title` and `tag` records), as `"<type>:<value>"`. Streaming. Used to warn
127
+ * when the copy dedupe quarantines holds a label the kept copy lacks (nothing is lost: quarantine is reversible).
128
+ */
129
+ export async function labelRecords(file ) {
130
+ const out = new Set ();
131
+ await eachRecord(file, LABEL_HINT_RE, (o) => {
132
+ if (o["type"] === "custom-title" && typeof o["customTitle"] === "string") out.add(`custom-title:${o["customTitle"]}`);
133
+ else if (o["type"] === "tag" && typeof o["tag"] === "string") out.add(`tag:${o["tag"]}`);
134
+ });
135
+ return out;
136
+ }
137
+
138
+ const TITLE_HINT_RE = /"type"\s*:\s*"(custom-title|ai-title)"/;
139
+
140
+ /**
141
+ * A Claude transcript's title as T3 Code shows it: the newest `custom-title` (set by the user), else the newest
142
+ * `ai-title`; null when it has neither or cannot be read. Only title records are parsed, never message content.
143
+ */
144
+ export async function conversationTitle(file ) {
145
+ let custom = null;
146
+ let ai = null;
147
+ try {
148
+ await eachRecord(file, TITLE_HINT_RE, (o) => {
149
+ if (o["type"] === "custom-title" && typeof o["customTitle"] === "string" && o["customTitle"].trim() !== "") custom = o["customTitle"].trim();
150
+ else if (o["type"] === "ai-title" && typeof o["aiTitle"] === "string" && o["aiTitle"].trim() !== "") ai = o["aiTitle"].trim();
151
+ });
152
+ } catch {
153
+ return null;
154
+ }
155
+ return custom ?? ai;
156
+ }
157
+
158
+ /** Streams `file`, parsing only the top-level JSON records whose line matches `hint` (and is not oversized). */
159
+ async function eachRecord(file , hint , fn ) {
160
+ const st = createReadStream(file);
161
+ const rl = createInterface({ input: st, crlfDelay: Infinity });
162
+ const it = rl[Symbol.asyncIterator]();
163
+ let fail = null;
164
+ const failed = new Promise ((_r, rej) => { fail = rej; });
165
+ failed.catch(() => {});
166
+ st.on("error", (e) => fail (e));
167
+ try {
168
+ for (let r = await Promise.race([it.next(), failed]); !r.done; r = await Promise.race([it.next(), failed])) {
169
+ const l = r.value ;
170
+ if (l.length > METADATA_MAX_LINE || !hint.test(l)) continue;
171
+ let o ;
172
+ try {
173
+ o = JSON.parse(l);
174
+ } catch {
175
+ continue; // not a record
176
+ }
177
+ if (typeof o === "object" && o !== null && !Array.isArray(o)) fn(o );
178
+ }
179
+ } finally {
180
+ rl.close();
181
+ st.destroy();
182
+ }
183
+ }
184
+
185
+ /** JSON with comments (// and /* *\/ outside strings) and trailing commas, as VS Code writes settings.json. */
186
+ export function parseJsonc(text ) {
187
+ let out = "";
188
+ let i = 0;
189
+ const n = text.length;
190
+ while (i < n) {
191
+ const c = text[i] ;
192
+ if (c === '"') {
193
+ let j = i + 1;
194
+ while (j < n && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
195
+ out += text.slice(i, j + 1);
196
+ i = j + 1;
197
+ } else if (c === "/" && text[i + 1] === "/") {
198
+ while (i < n && text[i] !== "\n") i++;
199
+ } else if (c === "/" && text[i + 1] === "*") {
200
+ const end = text.indexOf("*/", i + 2);
201
+ i = end === -1 ? n : end + 2;
202
+ out += " ";
203
+ } else {
204
+ out += c;
205
+ i++;
206
+ }
207
+ }
208
+ // Trailing commas, string-aware.
209
+ let res = "";
210
+ for (let k = 0; k < out.length; k++) {
211
+ const c = out[k] ;
212
+ if (c === '"') {
213
+ let j = k + 1;
214
+ while (j < out.length && out[j] !== '"') j += out[j] === "\\" ? 2 : 1;
215
+ res += out.slice(k, j + 1);
216
+ k = j;
217
+ } else if (c === ",") {
218
+ let j = k + 1;
219
+ while (j < out.length && /\s/.test(out[j] )) j++;
220
+ if (out[j] !== "}" && out[j] !== "]") res += c;
221
+ } else {
222
+ res += c;
223
+ }
224
+ }
225
+ return JSON.parse(res);
226
+ }
227
+
228
+ const isObj = (u ) => typeof u === "object" && u !== null && !Array.isArray(u);
229
+
230
+ /** `CLAUDE_CONFIG_DIR` from `claudeCode.environmentVariables` (array of {name, value} or an object), else null. */
231
+ export function pinFromSettings(settings ) {
232
+ if (!isObj(settings)) return null;
233
+ let ev = settings["claudeCode.environmentVariables"];
234
+ if (ev === undefined && isObj(settings["claudeCode"])) ev = settings["claudeCode"]["environmentVariables"];
235
+ if (Array.isArray(ev)) {
236
+ for (const e of ev) {
237
+ if (isObj(e) && e["name"] === "CLAUDE_CONFIG_DIR" && typeof e["value"] === "string" && e["value"] !== "") return e["value"];
238
+ }
239
+ return null;
240
+ }
241
+ if (isObj(ev) && typeof ev["CLAUDE_CONFIG_DIR"] === "string" && ev["CLAUDE_CONFIG_DIR"] !== "") return ev["CLAUDE_CONFIG_DIR"];
242
+ return null;
243
+ }
244
+
245
+ /** Reads `<root>/.vscode/settings.json` only (never a parent). Missing or unparseable -> null. */
246
+ export async function readVscodePin(root ) {
247
+ let text ;
248
+ try {
249
+ text = await readFile(join(root, ".vscode", "settings.json"), "utf8");
250
+ } catch {
251
+ return null;
252
+ }
253
+ try {
254
+ return pinFromSettings(parseJsonc(text.replace(/^\uFEFF/, "")));
255
+ } catch {
256
+ return null;
257
+ }
258
+ }
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+ function expandVars(p , home ) {
271
+ return expandHome(p.replace(/^\$\{(?:userHome|env:USERPROFILE|env:HOME)\}/, home).replace(/^%USERPROFILE%/i, home), home);
272
+ }
273
+
274
+ /** Account id whose home equals `dir` (after ~ expansion), or null. */
275
+ export function accountForHome(dir , config , home , platform ) {
276
+ const d = expandVars(dir, home);
277
+ for (const a of config.accounts) {
278
+ if (sameCwd(expandVars(a.home, home), d, platform)) return a.id;
279
+ }
280
+ return null;
281
+ }
282
+
283
+ /** Spec §4.3 rule 3: route -> `.vscode/settings.json` pin -> newest activity -> default. */
284
+ export async function projectAccount(root , ev ) {
285
+ const platform = ev.platform ?? process.platform;
286
+ const home = ev.home ?? homedir();
287
+ const routed = routeAccount(root, ev.config, platform);
288
+ if (routed !== null) return { accountId: routed, source: "route" };
289
+ const pin = await ev.readVscodePin(root);
290
+ if (pin !== null) {
291
+ const acct = accountForHome(pin, ev.config, home, platform);
292
+ if (acct !== null) return { accountId: acct, source: "vscode-pin" };
293
+ }
294
+ const known = new Set(ev.config.accounts.map((a) => a.id));
295
+ let best = null;
296
+ const nroot = normalizeCwd(root, platform);
297
+ for (const s of ev.sessions) {
298
+ if (s.harness !== "claude" || s.accountId === null || !known.has(s.accountId) || s.cwd === null) continue;
299
+ if (!sameCwd(s.cwd, nroot, platform)) continue;
300
+ if (best === null || newer(s, best, ev.config)) best = s;
301
+ }
302
+ if (best !== null) return { accountId: best.accountId , source: "recent-activity" };
303
+ return { accountId: ev.config.defaultAccount, source: "default" };
304
+ }
305
+
306
+ /** Newest updatedAt, then newest mtime, then the default account, then config order (deterministic). */
307
+ function newer(a , b , c ) {
308
+ const ta = Date.parse(a.updatedAt) || 0;
309
+ const tb = Date.parse(b.updatedAt) || 0;
310
+ if (ta !== tb) return ta > tb;
311
+ if (a.file.mtimeMs !== b.file.mtimeMs) return a.file.mtimeMs > b.file.mtimeMs;
312
+ if ((a.accountId === c.defaultAccount) !== (b.accountId === c.defaultAccount)) return a.accountId === c.defaultAccount;
313
+ const order = (s ) => c.accounts.findIndex((x) => x.id === s.accountId);
314
+ if (order(a) !== order(b)) return order(a) < order(b);
315
+ return a.file.path < b.file.path;
316
+ }