@parall/cli 1.58.2 → 1.59.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.
@@ -1 +1 @@
1
- {"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../src/commands/slack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QA4IrD"}
1
+ {"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../src/commands/slack.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QA8NrD"}
@@ -1,3 +1,5 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
1
3
  import { resolveCredentials } from '../lib/client.js';
2
4
  import { printError, printJson } from '../lib/output.js';
3
5
  import { resolveMessageText, TEXT_FILE_OPTION_DESC, TEXT_OPTION_DESC } from '../lib/text-input.js';
@@ -24,13 +26,36 @@ export function registerSlackCommands(program) {
24
26
  .option('--text <text>', TEXT_OPTION_DESC)
25
27
  .option('--text-file <path>', TEXT_FILE_OPTION_DESC)
26
28
  .option('--reply-to <messageId>', 'Inbound message id you are answering ({channel}:{ts}, thread children {channel}:{root}#{ts}); REQUIRED in channels (reply lands in its thread). In DMs pass it too: a thread-child id lands the reply in that thread, a bare id keeps the main flow — the session never forks either way')
29
+ .option('--file <path>', 'Attach a local file: it posts into the addressed conversation/thread with --text as the comment')
27
30
  .action(async (opts) => {
28
31
  try {
29
32
  const text = resolveMessageText(opts);
33
+ const { client, orgId } = resolveCredentials();
34
+ if (opts.file) {
35
+ const filePath = path.resolve(opts.file);
36
+ // Pre-check before reading: the server caps files at 100MB, so an
37
+ // oversize input must fail here instead of exhausting CLI memory.
38
+ const stat = fs.statSync(filePath);
39
+ if (!stat.isFile()) {
40
+ throw new Error(`--file must be a regular file: ${filePath}`);
41
+ }
42
+ if (stat.size > 100 * 1024 * 1024) {
43
+ throw new Error(`--file exceeds the 100MB slack file limit (${stat.size} bytes)`);
44
+ }
45
+ const content = fs.readFileSync(filePath);
46
+ const sent = await client.sendSlackFile(orgId, {
47
+ conversationId: opts.channel,
48
+ fileName: path.basename(filePath),
49
+ content: new Blob([content]),
50
+ ...(opts.replyTo ? { replyTo: opts.replyTo } : {}),
51
+ ...(text ? { text } : {}),
52
+ });
53
+ printJson(sent);
54
+ return;
55
+ }
30
56
  if (text === undefined || text === '') {
31
- throw new Error('Provide --text or --text-file');
57
+ throw new Error('Provide --text, --text-file or --file');
32
58
  }
33
- const { client, orgId } = resolveCredentials();
34
59
  const sent = await client.sendChannelMessage(orgId, {
35
60
  channel_type: 'slack',
36
61
  conversation_id: opts.channel,
@@ -43,6 +68,51 @@ export function registerSlackCommands(program) {
43
68
  printError(err);
44
69
  }
45
70
  });
71
+ slack
72
+ .command('file')
73
+ .description('Download an inbound Slack file attachment into the working directory')
74
+ .requiredOption('--id <fileId>', 'Slack file id from the inbound attachment placeholder (e.g. F0123ABCD)')
75
+ .option('-o, --output <path>', 'Output file path (default: ./{original_filename})')
76
+ .option('--force', 'Overwrite an existing file at the output path')
77
+ .action(async (opts) => {
78
+ try {
79
+ const { client, orgId } = resolveCredentials();
80
+ const file = await client.downloadSlackFile(orgId, opts.id);
81
+ const safeName = path.basename(file.fileName || opts.id);
82
+ const outputPath = opts.output ? path.resolve(opts.output) : path.resolve(safeName);
83
+ const finalPath = fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()
84
+ ? path.join(outputPath, safeName)
85
+ : outputPath;
86
+ // The sender controls the file name — refuse to clobber an existing
87
+ // file unless the caller explicitly asked to, and never follow a
88
+ // symlink even then (a same-named link would redirect the write to
89
+ // its target).
90
+ let existing;
91
+ try {
92
+ existing = fs.lstatSync(finalPath);
93
+ }
94
+ catch {
95
+ existing = undefined;
96
+ }
97
+ if (existing?.isSymbolicLink()) {
98
+ throw new Error(`Refusing to write through a symlink: ${finalPath} — pass -o <path>`);
99
+ }
100
+ fs.writeFileSync(finalPath, Buffer.from(file.data), { flag: opts.force ? 'w' : 'wx' });
101
+ printJson({
102
+ path: finalPath,
103
+ file_name: safeName,
104
+ file_size: file.data.byteLength,
105
+ mime_type: file.mimeType,
106
+ });
107
+ }
108
+ catch (err) {
109
+ if (err?.code === 'EEXIST') {
110
+ printError(new Error('Output file already exists — pass --force to overwrite, or -o <path>'));
111
+ return;
112
+ }
113
+ printError(err);
114
+ }
115
+ });
46
116
  // Read verbs: workspace visibility as the bot sees it. Authorization is
47
117
  // the bot's own Slack permissions (invite it to a channel to read that
48
118
  // channel's history) — reads are not limited to seen conversations.
@@ -1 +1 @@
1
- {"version":3,"file":"wiki.d.ts","sourceRoot":"","sources":["../../src/commands/wiki.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0BpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAs/BpD"}
1
+ {"version":3,"file":"wiki.d.ts","sourceRoot":"","sources":["../../src/commands/wiki.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0BpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QA4/BpD"}
@@ -231,6 +231,10 @@ export function registerWikiCommands(program) {
231
231
  process.stderr.write(`${verb} changeset ${result.changeset.id} (${result.status})\n`);
232
232
  }
233
233
  process.stderr.write(`Changed files: ${result.changed_paths.join(', ')}\n`);
234
+ if (result.stale_recovery) {
235
+ const moved = result.stale_recovery.stale_paths.join(', ') || 'server check';
236
+ process.stderr.write(`Server had moved since your last sync (${moved}); re-synced and re-proposed automatically.\n`);
237
+ }
234
238
  process.stderr.write(`Next: ${result.next_action}\n`);
235
239
  printJson(result);
236
240
  }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Reconciling a local wiki workspace with a server that moved on:
3
+ *
4
+ * - a line-level three-way text merge, used by `wiki sync` when both the
5
+ * server and the workspace changed the same file, so non-overlapping
6
+ * edits merge instead of parking an upstream copy under conflicts/;
7
+ * - the stale-base recovery policy `changeset create` follows before it
8
+ * hands the situation back to the agent.
9
+ *
10
+ * Everything here is pure (no filesystem, no network) so the policy is
11
+ * unit-testable without a mock wiki-service.
12
+ */
13
+ import { ApiError } from '@parall/sdk';
14
+ import type { SyncConflict, WikiSyncOutcome } from './wiki.js';
15
+ /** Server error code: a file_change's base_sha no longer matches the default branch. */
16
+ export declare const STALE_BASE_CODE = "STALE_BASE";
17
+ /**
18
+ * How many times one propose call may recover from a stale base on its own.
19
+ * One covers "the server moved since my last sync". A second stale hit right
20
+ * after a fresh re-sync means someone is publishing to the same files right
21
+ * now — that is a decision for the caller, not a retry loop.
22
+ */
23
+ export declare const MAX_STALE_RECOVERIES = 1;
24
+ export type ThreeWayMergeResult = {
25
+ kind: 'clean';
26
+ merged: Buffer;
27
+ } | {
28
+ kind: 'conflict';
29
+ conflictRegions: number;
30
+ } | {
31
+ kind: 'not-mergeable';
32
+ reason: 'binary' | 'lfs-pointer' | 'too-complex';
33
+ };
34
+ /**
35
+ * Upper bound on the line-match pairs one diff may process. node-diff3's LCS
36
+ * walks every (line in A, identical line in B) pair, so a file with many
37
+ * repeated lines (blank lines, table separators) costs occurrences² — about
38
+ * 1 s per million pairs on a laptop, 7–8 s at four million. Above the budget
39
+ * the merge is skipped in favour of the conflict marker: slow but correct is
40
+ * still a hang from the agent's point of view.
41
+ */
42
+ export declare const MERGE_MATCH_PAIR_BUDGET = 1000000;
43
+ /**
44
+ * Upper bound on lines per side. Independently of repeated lines, node-diff3
45
+ * scans a growing candidate array once per matched line, so even all-unique
46
+ * files cost roughly lines²: ≈90 ms at 10,000 lines and ≈200 ms at 15,000
47
+ * on a laptop (both sides editing distant regions), ≈4.7 s at 50,000 in
48
+ * review. 15,000 lines is far above any wiki document that is still a
49
+ * document; beyond it the merge is skipped for the conflict marker.
50
+ */
51
+ export declare const MERGE_MAX_LINES = 15000;
52
+ /**
53
+ * Number of (i, j) pairs with a[i] === b[j] — the work an LCS over the two
54
+ * line arrays performs — computed in O(|a| + |b|) from line multiplicities.
55
+ */
56
+ export declare function countMatchPairs(a: readonly string[], b: readonly string[]): number;
57
+ /**
58
+ * Merge `local` and `remote`, both derived from `base`, at line granularity.
59
+ * Clean when every changed region was touched by one side only, or both
60
+ * sides made the identical change; overlapping hunks are never auto-resolved.
61
+ * diff3 semantics: two changed regions overlap when no unchanged line
62
+ * separates them, so adjacent edits conflict even if they touch different
63
+ * lines — that is deliberate (git behaves the same) and the skill text says
64
+ * so.
65
+ * Binary content and Git LFS pointers are refused — a line merge of either
66
+ * would corrupt the file — so the caller keeps its conflict-marker path.
67
+ */
68
+ export declare function mergeTextThreeWay(input: {
69
+ base: Buffer;
70
+ local: Buffer;
71
+ remote: Buffer;
72
+ isText: (content: Buffer) => boolean;
73
+ }): ThreeWayMergeResult;
74
+ export type StalePath = {
75
+ path: string;
76
+ /** What the server did to this path since the workspace last synced it. */
77
+ reason: 'modified' | 'deleted' | 'created';
78
+ };
79
+ /**
80
+ * Compare each locally changed path's sync baseline against the server's
81
+ * current blob SHA. A locally created file is stale when the server now has
82
+ * one at that path; an update/delete is stale when the server's copy changed
83
+ * or vanished.
84
+ */
85
+ export declare function findStalePaths(input: {
86
+ changedPaths: Iterable<string>;
87
+ /** Sync-baseline blob SHA; undefined for a locally created file. */
88
+ baseSha: (path: string) => string | undefined;
89
+ /** Current server blob SHA; undefined when the server has no such path. */
90
+ serverSha: (path: string) => string | undefined;
91
+ }): StalePath[];
92
+ export declare function describeStalePath(stale: StalePath): string;
93
+ export type StaleRecoveryDecision = {
94
+ kind: 'retry';
95
+ } | {
96
+ kind: 'stop';
97
+ reason: 'failures' | 'conflicts' | 'retries-exhausted';
98
+ };
99
+ /**
100
+ * After a stale-base hit and a re-sync, decide whether propose may run again.
101
+ * Failures and conflicts always win over the retry budget: an exhausted
102
+ * budget with a clean sync means "the server keeps moving", but leftover
103
+ * conflicts are the more useful thing to tell the agent about.
104
+ */
105
+ export declare function decideStaleRecovery(input: {
106
+ /** Number of automatic recoveries already spent in this propose call. */
107
+ attempt: number;
108
+ outcome: WikiSyncOutcome;
109
+ }): StaleRecoveryDecision;
110
+ /** What an automatic stale-base recovery did, reported alongside the propose result. */
111
+ export type StaleRecoveryReport = {
112
+ /** Locally changed paths whose server copy had moved since the last sync. */
113
+ stale_paths: string[];
114
+ /** Who noticed: the CLI precheck against the server manifest, or the server's 409. */
115
+ detected_by: 'precheck' | 'server';
116
+ /** What the automatic re-sync did before re-proposing. */
117
+ sync: {
118
+ applied: number;
119
+ fast_forwarded: number;
120
+ merged: string[];
121
+ };
122
+ };
123
+ export declare function isStaleBaseError(err: unknown): err is ApiError;
124
+ export declare function formatStaleRecoveryError(input: {
125
+ stale: StalePath[];
126
+ decision: Extract<StaleRecoveryDecision, {
127
+ kind: 'stop';
128
+ }>;
129
+ outcome: WikiSyncOutcome;
130
+ /** Absolute marker path for a conflict: the upstream copy, or the remote-deleted marker. */
131
+ markerPath: (conflict: SyncConflict) => string;
132
+ }): string;
133
+ //# sourceMappingURL=wiki-merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wiki-merge.d.ts","sourceRoot":"","sources":["../../src/lib/wiki-merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE/D,wFAAwF;AACxF,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAMtC,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,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AE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,mBAAmB,CAAA;CAAE,CAAC;AAE7E;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,eAAe,CAAC;CAC1B,GAAG,qBAAqB,CAKxB;AAED,wFAAwF;AACxF,MAAM,MAAM,mBAAmB,GAAG;IAChC,6EAA6E;IAC7E,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,sFAAsF;IACtF,WAAW,EAAE,UAAU,GAAG,QAAQ,CAAC;IACnC,0DAA0D;IAC1D,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACrE,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,QAAQ,CAE9D;AAuBD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC,qBAAqB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3D,OAAO,EAAE,eAAe,CAAC;IACzB,4FAA4F;IAC5F,UAAU,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,MAAM,CAAC;CAChD,GAAG,MAAM,CA+CT"}
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Reconciling a local wiki workspace with a server that moved on:
3
+ *
4
+ * - a line-level three-way text merge, used by `wiki sync` when both the
5
+ * server and the workspace changed the same file, so non-overlapping
6
+ * edits merge instead of parking an upstream copy under conflicts/;
7
+ * - the stale-base recovery policy `changeset create` follows before it
8
+ * hands the situation back to the agent.
9
+ *
10
+ * Everything here is pure (no filesystem, no network) so the policy is
11
+ * unit-testable without a mock wiki-service.
12
+ */
13
+ import { ApiError } from '@parall/sdk';
14
+ import { diff3Merge } from 'node-diff3';
15
+ /** Server error code: a file_change's base_sha no longer matches the default branch. */
16
+ export const STALE_BASE_CODE = 'STALE_BASE';
17
+ /**
18
+ * How many times one propose call may recover from a stale base on its own.
19
+ * One covers "the server moved since my last sync". A second stale hit right
20
+ * after a fresh re-sync means someone is publishing to the same files right
21
+ * now — that is a decision for the caller, not a retry loop.
22
+ */
23
+ export const MAX_STALE_RECOVERIES = 1;
24
+ const LFS_POINTER_PREFIX = 'version https://git-lfs.github.com/spec/';
25
+ /**
26
+ * Upper bound on the line-match pairs one diff may process. node-diff3's LCS
27
+ * walks every (line in A, identical line in B) pair, so a file with many
28
+ * repeated lines (blank lines, table separators) costs occurrences² — about
29
+ * 1 s per million pairs on a laptop, 7–8 s at four million. Above the budget
30
+ * the merge is skipped in favour of the conflict marker: slow but correct is
31
+ * still a hang from the agent's point of view.
32
+ */
33
+ export const MERGE_MATCH_PAIR_BUDGET = 1_000_000;
34
+ /**
35
+ * Upper bound on lines per side. Independently of repeated lines, node-diff3
36
+ * scans a growing candidate array once per matched line, so even all-unique
37
+ * files cost roughly lines²: ≈90 ms at 10,000 lines and ≈200 ms at 15,000
38
+ * on a laptop (both sides editing distant regions), ≈4.7 s at 50,000 in
39
+ * review. 15,000 lines is far above any wiki document that is still a
40
+ * document; beyond it the merge is skipped for the conflict marker.
41
+ */
42
+ export const MERGE_MAX_LINES = 15_000;
43
+ /**
44
+ * Number of (i, j) pairs with a[i] === b[j] — the work an LCS over the two
45
+ * line arrays performs — computed in O(|a| + |b|) from line multiplicities.
46
+ */
47
+ export function countMatchPairs(a, b) {
48
+ const counts = new Map();
49
+ for (const line of a)
50
+ counts.set(line, (counts.get(line) ?? 0) + 1);
51
+ let pairs = 0;
52
+ for (const line of b) {
53
+ pairs += counts.get(line) ?? 0;
54
+ }
55
+ return pairs;
56
+ }
57
+ /**
58
+ * Merge `local` and `remote`, both derived from `base`, at line granularity.
59
+ * Clean when every changed region was touched by one side only, or both
60
+ * sides made the identical change; overlapping hunks are never auto-resolved.
61
+ * diff3 semantics: two changed regions overlap when no unchanged line
62
+ * separates them, so adjacent edits conflict even if they touch different
63
+ * lines — that is deliberate (git behaves the same) and the skill text says
64
+ * so.
65
+ * Binary content and Git LFS pointers are refused — a line merge of either
66
+ * would corrupt the file — so the caller keeps its conflict-marker path.
67
+ */
68
+ export function mergeTextThreeWay(input) {
69
+ for (const buf of [input.base, input.local, input.remote]) {
70
+ if (!input.isText(buf))
71
+ return { kind: 'not-mergeable', reason: 'binary' };
72
+ if (buf.toString('utf8', 0, LFS_POINTER_PREFIX.length) === LFS_POINTER_PREFIX) {
73
+ return { kind: 'not-mergeable', reason: 'lfs-pointer' };
74
+ }
75
+ }
76
+ const localLines = splitLines(input.local.toString('utf8'));
77
+ const baseLines = splitLines(input.base.toString('utf8'));
78
+ const remoteLines = splitLines(input.remote.toString('utf8'));
79
+ // Two independent cost drivers, both bounded before diff3 runs: sheer
80
+ // length (candidate-array scans grow with the LCS) and repeated lines
81
+ // (identical-line pairs). diff3 runs two LCS passes (base↔local,
82
+ // base↔remote); budget each.
83
+ if (Math.max(baseLines.length, localLines.length, remoteLines.length) > MERGE_MAX_LINES) {
84
+ return { kind: 'not-mergeable', reason: 'too-complex' };
85
+ }
86
+ if (countMatchPairs(baseLines, localLines) > MERGE_MATCH_PAIR_BUDGET ||
87
+ countMatchPairs(baseLines, remoteLines) > MERGE_MATCH_PAIR_BUDGET) {
88
+ return { kind: 'not-mergeable', reason: 'too-complex' };
89
+ }
90
+ const regions = diff3Merge(localLines, baseLines, remoteLines, { excludeFalseConflicts: true });
91
+ const out = [];
92
+ let conflictRegions = 0;
93
+ for (const region of regions) {
94
+ if (region.ok) {
95
+ out.push(...region.ok);
96
+ }
97
+ else if (region.conflict) {
98
+ conflictRegions++;
99
+ }
100
+ }
101
+ if (conflictRegions > 0)
102
+ return { kind: 'conflict', conflictRegions };
103
+ return { kind: 'clean', merged: Buffer.from(out.join(''), 'utf8') };
104
+ }
105
+ /**
106
+ * Split into lines that keep their own terminator (`\n` or `\r\n`), so a
107
+ * merge round-trips byte-exactly: joining the pieces back reproduces the
108
+ * input, including a missing trailing newline on the last line.
109
+ */
110
+ function splitLines(text) {
111
+ if (text === '')
112
+ return [];
113
+ const parts = text.split('\n');
114
+ const last = parts.pop();
115
+ const lines = parts.map((line) => `${line}\n`);
116
+ if (last !== '')
117
+ lines.push(last);
118
+ return lines;
119
+ }
120
+ /**
121
+ * Compare each locally changed path's sync baseline against the server's
122
+ * current blob SHA. A locally created file is stale when the server now has
123
+ * one at that path; an update/delete is stale when the server's copy changed
124
+ * or vanished.
125
+ */
126
+ export function findStalePaths(input) {
127
+ const stale = [];
128
+ for (const filePath of input.changedPaths) {
129
+ const base = input.baseSha(filePath);
130
+ const server = input.serverSha(filePath);
131
+ if (base === undefined) {
132
+ if (server !== undefined)
133
+ stale.push({ path: filePath, reason: 'created' });
134
+ }
135
+ else if (server === undefined) {
136
+ stale.push({ path: filePath, reason: 'deleted' });
137
+ }
138
+ else if (server !== base) {
139
+ stale.push({ path: filePath, reason: 'modified' });
140
+ }
141
+ }
142
+ return stale;
143
+ }
144
+ export function describeStalePath(stale) {
145
+ return `${stale.path} (${stale.reason} on the server since your last sync)`;
146
+ }
147
+ /**
148
+ * After a stale-base hit and a re-sync, decide whether propose may run again.
149
+ * Failures and conflicts always win over the retry budget: an exhausted
150
+ * budget with a clean sync means "the server keeps moving", but leftover
151
+ * conflicts are the more useful thing to tell the agent about.
152
+ */
153
+ export function decideStaleRecovery(input) {
154
+ if (input.outcome.failed.length > 0)
155
+ return { kind: 'stop', reason: 'failures' };
156
+ if (input.outcome.conflicts.length > 0)
157
+ return { kind: 'stop', reason: 'conflicts' };
158
+ if (input.attempt >= MAX_STALE_RECOVERIES)
159
+ return { kind: 'stop', reason: 'retries-exhausted' };
160
+ return { kind: 'retry' };
161
+ }
162
+ export function isStaleBaseError(err) {
163
+ return err instanceof ApiError && err.code === STALE_BASE_CODE;
164
+ }
165
+ /**
166
+ * The one resolution sequence that terminates.
167
+ *
168
+ * `sync` advances a path's baseline only when the working file matches the
169
+ * server byte-for-byte (`planSyncActions`: `localSha === remoteSha` →
170
+ * fast-forward). So hand-merging both sides into the file and proposing keeps
171
+ * the stale baseline: propose sends the old `base_sha`, the server answers
172
+ * 409, recovery re-syncs, the path conflicts again — the same error forever.
173
+ * Matching the server first is what lets `sync` move the baseline; the local
174
+ * edits are then re-applied on top of a current file.
175
+ */
176
+ const RESOLVE_CONFLICT_STEPS = 'Resolve each path in THIS order — matching the server first is what lets `sync` advance your baseline:\n' +
177
+ ' 1. Save your version aside: `cp <path> <path>.mine`\n' +
178
+ ' 2. Make the working copy match the server: `cp <upstream copy> <path>` ' +
179
+ '(for a `.remote-deleted` marker: `rm <path>`)\n' +
180
+ ' 3. `parall wiki sync` — your baseline advances only now\n' +
181
+ ' 4. Re-apply your changes to the now-current file using `<path>.mine`, then delete it and the marker\n' +
182
+ ' 5. Propose again.\n' +
183
+ 'Do NOT hand-merge and propose without step 2+3: the baseline stays stale and you get this same error every time.';
184
+ export function formatStaleRecoveryError(input) {
185
+ const moved = input.stale.length > 0
186
+ ? `${input.stale.length} file(s) changed on the server since your last sync:\n` +
187
+ input.stale.map((s) => ` ${describeStalePath(s)}`).join('\n')
188
+ : 'the server rejected the proposal as based on a stale sync';
189
+ switch (input.decision.reason) {
190
+ case 'conflicts': {
191
+ const lines = input.outcome.conflicts
192
+ .map((c) => ` ${c.path} — ${describeConflict(c)}; ` +
193
+ `${c.remoteCopyPath ? 'upstream copy' : 'marker'}: ${input.markerPath(c)}`)
194
+ .join('\n');
195
+ // "Untouched" is only true of the conflicting paths. The same recovery
196
+ // can have merged other paths cleanly, rewriting those working copies —
197
+ // say so, or the caller re-reads a file it believes it still owns.
198
+ const mergedNote = input.outcome.merged.length > 0
199
+ ? `Other path(s) merged cleanly and their working copies were rewritten (no action needed): ${input.outcome.merged.join(', ')}.\n`
200
+ : '';
201
+ return (`cannot propose: ${moved}\n` +
202
+ `Re-synced, but ${input.outcome.conflicts.length} file(s) need your decision — ` +
203
+ `your working copy of these paths was not modified:\n${lines}\n` +
204
+ mergedNote +
205
+ RESOLVE_CONFLICT_STEPS);
206
+ }
207
+ case 'failures': {
208
+ const lines = input.outcome.failed
209
+ .map((f) => ` ${f.path} — ${f.reason}${f.detail ? `: ${f.detail}` : ''}`)
210
+ .join('\n');
211
+ return (`cannot propose: ${moved}\n` +
212
+ `Re-syncing failed for ${input.outcome.failed.length} path(s):\n${lines}\n` +
213
+ 'Run `parall wiki sync` again (transient failures retry), then propose again.');
214
+ }
215
+ case 'retries-exhausted':
216
+ return (`cannot propose: ${moved}\n` +
217
+ 'Re-synced once already, and the server moved again before the re-proposal landed — ' +
218
+ 'someone else is publishing to the same files right now. Wait a moment, run `parall wiki sync`, then propose again.');
219
+ }
220
+ }
221
+ function describeConflict(conflict) {
222
+ switch (conflict.reason) {
223
+ case 'remote-changed-local-edited':
224
+ return 'both you and the server changed it and the changes overlap';
225
+ case 'remote-deleted-local-edited':
226
+ return 'the server deleted it and you still have edits';
227
+ case 'remote-added-local-collides':
228
+ return 'the server created this path with different content';
229
+ case 'remote-changed-local-deleted':
230
+ return 'the server changed it and you deleted it';
231
+ }
232
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"wiki-tools.d.ts","sourceRoot":"","sources":["../../src/lib/wiki-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAG5B,OAAO,EASL,KAAK,aAAa,EAInB,MAAM,WAAW,CAAC;AAUnB;;;;;;;;;GASG;AAEH,MAAM,MAAM,uBAAuB,GAAG;IACpC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,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export function buildWikiTools(ctx) {
517
517
  fastForwarded: z.number(),
518
518
  conflicts: z.array(z.unknown()),
519
519
  failed: z.array(z.unknown()),
520
+ merged: z.array(z.string()).optional(),
520
521
  })
521
522
  .nullable(),
522
523
  post_merge_sync_error: z.string().nullable(),
524
+ stale_recovery: z
525
+ .object({
526
+ stale_paths: z.array(z.string()),
527
+ detected_by: z.enum(['precheck', 'server']),
528
+ sync: z.object({
529
+ applied: z.number(),
530
+ fast_forwarded: z.number(),
531
+ merged: z.array(z.string()),
532
+ }),
533
+ })
534
+ .nullable(),
523
535
  diff_files: z.array(z.object({
524
536
  path: z.string(),
525
537
  additions: z.number(),
@@ -1,4 +1,5 @@
1
1
  import { type ParallClient, type Wiki, type WikiChangeset, type WikiDiff, type WikiDiffFile, type WikiTreeEntry } from '@parall/sdk';
2
+ import { type StaleRecoveryReport } from './wiki-merge.js';
2
3
  export { type ParsedFrontMatter, parseFrontMatter } from './wiki-frontmatter.js';
3
4
  export type ParallContext = {
4
5
  client: ParallClient;
@@ -127,6 +128,8 @@ export type WikiProposeResult = {
127
128
  next_action: string;
128
129
  post_merge_sync: WikiSyncOutcome | null;
129
130
  post_merge_sync_error: string | null;
131
+ /** Set when the server had moved since the last sync and propose re-synced and retried on its own. */
132
+ stale_recovery: StaleRecoveryReport | null;
130
133
  source: 'local_mount';
131
134
  };
132
135
  type WikiContentSource = 'local_mount' | 'api';
@@ -280,6 +283,8 @@ export type SyncResult = {
280
283
  fastForwarded: number;
281
284
  conflicts: SyncConflict[];
282
285
  failed: SyncFailure[];
286
+ /** Paths where non-overlapping local and upstream edits were merged into the working copy. */
287
+ merged: string[];
283
288
  }[];
284
289
  };
285
290
  /**
@@ -379,6 +384,12 @@ export type WikiSyncOutcome = {
379
384
  conflicts: SyncConflict[];
380
385
  /** Per-path failures that prevented a planned action from running. Manifest is left unchanged for these — next sync retries. */
381
386
  failed: SyncFailure[];
387
+ /**
388
+ * Paths both sides edited whose changes did not overlap: the upstream
389
+ * change was merged into the working copy at line level and the manifest
390
+ * advanced to the remote blob. Local edits stay pending for propose.
391
+ */
392
+ merged: string[];
382
393
  };
383
394
  export declare function syncSingleWiki(ctx: ParallContext, wiki: import('@parall/sdk').Wiki, mountPath: string): Promise<WikiSyncOutcome>;
384
395
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"wiki.d.ts","sourceRoot":"","sources":["../../src/lib/wiki.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAMrB,OAAO,EAAE,KAAK,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAMjF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,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,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAYjB;AAiJD,wBAAgB,eAAe,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM,CAQ3D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAKpE;AA+DD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMzD;AA+BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAuB1D;AAoqCD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAmB5D;AA+ED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM/D"}
package/dist/lib/wiki.js CHANGED
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  import { ApiError, } from '@parall/sdk';
5
5
  import { structuredPatch } from 'diff';
6
6
  import { hasFrontMatter, parseFrontMatter } from './wiki-frontmatter.js';
7
+ import { decideStaleRecovery, findStalePaths, formatStaleRecoveryError, isStaleBaseError, mergeTextThreeWay, } from './wiki-merge.js';
7
8
  // Re-exported so consumers (and tests) can reach the frontmatter parser via the
8
9
  // wiki module surface alongside detectFrontMatterEnd.
9
10
  export { parseFrontMatter } from './wiki-frontmatter.js';
@@ -347,41 +348,81 @@ export async function proposeWikiChangeset(ctx, wikiRef, options) {
347
348
  if (!title) {
348
349
  throw new Error('title is required');
349
350
  }
351
+ // Stale-base recovery loop. A stale base (the server moved since the last
352
+ // sync) is recovered automatically: re-sync — a three-way merge that keeps
353
+ // local edits — then propose again, at most MAX_STALE_RECOVERIES times.
354
+ // Anything the merge could not settle (overlapping edits, download
355
+ // failures, a server that keeps moving) surfaces as an error that names the
356
+ // paths and the next step; the workspace is never rolled back.
357
+ let recovery = null;
358
+ for (let attempt = 0;; attempt++) {
359
+ const outcome = await proposeOnce(ctx, wiki, mount, title, options, recovery);
360
+ if (outcome.kind === 'submitted') {
361
+ return outcome.result;
362
+ }
363
+ recovery = await recoverFromStaleBase(ctx, wiki, mount, {
364
+ stale: outcome.stale,
365
+ detectedBy: outcome.detectedBy,
366
+ attempt,
367
+ });
368
+ }
369
+ }
370
+ /**
371
+ * Re-sync after a stale-base hit and decide whether propose may run again.
372
+ * Throws the agent-facing guidance when it may not.
373
+ */
374
+ async function recoverFromStaleBase(ctx, wiki, mount, input) {
375
+ const outcome = await syncSingleWiki(ctx, wiki, mount.root);
376
+ const decision = decideStaleRecovery({ attempt: input.attempt, outcome });
377
+ if (decision.kind === 'stop') {
378
+ throw new Error(formatStaleRecoveryError({
379
+ stale: input.stale,
380
+ decision,
381
+ outcome,
382
+ markerPath: (conflict) => conflict.remoteCopyPath ??
383
+ path.join(mount.root, PRLL_WIKI_DIR, CONFLICTS_DIR, conflict.path + REMOTE_DELETED_MARKER_SUFFIX),
384
+ }));
385
+ }
386
+ return {
387
+ stale_paths: input.stale.map((s) => s.path),
388
+ detected_by: input.detectedBy,
389
+ sync: {
390
+ applied: outcome.applied,
391
+ fast_forwarded: outcome.fastForwarded,
392
+ merged: outcome.merged,
393
+ },
394
+ };
395
+ }
396
+ /**
397
+ * Stale-base precheck (fail-closed): compare each changed path's sync
398
+ * baseline against the server's CURRENT manifest. Proposing from a stale
399
+ * baseline would upload full content that silently rolls back concurrent
400
+ * edits. The server re-validates via base_sha (authoritative — this check
401
+ * just catches it earlier, with the complete file list).
402
+ */
403
+ async function findStalePathsAgainstServer(mount, diff) {
404
+ const serverManifest = (await wikiServiceFetch(mount.manifestUrl, requireMountToken(mount)));
405
+ const serverShaByPath = new Map(serverManifest.data.map((e) => [e.path, e.sha]));
406
+ return findStalePaths({
407
+ changedPaths: diff.changedPaths,
408
+ baseSha: (p) => diff.baseShaByPath.get(p),
409
+ serverSha: (p) => serverShaByPath.get(p),
410
+ });
411
+ }
412
+ async function proposeOnce(ctx, wiki, mount, title, options, recovery) {
350
413
  const manifest = await readLocalManifest(mount.root);
351
414
  const diff = await computeLocalDiff(mount, manifest);
352
415
  if (diff.changedPaths.length === 0) {
416
+ if (recovery) {
417
+ throw new Error(`nothing left to propose for wiki ${wiki.slug}: the server already has your changes ` +
418
+ `(re-sync fast-forwarded ${recovery.stale_paths.join(', ')}).`);
419
+ }
353
420
  throw new Error(`no changes to propose for wiki ${wiki.slug} — edit files under ${mount.root} first, ` +
354
421
  'then run `parall wiki diff` to confirm what will be proposed');
355
422
  }
356
- // Stale-base precheck (fail-closed): compare each changed path's sync
357
- // baseline against the server's CURRENT manifest. Proposing from a stale
358
- // baseline would upload full content that silently rolls back concurrent
359
- // edits. The server re-validates via base_sha (authoritative — this check
360
- // just fails earlier with the complete file list).
361
- const serverManifest = (await wikiServiceFetch(mount.manifestUrl, requireMountToken(mount)));
362
- const serverShaByPath = new Map(serverManifest.data.map((e) => [e.path, e.sha]));
363
- const staleLines = [];
364
- for (const filePath of diff.changedPaths) {
365
- const baseSha = diff.baseShaByPath.get(filePath);
366
- const serverSha = serverShaByPath.get(filePath);
367
- if (baseSha === undefined) {
368
- // Locally created file — stale if the server got one in the meantime.
369
- if (serverSha !== undefined) {
370
- staleLines.push(`${filePath} (created on the server since your last sync)`);
371
- }
372
- }
373
- else if (serverSha === undefined) {
374
- staleLines.push(`${filePath} (deleted on the server since your last sync)`);
375
- }
376
- else if (serverSha !== baseSha) {
377
- staleLines.push(`${filePath} (modified on the server since your last sync)`);
378
- }
379
- }
380
- if (staleLines.length > 0) {
381
- throw new Error(`cannot propose: ${staleLines.length} file(s) changed on the server since your last sync:\n` +
382
- staleLines.map((l) => ` ${l}`).join('\n') +
383
- '\nRun `parall wiki sync` to pull the latest content (your local edits are preserved; ' +
384
- 'conflicting files get a marker under .parall-wiki/conflicts/), resolve if needed, then propose again.');
423
+ const stale = await findStalePathsAgainstServer(mount, diff);
424
+ if (stale.length > 0) {
425
+ return { kind: 'stale', stale, detectedBy: 'precheck' };
385
426
  }
386
427
  // Build file_changes for the changeset API
387
428
  const fileChanges = [];
@@ -420,29 +461,44 @@ export async function proposeWikiChangeset(ctx, wikiRef, options) {
420
461
  }
421
462
  let changeset;
422
463
  const existingChangesetId = normalizeOptionalString(options.changesetId);
423
- if (existingChangesetId) {
424
- // Re-propose: replace_files makes the workspace diff define the
425
- // changeset's FULL content — the server resets the feature branch to
426
- // default HEAD first, so a change withdrawn locally (file reverted to
427
- // baseline) actually disappears from the proposal instead of silently
428
- // surviving on the branch.
429
- changeset = await ctx.client.updateWikiChangeset(ctx.orgId, wiki.id, existingChangesetId, {
430
- title,
431
- message: normalizeOptionalString(options.message),
432
- file_changes: fileChanges,
433
- replace_files: true,
434
- });
464
+ try {
465
+ if (existingChangesetId) {
466
+ // Re-propose: replace_files makes the workspace diff define the
467
+ // changeset's FULL content — the server resets the feature branch to
468
+ // default HEAD first, so a change withdrawn locally (file reverted to
469
+ // baseline) actually disappears from the proposal instead of silently
470
+ // surviving on the branch.
471
+ changeset = await ctx.client.updateWikiChangeset(ctx.orgId, wiki.id, existingChangesetId, {
472
+ title,
473
+ message: normalizeOptionalString(options.message),
474
+ file_changes: fileChanges,
475
+ replace_files: true,
476
+ });
477
+ }
478
+ else {
479
+ // Create new changeset via API
480
+ changeset = await ctx.client.createWikiChangeset(ctx.orgId, wiki.id, {
481
+ title,
482
+ message: normalizeOptionalString(options.message),
483
+ file_changes: fileChanges,
484
+ source_chat_id: normalizeOptionalString(options.sourceChatId),
485
+ source_message_id: normalizeOptionalString(options.sourceMessageId),
486
+ source_run_id: normalizeOptionalString(options.sourceRunId),
487
+ });
488
+ }
435
489
  }
436
- else {
437
- // Create new changeset via API
438
- changeset = await ctx.client.createWikiChangeset(ctx.orgId, wiki.id, {
439
- title,
440
- message: normalizeOptionalString(options.message),
441
- file_changes: fileChanges,
442
- source_chat_id: normalizeOptionalString(options.sourceChatId),
443
- source_message_id: normalizeOptionalString(options.sourceMessageId),
444
- source_run_id: normalizeOptionalString(options.sourceRunId),
445
- });
490
+ catch (error) {
491
+ // The server's base_sha check is authoritative and closes the window
492
+ // between the precheck and the write. Treat it exactly like a precheck
493
+ // hit: the caller re-syncs and retries.
494
+ if (!isStaleBaseError(error)) {
495
+ throw error;
496
+ }
497
+ return {
498
+ kind: 'stale',
499
+ stale: await findStalePathsAgainstServer(mount, diff),
500
+ detectedBy: 'server',
501
+ };
446
502
  }
447
503
  const autoMerged = changeset.status === 'merged';
448
504
  let postMergeSync = null;
@@ -456,20 +512,24 @@ export async function proposeWikiChangeset(ctx, wikiRef, options) {
456
512
  }
457
513
  }
458
514
  return {
459
- wiki_id: wiki.id,
460
- wiki_slug: wiki.slug,
461
- wiki_name: wiki.name,
462
- mount_path: mount.root,
463
- changed_paths: diff.changedPaths,
464
- diff_files: diff.diffFiles,
465
- changeset,
466
- status: changeset.status,
467
- auto_merged: autoMerged,
468
- requires_review: changesetRequiresReview(changeset),
469
- next_action: describeProposeNextAction(changeset, postMergeSync, postMergeSyncError),
470
- post_merge_sync: postMergeSync,
471
- post_merge_sync_error: postMergeSyncError,
472
- source: 'local_mount',
515
+ kind: 'submitted',
516
+ result: {
517
+ wiki_id: wiki.id,
518
+ wiki_slug: wiki.slug,
519
+ wiki_name: wiki.name,
520
+ mount_path: mount.root,
521
+ changed_paths: diff.changedPaths,
522
+ diff_files: diff.diffFiles,
523
+ changeset,
524
+ status: changeset.status,
525
+ auto_merged: autoMerged,
526
+ requires_review: changesetRequiresReview(changeset),
527
+ next_action: describeProposeNextAction(changeset, postMergeSync, postMergeSyncError, recovery),
528
+ post_merge_sync: postMergeSync,
529
+ post_merge_sync_error: postMergeSyncError,
530
+ stale_recovery: recovery,
531
+ source: 'local_mount',
532
+ },
473
533
  };
474
534
  }
475
535
  function changesetRequiresReview(changeset) {
@@ -477,7 +537,19 @@ function changesetRequiresReview(changeset) {
477
537
  changeset.status === 'approval_pending' ||
478
538
  changeset.status === 'approved');
479
539
  }
480
- function describeProposeNextAction(changeset, postMergeSync, postMergeSyncError) {
540
+ function describeProposeNextAction(changeset, postMergeSync, postMergeSyncError, recovery) {
541
+ const prefix = recovery ? `${describeStaleRecovery(recovery)} ` : '';
542
+ return prefix + describeChangesetNextAction(changeset, postMergeSync, postMergeSyncError);
543
+ }
544
+ /** One sentence on what the automatic stale-base recovery did, for the agent's log. */
545
+ function describeStaleRecovery(recovery) {
546
+ const where = recovery.stale_paths.length > 0 ? ` (${recovery.stale_paths.join(', ')})` : '';
547
+ const merged = recovery.sync.merged.length > 0
548
+ ? `, merged the upstream changes into ${recovery.sync.merged.join(', ')} (no overlapping hunks)`
549
+ : '';
550
+ return `The server had moved since your last sync${where}: re-synced${merged}, then re-proposed automatically.`;
551
+ }
552
+ function describeChangesetNextAction(changeset, postMergeSync, postMergeSyncError) {
481
553
  if (changeset.status === 'merged') {
482
554
  if (postMergeSyncError) {
483
555
  return 'Changeset auto-merged. Run `parall wiki sync` to refresh the local manifest.';
@@ -676,6 +748,7 @@ export async function syncAllMounts(ctx, wikiRef) {
676
748
  fastForwarded: outcome.fastForwarded,
677
749
  conflicts: outcome.conflicts,
678
750
  failed: outcome.failed,
751
+ merged: outcome.merged,
679
752
  });
680
753
  }
681
754
  if (!target) {
@@ -837,6 +910,7 @@ export async function syncSingleWiki(ctx, wiki, mountPath) {
837
910
  const downloadedBySha = new Map();
838
911
  const conflicts = [];
839
912
  const failed = [];
913
+ const merged = [];
840
914
  let applied = 0;
841
915
  let fastForwarded = 0;
842
916
  // Surface shape conflicts as sync failures up front so we don't try to write
@@ -961,11 +1035,34 @@ export async function syncSingleWiki(ctx, wiki, mountPath) {
961
1035
  });
962
1036
  break;
963
1037
  }
1038
+ // Genuine concurrent edit (both sides derived from the same base):
1039
+ // try a line-level three-way merge first. Non-overlapping edits merge
1040
+ // into the working file and the manifest advances to the remote blob,
1041
+ // so the next propose carries a current base_sha. Hunks diff3 cannot
1042
+ // merge (both sides touched the same or adjacent lines), binaries, LFS
1043
+ // pointers, a missing baseline object, or a working file that moved
1044
+ // since the snapshot all fall through to the conflict marker — never
1045
+ // guess.
1046
+ if (action.baseSha !== null && action.localSha !== null) {
1047
+ const base = await readBaselineObject(mountPath, action.baseSha);
1048
+ const localPath = resolvePathInsideRoot(mountPath, action.path);
1049
+ const local = base ? await fs.readFile(localPath) : null;
1050
+ const merge = base && local && computeGitBlobSHA(local) === action.localSha
1051
+ ? mergeTextThreeWay({ base, local, remote: buf, isText: isWikiTextContent })
1052
+ : null;
1053
+ if (merge?.kind === 'clean') {
1054
+ await fs.writeFile(localPath, merge.merged);
1055
+ newFiles[action.path] = { sha: action.remoteSha, size: action.remoteSize };
1056
+ downloadedBySha.set(action.remoteSha, buf);
1057
+ merged.push(action.path);
1058
+ break;
1059
+ }
1060
+ }
964
1061
  const remoteCopy = await writeConflictMarker(mountPath, action.path, REMOTE_CONFLICT_SUFFIX, buf);
965
1062
  // Reason classification:
966
1063
  // - base null + local present → both sides added the same path with different bytes
967
1064
  // - base present + local null → user deleted locally, server changed it
968
- // - base present + local present (and ≠ both) → genuine concurrent edit
1065
+ // - base present + local present (and ≠ both) → concurrent edit whose changes overlap
969
1066
  let reason;
970
1067
  if (action.baseSha === null) {
971
1068
  reason = 'remote-added-local-collides';
@@ -1004,6 +1101,9 @@ export async function syncSingleWiki(ctx, wiki, mountPath) {
1004
1101
  await writeLocalManifest(mountPath, newManifest);
1005
1102
  await ensureBaselineObjects(mountPath, newFiles, downloadedBySha);
1006
1103
  await gcBaselineObjects(mountPath, newFiles);
1104
+ for (const p of merged) {
1105
+ console.warn(`[wiki sync] merged upstream changes into ${p} (no overlapping hunks)`);
1106
+ }
1007
1107
  if (conflicts.length > 0) {
1008
1108
  for (const c of conflicts) {
1009
1109
  const where = c.remoteCopyPath ? ` → ${path.relative(mountPath, c.remoteCopyPath)}` : '';
@@ -1016,7 +1116,7 @@ export async function syncSingleWiki(ctx, wiki, mountPath) {
1016
1116
  console.warn(`[wiki sync] failed to ${f.reason} ${f.path}${detail} — manifest unchanged, will retry next sync`);
1017
1117
  }
1018
1118
  }
1019
- return { applied, fastForwarded, conflicts, failed };
1119
+ return { applied, fastForwarded, conflicts, failed, merged };
1020
1120
  }
1021
1121
  /** Compute the git blob SHA of a working-tree file, or null if absent. */
1022
1122
  async function readLocalGitBlobSha(mountRoot, relPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parall/cli",
3
- "version": "1.58.2",
3
+ "version": "1.59.0",
4
4
  "description": "CLI client for Parall — universal agent & human access to Parall API",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,15 +35,16 @@
35
35
  "commander": "^13.0.0",
36
36
  "diff": "^8.0.3",
37
37
  "js-yaml": "^4.1.0",
38
+ "node-diff3": "3.2.1",
38
39
  "zod": "^4.3.6",
39
- "@parall/agent-core": "1.58.2",
40
- "@parall/sdk": "1.58.2"
40
+ "@parall/agent-core": "1.59.0",
41
+ "@parall/sdk": "1.59.0"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@types/js-yaml": "^4.0.9",
44
45
  "@types/node": "^22.0.0",
45
46
  "typescript": "^5.7.0",
46
- "@parall/agent-core": "1.58.2"
47
+ "@parall/agent-core": "1.59.0"
47
48
  },
48
49
  "scripts": {
49
50
  "build": "tsc",