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,168 @@
1
+ // toClaudeJsonl: a CanonicalTranscript (any harness) as a Claude Code transcript that T3 Code imports and
2
+ // `claude --resume` continues. The record shape is exactly what spike S3 measured live (docs/spikes/S3-conversion.md,
3
+ // fixture test/fixtures/claude/converted-minimal.jsonl):
4
+ //
5
+ // {"parentUuid", "type", ["isMeta",] "message": {"role", "content"}, "uuid", "timestamp", "cwd", "sessionId"}
6
+ //
7
+ // - Record 0 is the provenance: a `user` record with isMeta: true (hidden in T3's timeline and title, seen by the
8
+ // model). Then one record per message. All 7 fields on every record (the smallest set that works for both T3 and
9
+ // the CLI without relying on accidental behaviour, S3 §1).
10
+ // - User content is a string; assistant content is one text block.
11
+ // - Chain: strictly linear, parentUuid null on record 0, then the previous record's uuid (the CLI needs it, S3 §2).
12
+ // Record uuids are uuidV5(`<session uuid>:<record index>`): re-conversion is byte-identical.
13
+ // - Timestamps: ISO-8601 UTC with ms, strictly increasing (+1 ms on ties or reversals, S3 §3), so the CLI's leaf is
14
+ // unambiguous and T3's createdAt is the first message's real time.
15
+ // - Consecutive same-role messages are MERGED into one record (blank line between). S3 shows consecutive user records
16
+ // work (the loader joins them, §4), but consecutive assistant records were never tested; merging keeps the
17
+ // user/assistant alternation the API expects for both roles and costs nothing in T3 (one bubble per turn).
18
+ // - Tool calls and attachments arrive already flattened into text by the source adapter.
19
+
20
+ import { open } from "node:fs/promises";
21
+
22
+ import { isUuid, uuidV5 } from "../core/uuid.js";
23
+ import { hasConverter } from "../sources/registry.js";
24
+
25
+ /** Default history budget: the size above which a native transcript is flagged `over-32mib` (truncated-over-32mib). */
26
+ export const DEFAULT_MAX_HISTORY_BYTES = 32 * 1024 * 1024;
27
+ /** Text of a message that has no text at all (T3 renders nothing for an empty bubble; the model needs a turn). */
28
+ export const NO_TEXT_PLACEHOLDER = "[no text content]";
29
+ /** Appended to a first user message clipped to fit the size limit. */
30
+ export const CLIP_MARKER = "… [truncated by t3code-session-manager]";
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ function provenanceText(t , omitted ) {
44
+ const base = `Imported from ${t.harness} session ${t.nativeId} (started ${t.startedAt}) by t3code-session-manager.`;
45
+ return omitted > 0 ? `${base} ${omitted} earlier messages were left out to fit the size limit.` : base;
46
+ }
47
+
48
+ /** Each message's time in ms: its own timestamp, or startedAt + index ms when it is not a valid date. */
49
+ function turns(t , base ) {
50
+ const out = [];
51
+ t.messages.forEach((m , i) => {
52
+ const own = Date.parse(m.timestamp);
53
+ const ms = Number.isFinite(own) ? own : base + i;
54
+ const text = m.text.trim() === "" ? "" : m.text;
55
+ const prev = out[out.length - 1];
56
+ if (prev && prev.role === m.role) {
57
+ prev.text = [prev.text, text].filter((x) => x !== "").join("\n\n");
58
+ prev.ms = Math.max(prev.ms, ms);
59
+ } else out.push({ role: m.role, text, ms });
60
+ });
61
+ return out;
62
+ }
63
+
64
+ function record(
65
+ i , parent , role , text , ms , o , meta = false,
66
+ ) {
67
+ const uuid = uuidV5(`${o.uuid}:${i}`);
68
+ const body = text === "" ? NO_TEXT_PLACEHOLDER : text;
69
+ const message = role === "user" ? { role, content: body } : { role, content: [{ type: "text", text: body }] };
70
+ const r = meta
71
+ ? { parentUuid: parent, type: role, isMeta: true, message, uuid, timestamp: new Date(ms).toISOString(), cwd: o.cwd, sessionId: o.uuid }
72
+ : { parentUuid: parent, type: role, message, uuid, timestamp: new Date(ms).toISOString(), cwd: o.cwd, sessionId: o.uuid };
73
+ return { line: JSON.stringify(r) + "\n", uuid };
74
+ }
75
+
76
+ /**
77
+ * Render `t` as Claude Code JSONL. When the result would exceed `maxHistoryBytes`, keeps the provenance record (which
78
+ * then says how many messages were left out), the first user message and the newest contiguous messages that fit,
79
+ * and reports `truncated: true`. Pure and deterministic.
80
+ */
81
+ export function toClaudeJsonl(t , o ) {
82
+ if (!isUuid(o.uuid)) throw new Error(`toClaudeJsonl: session id must be a UUID (got ${o.uuid})`);
83
+ const max = o.maxHistoryBytes ?? DEFAULT_MAX_HISTORY_BYTES;
84
+ const started = Date.parse(t.startedAt);
85
+ // An invalid startedAt: the first valid message time (else the epoch, the last resort).
86
+ const firstValid = t.messages.map((m) => Date.parse(m.timestamp)).find((x) => Number.isFinite(x));
87
+ const base = Number.isFinite(started) ? started : firstValid ?? 0;
88
+ const all = turns(t, base);
89
+ const provMs = all.length > 0 ? Math.min(base, all[0] .ms) : base;
90
+
91
+ const render = (kept , omitted ) => {
92
+ let parent = null;
93
+ let last = provMs;
94
+ let out = "";
95
+ const p = record(0, null, "user", provenanceText(t, omitted), provMs, o, true);
96
+ out += p.line;
97
+ parent = p.uuid;
98
+ kept.forEach((m, k) => {
99
+ last = Math.max(m.ms, last + 1);
100
+ const r = record(k + 1, parent, m.role, m.text, last, o);
101
+ out += r.line;
102
+ parent = r.uuid;
103
+ });
104
+ return out;
105
+ };
106
+
107
+ const full = render(all, 0);
108
+ if (Buffer.byteLength(full, "utf8") <= max) return { text: full, truncated: false };
109
+
110
+ // Every record's size is independent of its neighbours except for the uuids (fixed 36 chars) and the timestamp
111
+ // (fixed 24 chars), so per-turn sizes measured once are exact for any selection.
112
+ const size = (m , k ) => Buffer.byteLength(record(k + 1, "", m.role, m.text, m.ms, o).line, "utf8") + 36;
113
+ const firstUser = all.findIndex((m) => m.role === "user");
114
+ const head = firstUser >= 0 ? [{ ...all[firstUser] }] : [];
115
+ // The provenance's length depends on the omitted count; reserve the longest it can be.
116
+ let budget = max - Buffer.byteLength(record(0, null, "user", provenanceText(t, all.length), provMs, o, true).line, "utf8");
117
+ if (head.length > 0 && size(head[0] , 0) > budget) {
118
+ // The first user message alone does not fit: keep the longest prefix that does, marked as clipped.
119
+ const full = head[0] .text;
120
+ const fits = (k ) => size({ ...head[0] , text: full.slice(0, k) + CLIP_MARKER }, 0) <= budget;
121
+ let lo = 0, hi = full.length;
122
+ while (lo < hi) {
123
+ const mid = Math.ceil((lo + hi) / 2);
124
+ if (fits(mid)) lo = mid; else hi = mid - 1;
125
+ }
126
+ head[0] .text = full.slice(0, lo) + CLIP_MARKER;
127
+ }
128
+ budget -= head.reduce((n, m) => n + size(m, 0), 0);
129
+ const tail = [];
130
+ for (let i = all.length - 1; i > Math.max(firstUser, -1); i--) {
131
+ const s = size(all[i] , 1);
132
+ if (s > budget) break; // contiguous newest slice only
133
+ budget -= s;
134
+ tail.unshift(all[i] );
135
+ }
136
+ const kept = [...head, ...tail];
137
+ return { text: render(kept, all.length - kept.length), truncated: true };
138
+ }
139
+
140
+ /**
141
+ * True when `path` (Claude session `nativeId`) is a transcript t3sm wrote by converting another harness's session:
142
+ * its id is a version-5 UUID and its first record is t3sm's provenance (isMeta user, parentUuid null, record uuid
143
+ * derived in t3sm's namespace, "Imported from <harness with a converter> session …"). Cheap: a non-v5 id never opens the
144
+ * file, and only the first 64 KiB are read. Never throws.
145
+ */
146
+ export async function isConvertedTranscript(path , nativeId , isConvert = hasConverter) {
147
+ if (!isUuid(nativeId) || nativeId[14] !== "5") return false;
148
+ let first ;
149
+ try {
150
+ const fh = await open(path, "r");
151
+ try {
152
+ const buf = Buffer.alloc(65_536);
153
+ const { bytesRead } = await fh.read(buf, 0, buf.length, 0);
154
+ const text = buf.subarray(0, bytesRead).toString("utf8");
155
+ const nl = text.indexOf("\n");
156
+ if (nl < 0) return false;
157
+ first = text.slice(0, nl);
158
+ } finally {
159
+ await fh.close();
160
+ }
161
+ const r = JSON.parse(first) ;
162
+ if (r.parentUuid !== null || r.type !== "user" || r.isMeta !== true || r.uuid !== uuidV5(`${nativeId.toLowerCase()}:0`)) return false;
163
+ const m = typeof r.message?.content === "string" ? /^Imported from (\S+) session .* by t3code-session-manager\./.exec(r.message.content) : null;
164
+ return m !== null && isConvert(m[1] );
165
+ } catch {
166
+ return false;
167
+ }
168
+ }
@@ -0,0 +1,116 @@
1
+ // faithfulCopy: the text of a faithful copy of a Claude transcript (spec §4.3), for a conversation whose folder T3 Code
2
+ // refuses (the home folder, ~/Documents/Codex...). Unlike claudeWriter (which flattens a canonical transcript), every
3
+ // line of the source is kept as it is, so the copy resumes with the full history (tools, thinking, titles); only
4
+ // the top-level `cwd` and `sessionId` of the records that carry them change, so T3 Code files it under the target
5
+ // project with a new id. A provenance record (no `uuid`: Claude Code and T3 Code ignore its unknown type, S6 §8.4)
6
+ // is appended once and links the copy to its original.
7
+ //
8
+ // faithfulCopy is pure apart from reading the source (once, whole). readFaithfulCopy adds the checks every caller needs
9
+ // (the source stat'd before and after the read: in use or changed meanwhile -> wait) and discovery's measure of the
10
+ // original. Writing, journaling and publishing are the callers' job: materialize (the first copy, and a refresh in
11
+ // place) and follow (a revision of a copy that follows its original, src/ops/follow.ts).
12
+ // Line rules: lines are split on LF; a record without top-level cwd / sessionId, a blank line and a corrupt line are
13
+ // kept byte for byte (as UTF-8 text); a record that carries them is re-serialized with the same keys in the same order
14
+ // (its other values are equal, though JSON escapes may be spelled differently), keeping a BOM and a trailing CR.
15
+
16
+ import { readFile } from "node:fs/promises";
17
+ import { statSafe } from "../core/fsutil.js";
18
+ import { isActive } from "../core/activity.js";
19
+ import { scanTranscriptChunks } from "../sources/claude.js";
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ export const PROVENANCE_TYPE = "t3sm-provenance";
31
+ export const WRITTEN_BY = "t3code-session-manager";
32
+
33
+ /** The provenance record of a faithful copy (one JSON line, no newline). */
34
+ export function provenanceLine(p ) {
35
+ return JSON.stringify({ type: PROVENANCE_TYPE, fromPath: p.fromPath, fromSessionId: p.fromSessionId, fromCwd: p.fromCwd, writtenBy: WRITTEN_BY });
36
+ }
37
+
38
+ /**
39
+ * The copy's text and how many source lines it holds (blank lines not counted; the provenance record not counted).
40
+ * The source file is only read.
41
+ */
42
+ export async function faithfulCopy(source , o ) {
43
+ const raw = await readFile(source, "utf8");
44
+ const pieces = raw.split("\n");
45
+ // A final newline leaves an empty last piece: not a line.
46
+ if (pieces.length > 0 && pieces[pieces.length - 1] === "") pieces.pop();
47
+ let records = 0;
48
+ const out = [];
49
+ for (let i = 0; i < pieces.length; i++) {
50
+ const line = pieces[i] ;
51
+ if (line.trim() !== "") records++;
52
+ out.push(swap(line, i === 0, o));
53
+ }
54
+ out.push(provenanceLine(o.provenance));
55
+ return { text: out.join("\n") + "\n", records };
56
+ }
57
+
58
+ /** The line with its top-level cwd / sessionId swapped, or the line itself when it carries neither or is not a record. */
59
+ function swap(line , first , o ) {
60
+ let body = line;
61
+ const bom = first && body.charCodeAt(0) === 0xfeff ? "\uFEFF" : "";
62
+ if (bom) body = body.slice(1);
63
+ const cr = body.endsWith("\r") ? "\r" : "";
64
+ if (cr) body = body.slice(0, -1);
65
+ if (!body.includes(`"cwd"`) && !body.includes(`"sessionId"`)) return line; // cheap: most lines are not parsed twice
66
+ let rec ;
67
+ try {
68
+ rec = JSON.parse(body);
69
+ } catch {
70
+ return line; // corrupt: copied as it is
71
+ }
72
+ if (rec === null || typeof rec !== "object" || Array.isArray(rec)) return line;
73
+ const r = rec ;
74
+ const hasCwd = Object.hasOwn(r, "cwd");
75
+ const hasId = Object.hasOwn(r, "sessionId");
76
+ if (!hasCwd && !hasId) return line; // only nested fields of that name (tool input): content, never rewritten
77
+ // Assigning existing keys keeps their position: same keys, same order.
78
+ if (hasCwd) r.cwd = o.cwd;
79
+ if (hasId) r.sessionId = o.sessionId;
80
+ return bom + JSON.stringify(r) + cr;
81
+ }
82
+
83
+ /** The original as copied (journaled as `file-written.rehomeOf`): the planner's and the follow's baseline. */
84
+
85
+
86
+ async function* once(b ) {
87
+ yield b;
88
+ }
89
+
90
+ /**
91
+ * A faithful copy of the Claude transcript at `source.path` (session `source.nativeId`, folder `o.fromCwd`), checked
92
+ * against the file it was read from, or why it has to wait: written within ACTIVE_WINDOW_MS (in use) -> `active`;
93
+ * changed while it was read -> `source-busy`. Throws when the source cannot be read. Shared by materialize (the first
94
+ * copy) and follow (a copy that follows its original).
95
+ *
96
+ * activity: discovery's measure of the original (only cwd / sessionId differ in the copy, and the provenance record
97
+ * has no timestamp and is no message; no timestamp at all: the file's time). cwdOffsetBytes: bytes up to and
98
+ * including the copy's first record that carries cwd, as discovery counts them.
99
+ */
100
+ export async function readFaithfulCopy(
101
+ source , o , now ,
102
+ ) {
103
+ const before = await statSafe(source.path);
104
+ if (before === null) throw new Error(`${source.path} no longer exists`);
105
+ if (isActive(before.mtimeMs, now)) return { defer: "active" };
106
+ const { text } = await faithfulCopy(source.path, { cwd: o.cwd, sessionId: o.sessionId, provenance: { fromPath: source.path, fromSessionId: source.nativeId, fromCwd: o.fromCwd } });
107
+ const after = await statSafe(source.path);
108
+ if (after === null || after.size !== before.size || after.mtimeMs !== before.mtimeMs) return { defer: "source-busy" };
109
+ const m = await scanTranscriptChunks(once(Buffer.from(text, "utf8")));
110
+ return {
111
+ text,
112
+ activity: { updatedAt: m.updatedAt ?? new Date(before.mtimeMs).toISOString(), messageCount: m.messageCount },
113
+ rehomeOf: { path: source.path, nativeId: source.nativeId, cwd: o.fromCwd, size: before.size, mtimeMs: before.mtimeMs },
114
+ cwdOffsetBytes: m.cwdOffsetBytes,
115
+ };
116
+ }