teamshare-bridge 0.28.24 → 0.28.26

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 (84) hide show
  1. package/dist/bridge/doctor.js +21 -0
  2. package/dist/bridge/doctor.js.map +1 -1
  3. package/dist/bridge/wake-handler.js +11 -3
  4. package/dist/bridge/wake-handler.js.map +1 -1
  5. package/dist/cli/commands/blog.js +8 -1
  6. package/dist/cli/commands/blog.js.map +1 -1
  7. package/dist/cli/commands/build.js +23 -3
  8. package/dist/cli/commands/build.js.map +1 -1
  9. package/dist/cli/commands/insight.js +8 -1
  10. package/dist/cli/commands/insight.js.map +1 -1
  11. package/dist/cli/commands/plan.js +8 -4
  12. package/dist/cli/commands/plan.js.map +1 -1
  13. package/dist/cli/commands/planner.js +9 -0
  14. package/dist/cli/commands/planner.js.map +1 -1
  15. package/dist/cli/commands/research.js +15 -4
  16. package/dist/cli/commands/research.js.map +1 -1
  17. package/dist/cli/commands/run.js +70 -6
  18. package/dist/cli/commands/run.js.map +1 -1
  19. package/dist/cli/commands/worker.js +23 -4
  20. package/dist/cli/commands/worker.js.map +1 -1
  21. package/dist/cli/commands/workflow.js +2 -2
  22. package/dist/cli/commands/workflow.js.map +1 -1
  23. package/dist/lib/api-agents.d.ts +18 -0
  24. package/dist/lib/api-agents.js +21 -0
  25. package/dist/lib/api-agents.js.map +1 -1
  26. package/dist/lib/api-tasks.d.ts +26 -0
  27. package/dist/lib/api-tasks.js +16 -0
  28. package/dist/lib/api-tasks.js.map +1 -1
  29. package/dist/lib/api-types.d.ts +23 -0
  30. package/dist/lib/brief.d.ts +12 -10
  31. package/dist/lib/brief.js +65 -10
  32. package/dist/lib/brief.js.map +1 -1
  33. package/dist/lib/chat/board-reply.js +13 -2
  34. package/dist/lib/chat/board-reply.js.map +1 -1
  35. package/dist/lib/chat/chat-reply.d.ts +3 -1
  36. package/dist/lib/chat/chat-reply.js +13 -2
  37. package/dist/lib/chat/chat-reply.js.map +1 -1
  38. package/dist/lib/chat/doc-reply.js +12 -2
  39. package/dist/lib/chat/doc-reply.js.map +1 -1
  40. package/dist/lib/chat/workflow-author-reply.js +11 -2
  41. package/dist/lib/chat/workflow-author-reply.js.map +1 -1
  42. package/dist/lib/git/git-branch.d.ts +51 -1
  43. package/dist/lib/git/git-branch.js +89 -1
  44. package/dist/lib/git/git-branch.js.map +1 -1
  45. package/dist/lib/git/git-core.d.ts +20 -0
  46. package/dist/lib/git/git-core.js +58 -0
  47. package/dist/lib/git/git-core.js.map +1 -1
  48. package/dist/lib/git/git-finalize.d.ts +52 -0
  49. package/dist/lib/git/git-finalize.js +165 -13
  50. package/dist/lib/git/git-finalize.js.map +1 -1
  51. package/dist/lib/git/git-naming.d.ts +111 -0
  52. package/dist/lib/git/git-naming.js +278 -0
  53. package/dist/lib/git/git-naming.js.map +1 -0
  54. package/dist/lib/git/git-prepare.d.ts +7 -0
  55. package/dist/lib/git/git-prepare.js.map +1 -1
  56. package/dist/lib/git/index-recovery.js +18 -0
  57. package/dist/lib/git/index-recovery.js.map +1 -1
  58. package/dist/lib/harness/harness-adapter.d.ts +10 -0
  59. package/dist/lib/harness/harness-adapter.js.map +1 -1
  60. package/dist/lib/harness/spawn.js +60 -1
  61. package/dist/lib/harness/spawn.js.map +1 -1
  62. package/dist/lib/orchestrator/handlers/repair.d.ts +7 -0
  63. package/dist/lib/orchestrator/handlers/repair.js +2 -0
  64. package/dist/lib/orchestrator/handlers/repair.js.map +1 -1
  65. package/dist/lib/orchestrator/worktree.js +70 -18
  66. package/dist/lib/orchestrator/worktree.js.map +1 -1
  67. package/dist/lib/run-guidance.d.ts +30 -0
  68. package/dist/lib/run-guidance.js +129 -0
  69. package/dist/lib/run-guidance.js.map +1 -0
  70. package/dist/lib/run-report.d.ts +19 -0
  71. package/dist/lib/run-report.js +23 -0
  72. package/dist/lib/run-report.js.map +1 -1
  73. package/dist/lib/workflow/node-executor.js +10 -0
  74. package/dist/lib/workflow/node-executor.js.map +1 -1
  75. package/dist/lib/workspace/isolation-repair.d.ts +9 -0
  76. package/dist/lib/workspace/isolation-repair.js +2 -0
  77. package/dist/lib/workspace/isolation-repair.js.map +1 -1
  78. package/dist/lib/workspace/mirror.d.ts +95 -0
  79. package/dist/lib/workspace/mirror.js +251 -8
  80. package/dist/lib/workspace/mirror.js.map +1 -1
  81. package/dist/lib/workspace/task-base.d.ts +89 -0
  82. package/dist/lib/workspace/task-base.js +342 -0
  83. package/dist/lib/workspace/task-base.js.map +1 -0
  84. package/package.json +1 -1
@@ -0,0 +1,89 @@
1
+ export type TaskBaseSource = 'record' | 'project' | 'folder' | 'repo-default';
2
+ export interface TaskBaseRecord {
3
+ taskId: string;
4
+ /** The linked folder this record belongs to (a moved project gets a new one). */
5
+ folder: string;
6
+ /** `<project>/<feature>` — the branch the work is delivered on. */
7
+ branch: string;
8
+ /** The branch this task STARTED from (the ref every run pulls). */
9
+ base: string;
10
+ /** Which input produced `base` when it was recorded. */
11
+ source: TaskBaseSource;
12
+ createdAt: string;
13
+ updatedAt: string;
14
+ /** How many runs have used this record. */
15
+ runs: number;
16
+ }
17
+ export interface TaskBasePlan {
18
+ taskId: string;
19
+ /** The branch the tree is put ON and the work is delivered on. */
20
+ branch: string;
21
+ /**
22
+ * The ref to merge into the branch before the agent starts, so the run works
23
+ * against current state. Null when nothing could be resolved.
24
+ */
25
+ pullFrom: string | null;
26
+ baseSource: TaskBaseSource;
27
+ /** `record` = this task already has a branch/base on this machine. */
28
+ branchSource: 'record' | 'derived';
29
+ /** True when at least one of the two refs already exists on this machine. */
30
+ branchExists: boolean;
31
+ /** The recorded base, when the record's base no longer resolves. */
32
+ staleBase?: string;
33
+ }
34
+ /** Absolute path of a task's record file. */
35
+ export declare function taskBasePath(taskId: string): string;
36
+ /** The record for a task ON THIS FOLDER, or null. Never throws. */
37
+ export declare function readTaskBase(taskId: string, folder: string): TaskBaseRecord | null;
38
+ /** Every record on this machine, newest first. Never throws. */
39
+ export declare function listTaskBases(): TaskBaseRecord[];
40
+ /** Drop records whose task has not run in `TASK_BASE_TTL_MS`. Never throws. */
41
+ export declare function pruneTaskBases(now?: number): number;
42
+ /**
43
+ * Resolve a recorded base inside a SPECIFIC repo (a multi-repo mirror shares one
44
+ * base NAME across repos that each have their own remotes).
45
+ *
46
+ * Accepts both `staging` and `origin/staging`, prefers the remote-tracking ref,
47
+ * and returns null when neither exists HERE — in which case the repo is simply
48
+ * not updated, rather than being merged with an unrelated branch.
49
+ */
50
+ export declare function resolveBaseRefIn(repo: string, base: string): string | null;
51
+ /**
52
+ * Decide the branch, the start point and the pull for one task.
53
+ *
54
+ * Pure decision-making: it reads git refs and the record, writes nothing. Both
55
+ * `createIsolationMirror` and the repair call it, which is the whole point —
56
+ * there is no second opinion anywhere in the bridge.
57
+ */
58
+ export declare function planTaskBase(opts: {
59
+ folder: string;
60
+ taskId: string;
61
+ projectSlug?: string | null;
62
+ taskTitle?: string | null;
63
+ /** Hub-assigned branch name (orchestrator/chain); wins over the derivation. */
64
+ deliverableBranch?: string | null;
65
+ /**
66
+ * The branch this task already DELIVERED on, recorded by the hub after a
67
+ * guarded rename to an agent-proposed name (2026-12). It outranks the local
68
+ * record: the record was written before the rename and would send a retry
69
+ * back to the pre-rename branch, which no longer holds the delivered work.
70
+ */
71
+ deliveryBranch?: string | null;
72
+ /** Project-wide base branch from TeamShare settings. */
73
+ configuredBase?: string | null;
74
+ }): TaskBasePlan;
75
+ /**
76
+ * Persist the plan for this task. Called ONCE per successful tree creation.
77
+ *
78
+ * The BASE is written once and then kept: it is "the branch this task started
79
+ * from", and a later project-setting change must not silently re-point an
80
+ * in-flight task's updates at another branch. Only a base that no longer
81
+ * resolves is replaced (self-heal), which `planTaskBase` reports as
82
+ * `staleBase`.
83
+ */
84
+ export declare function recordTaskBase(opts: {
85
+ folder: string;
86
+ plan: TaskBasePlan;
87
+ /** The base the tree was ACTUALLY cut/synced from (per the mirror marker). */
88
+ actualBase?: string | null;
89
+ }): TaskBaseRecord | null;
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.taskBasePath = taskBasePath;
4
+ exports.readTaskBase = readTaskBase;
5
+ exports.listTaskBases = listTaskBases;
6
+ exports.pruneTaskBases = pruneTaskBases;
7
+ exports.resolveBaseRefIn = resolveBaseRefIn;
8
+ exports.planTaskBase = planTaskBase;
9
+ exports.recordTaskBase = recordTaskBase;
10
+ /**
11
+ * task-base: THE deterministic answer to "what branch does this task's tree
12
+ * start from, and what does it pull to stay current" (2026-11-18).
13
+ *
14
+ * Why this module exists. Three different paths create an isolation tree —
15
+ * the WS wake (`wake-handler`), the session-start rebuild (`ensureLiveMirror`),
16
+ * and the repair button (`isolation-repair`) — and only the first two passed
17
+ * the task's own branch. The repair passed `configuredBase` alone, so the tree
18
+ * it built was cut from whatever `main` was checked out:
19
+ *
20
+ * repair builds `taskrun-<taskId>` from origin/main (new tip)
21
+ * -> the next run ADOPTS that tree
22
+ * -> `git checkout <task-branch>` is refused over local changes
23
+ * -> the run commits on a DETACHED HEAD and reports "on `HEAD`"
24
+ *
25
+ * The fix is not "remember to pass the branch in three places". It is one
26
+ * function every creator calls, with a machine-local record so the answer is
27
+ * the SAME on every run of a task, even on a machine that has never seen it:
28
+ *
29
+ * 1. BRANCH = the branch this task already uses (record) else the derived
30
+ * `<project>/<feature>`; the LOCAL branch wins over origin (unpushed
31
+ * agent work is the only copy).
32
+ * 2. START = that branch when it exists, else the first-run ladder
33
+ * (recorded base -> project base -> folder's checked-out branch -> repo
34
+ * default). Nothing else may decide this.
35
+ * 3. PULL = the branch the task STARTED from (recorded on its first run),
36
+ * merged into the tree at the start of every later run so the run works
37
+ * against current state. A conflict is NOT resolved by the bridge: it is
38
+ * left in the tree and the brief tells the agent to resolve it.
39
+ *
40
+ * The record is deliberately machine-local (`~/.teamshare/task-bases`): the
41
+ * linked folder, the branch tip and the base are facts about THIS machine's
42
+ * checkout. It is keyed by task id (one small JSON per task), written
43
+ * atomically, pruned after 30 days, and ignored when the project moved
44
+ * (a different folder = a different tree, so the old branch is meaningless).
45
+ */
46
+ const node_fs_1 = require("node:fs");
47
+ const node_os_1 = require("node:os");
48
+ const node_path_1 = require("node:path");
49
+ const git_core_1 = require("../git/git-core");
50
+ const git_branch_1 = require("../git/git-branch");
51
+ const log = (msg) => console.log(`[task-base] ${msg}`);
52
+ /**
53
+ * Where the per-task records live. Overridable so a test run never writes into
54
+ * the developer's real `~/.teamshare` (same pattern as the mirror leases).
55
+ */
56
+ const TASK_BASE_DIR = process.env.TS_TASK_BASE_DIR?.trim() ||
57
+ (0, node_path_1.join)((0, node_os_1.homedir)(), '.teamshare', 'task-bases');
58
+ /** A record older than this is pruned (a task's tree is long gone by then). */
59
+ const TASK_BASE_TTL_MS = 30 * 24 * 3600_000;
60
+ function norm(p) {
61
+ return (0, node_path_1.resolve)(p).replace(/\\/g, '/').toLowerCase().replace(/\/+$/, '');
62
+ }
63
+ /** Absolute path of a task's record file. */
64
+ function taskBasePath(taskId) {
65
+ return (0, node_path_1.join)(TASK_BASE_DIR, `${taskId}.json`);
66
+ }
67
+ function isRecord(value) {
68
+ const r = value;
69
+ return (!!r &&
70
+ typeof r.taskId === 'string' &&
71
+ typeof r.folder === 'string' &&
72
+ typeof r.branch === 'string' &&
73
+ typeof r.base === 'string');
74
+ }
75
+ /** The record for a task ON THIS FOLDER, or null. Never throws. */
76
+ function readTaskBase(taskId, folder) {
77
+ try {
78
+ const p = taskBasePath(taskId);
79
+ if (!(0, node_fs_1.existsSync)(p))
80
+ return null;
81
+ const parsed = JSON.parse((0, node_fs_1.readFileSync)(p, 'utf8'));
82
+ if (!isRecord(parsed))
83
+ return null;
84
+ if (norm(parsed.folder) !== norm(folder))
85
+ return null;
86
+ return parsed;
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ }
92
+ /** Every record on this machine, newest first. Never throws. */
93
+ function listTaskBases() {
94
+ const out = [];
95
+ let names = [];
96
+ try {
97
+ names = (0, node_fs_1.readdirSync)(TASK_BASE_DIR).filter((n) => n.endsWith('.json'));
98
+ }
99
+ catch {
100
+ return out;
101
+ }
102
+ for (const name of names) {
103
+ try {
104
+ const parsed = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(TASK_BASE_DIR, name), 'utf8'));
105
+ if (isRecord(parsed))
106
+ out.push(parsed);
107
+ }
108
+ catch {
109
+ /* a half-written or hand-edited record is ignored, never fatal */
110
+ }
111
+ }
112
+ out.sort((a, b) => (b.updatedAt ?? '').localeCompare(a.updatedAt ?? ''));
113
+ return out;
114
+ }
115
+ /** Atomic write (two processes may race the same task file). Never throws. */
116
+ function writeRecord(rec) {
117
+ try {
118
+ (0, node_fs_1.mkdirSync)(TASK_BASE_DIR, { recursive: true });
119
+ const target = taskBasePath(rec.taskId);
120
+ const tmp = `${target}.${process.pid}.tmp`;
121
+ (0, node_fs_1.writeFileSync)(tmp, JSON.stringify(rec, null, 2), 'utf8');
122
+ (0, node_fs_1.renameSync)(tmp, target);
123
+ }
124
+ catch (err) {
125
+ log(`could not persist the base for task ${rec.taskId.slice(0, 8)}: ${err instanceof Error ? err.message : String(err)}`);
126
+ }
127
+ }
128
+ /** Drop records whose task has not run in `TASK_BASE_TTL_MS`. Never throws. */
129
+ function pruneTaskBases(now = Date.now()) {
130
+ let removed = 0;
131
+ let names = [];
132
+ try {
133
+ names = (0, node_fs_1.readdirSync)(TASK_BASE_DIR);
134
+ }
135
+ catch {
136
+ return 0;
137
+ }
138
+ for (const name of names) {
139
+ const p = (0, node_path_1.join)(TASK_BASE_DIR, name);
140
+ try {
141
+ const age = now - (0, node_fs_1.statSync)(p).mtimeMs;
142
+ let dead = age > TASK_BASE_TTL_MS;
143
+ if (!dead) {
144
+ // A record whose linked folder is gone can never be reached again (a
145
+ // moved or deleted project). Dropping it keeps `doctor` honest and stops
146
+ // a dead workspace key from pinning an old branch forever.
147
+ try {
148
+ const rec = JSON.parse((0, node_fs_1.readFileSync)(p, 'utf8'));
149
+ const folder = isRecord(rec) ? rec.folder : '';
150
+ dead = !folder || !(0, node_fs_1.existsSync)(folder);
151
+ }
152
+ catch {
153
+ dead = true; // unreadable record
154
+ }
155
+ }
156
+ if (dead) {
157
+ (0, node_fs_1.rmSync)(p, { force: true });
158
+ removed += 1;
159
+ }
160
+ }
161
+ catch {
162
+ /* vanished mid-scan */
163
+ }
164
+ }
165
+ if (removed > 0)
166
+ log(`pruned ${removed} task base record(s) (expired or their folder is gone)`);
167
+ return removed;
168
+ }
169
+ /** True when `ref` resolves to a commit in `repo`. */
170
+ function resolves(repo, ref) {
171
+ if (!ref)
172
+ return false;
173
+ return (0, git_core_1.git)(repo, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]).ok;
174
+ }
175
+ /**
176
+ * Prefer the remote-tracking ref (fresh, and what a PR targets) but accept a
177
+ * local branch when there is no remote copy. Local-only is a real state: a
178
+ * previous attempt may have committed without credentials.
179
+ */
180
+ function preferRemote(repo, name) {
181
+ const ref = name.trim();
182
+ if (!ref)
183
+ return null;
184
+ if (!ref.startsWith('origin/') && resolves(repo, `origin/${ref}`)) {
185
+ return `origin/${ref}`;
186
+ }
187
+ return resolves(repo, ref) ? ref : null;
188
+ }
189
+ /**
190
+ * Resolve a recorded base inside a SPECIFIC repo (a multi-repo mirror shares one
191
+ * base NAME across repos that each have their own remotes).
192
+ *
193
+ * Accepts both `staging` and `origin/staging`, prefers the remote-tracking ref,
194
+ * and returns null when neither exists HERE — in which case the repo is simply
195
+ * not updated, rather than being merged with an unrelated branch.
196
+ */
197
+ function resolveBaseRefIn(repo, base) {
198
+ const ref = (base || '').trim();
199
+ if (!ref)
200
+ return null;
201
+ if (ref.startsWith('origin/')) {
202
+ if (resolves(repo, ref))
203
+ return ref;
204
+ return resolves(repo, ref.slice('origin/'.length))
205
+ ? ref.slice('origin/'.length)
206
+ : null;
207
+ }
208
+ return preferRemote(repo, ref);
209
+ }
210
+ /**
211
+ * The ladder for a task's FIRST run — deliberately the same order the mirror
212
+ * uses (`resolveBaseBranch`), minus branch continuation, because continuation
213
+ * IS this module.
214
+ */
215
+ function firstRunBase(folder, configuredBase) {
216
+ const configured = configuredBase
217
+ ? preferRemote(folder, configuredBase)
218
+ : null;
219
+ if (configured)
220
+ return { base: configured, source: 'project' };
221
+ const checkedOut = (0, git_branch_1.currentBranchName)(folder);
222
+ const folderRef = checkedOut ? preferRemote(folder, checkedOut) : null;
223
+ if (folderRef)
224
+ return { base: folderRef, source: 'folder' };
225
+ const sym = (0, git_core_1.git)(folder, [
226
+ 'symbolic-ref',
227
+ '--short',
228
+ 'refs/remotes/origin/HEAD',
229
+ ]);
230
+ const fromOriginHead = sym.ok ? preferRemote(folder, sym.out.trim()) : null;
231
+ if (fromOriginHead)
232
+ return { base: fromOriginHead, source: 'repo-default' };
233
+ for (const candidate of ['main', 'master']) {
234
+ const hit = preferRemote(folder, candidate);
235
+ if (hit)
236
+ return { base: hit, source: 'repo-default' };
237
+ }
238
+ return { base: null, source: 'repo-default' };
239
+ }
240
+ /**
241
+ * Decide the branch, the start point and the pull for one task.
242
+ *
243
+ * Pure decision-making: it reads git refs and the record, writes nothing. Both
244
+ * `createIsolationMirror` and the repair call it, which is the whole point —
245
+ * there is no second opinion anywhere in the bridge.
246
+ */
247
+ function planTaskBase(opts) {
248
+ const { folder, taskId } = opts;
249
+ const record = readTaskBase(taskId, folder);
250
+ const derived = (0, git_branch_1.desiredBranch)({
251
+ taskId,
252
+ projectSlug: opts.projectSlug ?? undefined,
253
+ taskTitle: opts.taskTitle ?? undefined,
254
+ ...(opts.deliverableBranch ? { branchName: opts.deliverableBranch } : {}),
255
+ ...(opts.deliveryBranch ? { deliveryBranch: opts.deliveryBranch } : {}),
256
+ });
257
+ // The record wins over a re-derivation: a task whose title was edited still
258
+ // has its work on the branch the FIRST run established, and a renamed task
259
+ // must not silently start a second, empty branch.
260
+ //
261
+ // The HUB's delivered branch outranks both (2026-12): after an agent-proposed
262
+ // rename the record still names the pre-rename branch, and honouring it would
263
+ // cut a fresh branch from the base instead of continuing the delivered work.
264
+ const delivered = (opts.deliveryBranch ?? '').trim();
265
+ const branch = delivered || record?.branch?.trim() || derived;
266
+ const localExists = resolves(folder, branch);
267
+ const remoteExists = resolves(folder, `origin/${branch}`);
268
+ const branchExists = localExists || remoteExists;
269
+ if (record && branch !== derived) {
270
+ log(`task ${taskId.slice(0, 8)} keeps its recorded branch ${branch} (derived would be ${derived})`);
271
+ }
272
+ // Pull target: the branch this task STARTED from. A recorded base that no
273
+ // longer resolves (deleted on the remote and pruned locally) is replaced by
274
+ // the current ladder and re-recorded by `recordTaskBase` below.
275
+ const recordedBase = record?.base?.trim() ?? '';
276
+ const recordedRef = recordedBase ? preferRemote(folder, recordedBase) : null;
277
+ const staleBase = recordedBase && !recordedRef ? recordedBase : undefined;
278
+ if (recordedRef) {
279
+ return {
280
+ taskId,
281
+ branch,
282
+ pullFrom: recordedRef,
283
+ baseSource: 'record',
284
+ branchSource: record ? 'record' : 'derived',
285
+ branchExists,
286
+ };
287
+ }
288
+ const fresh = firstRunBase(folder, opts.configuredBase ?? null);
289
+ if (staleBase) {
290
+ log(`task ${taskId.slice(0, 8)}: recorded base "${staleBase}" no longer resolves - using ${fresh.base ?? '(none)'}`);
291
+ }
292
+ if (!branchExists) {
293
+ // THE RULE (human, 2026-11-18): a missing branch never blocks a run. The
294
+ // tree is cut from the base and the branch is CREATED at that commit, so the
295
+ // run continues on its own branch from whatever state exists.
296
+ log(`task ${taskId.slice(0, 8)}: branch ${branch} does not exist yet - cutting the tree from ` +
297
+ `${fresh.base ?? 'the repo state'} and creating it there (continue)`);
298
+ }
299
+ return {
300
+ taskId,
301
+ branch,
302
+ pullFrom: fresh.base,
303
+ baseSource: fresh.source,
304
+ branchSource: record ? 'record' : 'derived',
305
+ branchExists,
306
+ ...(staleBase ? { staleBase } : {}),
307
+ };
308
+ }
309
+ /**
310
+ * Persist the plan for this task. Called ONCE per successful tree creation.
311
+ *
312
+ * The BASE is written once and then kept: it is "the branch this task started
313
+ * from", and a later project-setting change must not silently re-point an
314
+ * in-flight task's updates at another branch. Only a base that no longer
315
+ * resolves is replaced (self-heal), which `planTaskBase` reports as
316
+ * `staleBase`.
317
+ */
318
+ function recordTaskBase(opts) {
319
+ const { folder, plan } = opts;
320
+ const existing = readTaskBase(plan.taskId, folder);
321
+ const now = new Date().toISOString();
322
+ const base = (existing && !plan.staleBase ? existing.base : null) ??
323
+ opts.actualBase?.trim() ??
324
+ plan.pullFrom ??
325
+ '';
326
+ const rec = {
327
+ taskId: plan.taskId,
328
+ folder,
329
+ branch: plan.branch,
330
+ base: base || plan.pullFrom || '',
331
+ source: existing && !plan.staleBase ? existing.source : plan.baseSource,
332
+ createdAt: existing?.createdAt ?? now,
333
+ updatedAt: now,
334
+ runs: (existing?.runs ?? 0) + 1,
335
+ };
336
+ if (!rec.base)
337
+ return null;
338
+ writeRecord(rec);
339
+ pruneTaskBases();
340
+ return rec;
341
+ }
342
+ //# sourceMappingURL=task-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-base.js","sourceRoot":"","sources":["../../../src/lib/workspace/task-base.ts"],"names":[],"mappings":";;AAyGA,oCAEC;AAcD,oCAcC;AAGD,sCAoBC;AAoBD,wCAsCC;AA8BD,4CAUC;AA0CD,oCAuFC;AAWD,wCA6BC;AAzaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qCASiB;AACjB,qCAAkC;AAClC,yCAA0C;AAC1C,8CAAsC;AACtC,kDAAqE;AAErE,MAAM,GAAG,GAAG,CAAC,GAAW,EAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,EAAE,CAAC,CAAC;AAErE;;;GAGG;AACH,MAAM,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE;IACpC,IAAA,gBAAI,EAAC,IAAA,iBAAO,GAAE,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAE9C,+EAA+E;AAC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;QACpD,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE;QACvB,IAAI,CAAC,QAAQ;QACb,EAAE,CAAC;IAEL,MAAM,GAAG,GAAmB;QAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM;QACN,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE;QACjC,MAAM,EAAE,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU;QACvE,SAAS,EAAE,QAAQ,EAAE,SAAS,IAAI,GAAG;QACrC,SAAS,EAAE,GAAG;QACd,IAAI,EAAE,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC;KAChC,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAC3B,WAAW,CAAC,GAAG,CAAC,CAAC;IACjB,cAAc,EAAE,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamshare-bridge",
3
- "version": "0.28.24",
3
+ "version": "0.28.26",
4
4
  "description": "Local bridge for TeamShare agents - CLI session runner, auto-wake WebSocket daemon, and teamshare:// protocol handler.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",