@swarmdo/cli 1.27.0 → 1.30.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.
- package/.claude/helpers/auto-memory-hook.mjs +70 -33
- package/README.md +11 -9
- package/bin/cli.js +38 -0
- package/dist/src/apply/apply.d.ts +6 -0
- package/dist/src/apply/apply.d.ts.map +1 -1
- package/dist/src/apply/apply.js +41 -8
- package/dist/src/apply/apply.js.map +1 -1
- package/dist/src/commands/apply.d.ts.map +1 -1
- package/dist/src/commands/apply.js +17 -4
- package/dist/src/commands/apply.js.map +1 -1
- package/dist/src/commands/compact-snapshot.d.ts +17 -0
- package/dist/src/commands/compact-snapshot.d.ts.map +1 -0
- package/dist/src/commands/compact-snapshot.js +133 -0
- package/dist/src/commands/compact-snapshot.js.map +1 -0
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +4 -3
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/pack.d.ts +8 -0
- package/dist/src/commands/pack.d.ts.map +1 -1
- package/dist/src/commands/pack.js +28 -2
- package/dist/src/commands/pack.js.map +1 -1
- package/dist/src/commands/usage.d.ts.map +1 -1
- package/dist/src/commands/usage.js +174 -2
- package/dist/src/commands/usage.js.map +1 -1
- package/dist/src/compact/compact.d.ts.map +1 -1
- package/dist/src/compact/compact.js +17 -7
- package/dist/src/compact/compact.js.map +1 -1
- package/dist/src/compact-snapshot/compact-snapshot.d.ts +58 -0
- package/dist/src/compact-snapshot/compact-snapshot.d.ts.map +1 -0
- package/dist/src/compact-snapshot/compact-snapshot.js +104 -0
- package/dist/src/compact-snapshot/compact-snapshot.js.map +1 -0
- package/dist/src/config-lint/lint.d.ts.map +1 -1
- package/dist/src/config-lint/lint.js +16 -2
- package/dist/src/config-lint/lint.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts.map +1 -1
- package/dist/src/init/helpers-generator.js +33 -3
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/redact/redact.js +1 -1
- package/dist/src/redact/redact.js.map +1 -1
- package/dist/src/sbom/sbom.d.ts.map +1 -1
- package/dist/src/sbom/sbom.js +5 -2
- package/dist/src/sbom/sbom.js.map +1 -1
- package/dist/src/swarmvector/model-prices.d.ts.map +1 -1
- package/dist/src/swarmvector/model-prices.js +12 -2
- package/dist/src/swarmvector/model-prices.js.map +1 -1
- package/dist/src/testreport/testreport.d.ts.map +1 -1
- package/dist/src/testreport/testreport.js +11 -2
- package/dist/src/testreport/testreport.js.map +1 -1
- package/dist/src/transcript/export.d.ts +5 -0
- package/dist/src/transcript/export.d.ts.map +1 -1
- package/dist/src/transcript/export.js +8 -1
- package/dist/src/transcript/export.js.map +1 -1
- package/dist/src/usage/claude-pricing.d.ts +6 -2
- package/dist/src/usage/claude-pricing.d.ts.map +1 -1
- package/dist/src/usage/claude-pricing.js +33 -4
- package/dist/src/usage/claude-pricing.js.map +1 -1
- package/dist/src/usage/limits.d.ts +77 -0
- package/dist/src/usage/limits.d.ts.map +1 -0
- package/dist/src/usage/limits.js +134 -0
- package/dist/src/usage/limits.js.map +1 -0
- package/dist/src/usage/reflect-html.d.ts +23 -0
- package/dist/src/usage/reflect-html.d.ts.map +1 -0
- package/dist/src/usage/reflect-html.js +94 -0
- package/dist/src/usage/reflect-html.js.map +1 -0
- package/dist/src/usage/reflect.d.ts +105 -0
- package/dist/src/usage/reflect.d.ts.map +1 -0
- package/dist/src/usage/reflect.js +165 -0
- package/dist/src/usage/reflect.js.map +1 -0
- package/dist/src/usage/spend-forecast.d.ts +28 -0
- package/dist/src/usage/spend-forecast.d.ts.map +1 -0
- package/dist/src/usage/spend-forecast.js +33 -0
- package/dist/src/usage/spend-forecast.js.map +1 -0
- package/dist/src/usage/transcript-errors.d.ts +14 -0
- package/dist/src/usage/transcript-errors.d.ts.map +1 -1
- package/dist/src/usage/transcript-errors.js +10 -0
- package/dist/src/usage/transcript-errors.js.map +1 -1
- package/dist/src/usage/transcript-usage.js +1 -1
- package/dist/src/usage/transcript-usage.js.map +1 -1
- package/dist/src/util/csv.d.ts +14 -0
- package/dist/src/util/csv.d.ts.map +1 -0
- package/dist/src/util/csv.js +20 -0
- package/dist/src/util/csv.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/plugins/swarmdo-metaharness/.claude-plugin/plugin.json +5 -2
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
15
15
|
import { join, dirname } from 'path';
|
|
16
|
-
import { fileURLToPath } from 'url';
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
17
17
|
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
19
|
const __dirname = dirname(__filename);
|
|
@@ -52,13 +52,30 @@ async function gracefulExit(signal) {
|
|
|
52
52
|
process.on('SIGTERM', () => { gracefulExit('SIGTERM'); });
|
|
53
53
|
process.on('SIGINT', () => { gracefulExit('SIGINT'); });
|
|
54
54
|
|
|
55
|
-
// Ensure data dir
|
|
56
|
-
if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
|
|
57
|
-
|
|
58
55
|
// ============================================================================
|
|
59
56
|
// Simple JSON File Backend (implements IMemoryBackend interface)
|
|
60
57
|
// ============================================================================
|
|
61
58
|
|
|
59
|
+
// Collapse entries that are the SAME memory — identical content signature but
|
|
60
|
+
// distinct ids — keeping the first occurrence. The auto-memory bridge
|
|
61
|
+
// historically re-imported every session with a fresh random id, bloating the
|
|
62
|
+
// store ~22x (#53); this heals already-bloated stores and de-dupes defensively.
|
|
63
|
+
// Keyed by namespace + content hash (or raw content) so genuinely distinct
|
|
64
|
+
// memories are never merged. Pure.
|
|
65
|
+
function dedupeByContentSignature(entries) {
|
|
66
|
+
const seen = new Set();
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const e of entries) {
|
|
69
|
+
const ns = (e && e.namespace) || 'default';
|
|
70
|
+
const body = (e && e.metadata && e.metadata.contentHash) || (e && (e.content || e.value)) || '';
|
|
71
|
+
const sig = ns + '\u0001' + body;
|
|
72
|
+
if (seen.has(sig)) continue;
|
|
73
|
+
seen.add(sig);
|
|
74
|
+
out.push(e);
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
class JsonFileBackend {
|
|
63
80
|
constructor(filePath) {
|
|
64
81
|
this.filePath = filePath;
|
|
@@ -70,7 +87,12 @@ class JsonFileBackend {
|
|
|
70
87
|
try {
|
|
71
88
|
const data = JSON.parse(readFileSync(this.filePath, 'utf-8'));
|
|
72
89
|
if (Array.isArray(data)) {
|
|
73
|
-
|
|
90
|
+
// Collapse content-duplicates left by the pre-#53 import bug (same
|
|
91
|
+
// memory re-imported each session under a fresh id). Auto-heals an
|
|
92
|
+
// already-bloated store by rewriting it once when dupes are dropped.
|
|
93
|
+
const deduped = dedupeByContentSignature(data);
|
|
94
|
+
for (const entry of deduped) this.entries.set(entry.id, entry);
|
|
95
|
+
if (deduped.length < data.length) this._persist();
|
|
74
96
|
}
|
|
75
97
|
} catch { /* start fresh */ }
|
|
76
98
|
}
|
|
@@ -99,7 +121,11 @@ class JsonFileBackend {
|
|
|
99
121
|
async query(opts) {
|
|
100
122
|
let results = [...this.entries.values()];
|
|
101
123
|
if (opts?.namespace) results = results.filter(e => e.namespace === opts.namespace);
|
|
102
|
-
|
|
124
|
+
// NOTE: opts.type is the QueryType search STRATEGY (semantic|keyword|hybrid|…),
|
|
125
|
+
// NOT an entry MemoryType. This JSON backend has no vector search, so the
|
|
126
|
+
// strategy is moot — filtering entries by it excluded everything (a 'hybrid'
|
|
127
|
+
// query matched no 'semantic' entries), which zeroed out the bridge's
|
|
128
|
+
// content-hash dedup and let the store bloat ~22x per re-import (#53).
|
|
103
129
|
if (opts?.limit) results = results.slice(0, opts.limit);
|
|
104
130
|
return results;
|
|
105
131
|
}
|
|
@@ -367,32 +393,43 @@ async function doStatus() {
|
|
|
367
393
|
// Main
|
|
368
394
|
// ============================================================================
|
|
369
395
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
//
|
|
376
|
-
|
|
377
|
-
process.
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
396
|
+
// Only dispatch CLI commands when this file is executed directly
|
|
397
|
+
// (`node auto-memory-hook.mjs …`), NOT when it is imported by a test —
|
|
398
|
+
// importing must not run a command or exit the process (#53 regression test
|
|
399
|
+
// imports JsonFileBackend + dedupeByContentSignature below).
|
|
400
|
+
if (import.meta.url === pathToFileURL(process.argv[1] || '').href) {
|
|
401
|
+
// Ensure data dir (only when actually running a command, not on import)
|
|
402
|
+
if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
|
|
403
|
+
const command = process.argv[2] || 'status';
|
|
404
|
+
|
|
405
|
+
// Dynamic import() failures can surface as unhandled rejections on a later
|
|
406
|
+
// microtask even when the awaiting call site already caught them, which would
|
|
407
|
+
// otherwise force a non-zero exit. Swallow to keep hooks exit-0, but surface the
|
|
408
|
+
// reason under SWARMDO_DEBUG/DEBUG so genuine async bugs aren't silently hidden
|
|
409
|
+
// (FIX 2 — the previous `() => {}` discarded every rejection process-wide).
|
|
410
|
+
process.on('unhandledRejection', (reason) => {
|
|
411
|
+
if (DEBUG) {
|
|
412
|
+
const detail = reason && reason.message ? reason.message : String(reason);
|
|
413
|
+
process.stderr.write(`[AutoMemory] unhandledRejection (suppressed): ${detail}\n`);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
try {
|
|
418
|
+
switch (command) {
|
|
419
|
+
case 'import': await doImport(); break;
|
|
420
|
+
case 'sync': await doSync(); break;
|
|
421
|
+
case 'status': await doStatus(); break;
|
|
422
|
+
default:
|
|
423
|
+
console.log('Usage: auto-memory-hook.mjs <import|sync|status>');
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
} catch (err) {
|
|
427
|
+
// Hooks must never crash Claude Code - fail silently
|
|
428
|
+
try { dim(`Error (non-critical): ${err.message}`); } catch (_) {}
|
|
392
429
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
try { dim(`Error (non-critical): ${err.message}`); } catch (_) {}
|
|
430
|
+
// Force clean exit — process.exitCode alone isn't enough if async errors override it
|
|
431
|
+
process.exit(0);
|
|
396
432
|
}
|
|
397
|
-
|
|
398
|
-
|
|
433
|
+
|
|
434
|
+
// Exported for unit tests (the run-guard above keeps import side-effect-free).
|
|
435
|
+
export { JsonFileBackend, dedupeByContentSignature };
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://swarmdo.com)
|
|
4
4
|
|
|
5
|
-
[](https://img.shields.io/badge/npx%20swarmdo-v1.30.0-cb3837?style=for-the-badge&logo=npm&logoColor=white)](https://github.com/SwarmDo/swarmdo/releases)
|
|
6
6
|
[](https://github.com/SwarmDo/swarmdo/blob/main/LICENSE)
|
|
7
7
|
[](https://swarmdo.com)
|
|
8
8
|
[](https://github.com/SwarmDo/swarmdo)
|
|
@@ -47,17 +47,17 @@ There are **two different install paths** with very different surface areas. Pic
|
|
|
47
47
|
|
|
48
48
|
| | **Claude Code Plugin** | **CLI install (`npx swarmdo init`)** |
|
|
49
49
|
|---|---|---|
|
|
50
|
-
| What it gives you | Slash commands +
|
|
50
|
+
| What it gives you | Slash commands + skills + agent definitions per-plugin; `swarmdo-core` also registers the swarmdo MCP server | Full Swarmdo loop — 98 agents, 60+ commands, 30 skills, MCP server, hooks, daemon |
|
|
51
51
|
| Files in your workspace | **Zero** | `.claude/`, `.swarmdo/`, `CLAUDE.md`, helpers, settings |
|
|
52
|
-
| MCP server registered | **
|
|
52
|
+
| MCP server registered | **Yes with `swarmdo-core`** (via the plugin's `.mcp.json`); other plugins are commands/skills only | Yes |
|
|
53
53
|
| Hooks installed | No | Yes |
|
|
54
|
-
| Best for | Try
|
|
54
|
+
| Best for | Try Swarmdo without committing files to your workspace | Production use — everything works as documented |
|
|
55
55
|
|
|
56
|
-
### Path A — Claude Code Plugins (
|
|
56
|
+
### Path A — Claude Code Plugins (zero files in your repo)
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
59
|
# Add the marketplace
|
|
60
|
-
/plugin marketplace add
|
|
60
|
+
/plugin marketplace add SwarmDo/swarmdo
|
|
61
61
|
|
|
62
62
|
# Install core + any plugins you need
|
|
63
63
|
/plugin install swarmdo-core@swarmdo
|
|
@@ -66,7 +66,9 @@ There are **two different install paths** with very different surface areas. Pic
|
|
|
66
66
|
/plugin install swarmdo-neural-trader@swarmdo
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
`swarmdo-core` registers the swarmdo MCP server (300+ tools) plus base agents and setup skills; the other plugins add their slash commands and agent definitions. Hooks and the daemon still require Path B.
|
|
70
|
+
|
|
71
|
+
> 📦 `swarmdo-core` has been submitted to Anthropic's Claude Code plugin directory (community marketplace). Once approved it will also be installable via `/plugin install swarmdo-core@claude-community` — no marketplace-add needed.
|
|
70
72
|
|
|
71
73
|
<details>
|
|
72
74
|
<summary><strong>🔌 All 35 plugins</strong></summary>
|
|
@@ -159,7 +161,7 @@ This adds slash commands and agent definitions only. The Swarmdo MCP server is N
|
|
|
159
161
|
|
|
160
162
|
```bash
|
|
161
163
|
# One-line install (POSIX shells only — see Windows note below)
|
|
162
|
-
curl -fsSL https://cdn.jsdelivr.net/gh/
|
|
164
|
+
curl -fsSL https://cdn.jsdelivr.net/gh/SwarmDo/swarmdo@main/scripts/install.sh | bash
|
|
163
165
|
```
|
|
164
166
|
|
|
165
167
|
**All platforms (including native Windows PowerShell / cmd):**
|
|
@@ -269,7 +271,7 @@ The recent release train added a full day-to-day operations layer around the swa
|
|
|
269
271
|
|
|
270
272
|
| Command | What it does |
|
|
271
273
|
|---------|-------------|
|
|
272
|
-
| `swarmdo usage` (alias `cost`) | Claude Code **spend analytics** from your local transcripts — `daily`, `monthly
|
|
274
|
+
| `swarmdo usage` (alias `cost`) | Claude Code **spend analytics** from your local transcripts — `daily`, `monthly` (with a month-end spend projection), `models`, `projects`, `sessions`, live 5-hour `blocks` burn, `errors` (tool-failure analytics), `cache` (prompt-cache efficiency + $ saved), `diff` (period-over-period comparison with per-model movers), `reflect` (a wrapped-style retrospective — busiest day, streak, top models/projects, peak hour, delegation ratio — with a shareable `--html` dashboard), and `limits` (an official-quota **exhaustion forecaster** over Claude Code's `rate_limits`); the standard views take `--csv` for spreadsheet export |
|
|
273
275
|
| `swarmdo usage guard` | **Budget policy** — limits for the active 5h block / today / month via flags or `SWARMDO_GUARD_*` env → ok / warn / over; `--strict` exits 1, safe for CI gates and Stop hooks |
|
|
274
276
|
| `swarmdo hud` | **One-screen ops HUD** — 5h block burn, task readiness, daemon workers, memory snapshots (`--watch`, `--json`) |
|
|
275
277
|
| `swarmdo repair` (alias `tdd-repair`) | **Test-Driven Repair** — a bounded, budget-capped headless `claude` loop that fixes source until a failing test passes; dry-run unless `--confirm` |
|
package/bin/cli.js
CHANGED
|
@@ -93,6 +93,20 @@ console.log = (...args) => {
|
|
|
93
93
|
_origLog.apply(console, args);
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
// Claude Code plugin hint (code.claude.com/docs/en/plugin-hints): when a
|
|
97
|
+
// session runs swarmdo through Claude Code's Bash tool, emit the one-line
|
|
98
|
+
// marker so Claude Code can offer to install our plugin. Emitted here in the
|
|
99
|
+
// bin shim — NOT in dist/src/index.js — so it also covers the #2256 fast
|
|
100
|
+
// paths below (--version/--help are exactly the probes Claude runs on an
|
|
101
|
+
// unfamiliar CLI). Claude Code strips the line from all output before it
|
|
102
|
+
// reaches the model and only prompts if/when swarmdo-core is listed in the
|
|
103
|
+
// official Anthropic marketplace; until then it is silently dropped.
|
|
104
|
+
if (process.env.CLAUDECODE) {
|
|
105
|
+
process.stderr.write(
|
|
106
|
+
'<claude-code-hint v="1" type="plugin" value="swarmdo-core@claude-plugins-official" />\n'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
96
110
|
// #2256 fast path: --version / -V / --help / -h must NOT trigger heavy
|
|
97
111
|
// imports (agentic-flow, swarmvector ONNX, etc.) — those eagerly download a
|
|
98
112
|
// 23 MB ONNX model on cold cache, blocking 60+ s and causing SIGTERM
|
|
@@ -116,6 +130,30 @@ console.log = (...args) => {
|
|
|
116
130
|
// loading. The version short-circuit is the only one safe to inline.
|
|
117
131
|
}
|
|
118
132
|
|
|
133
|
+
// #45 fast path: `compact-snapshot` is wired to UserPromptSubmit (fires on
|
|
134
|
+
// EVERY prompt) and PreCompact, so it must not pay the full-CLI bootstrap
|
|
135
|
+
// (~0.6s incl. the 23 MB ONNX load). Its own module imports only fs/git/output
|
|
136
|
+
// + the pure engine, so dispatch it directly and exit before any heavy import.
|
|
137
|
+
// A bare `--help` still falls through to the rich help path below.
|
|
138
|
+
{
|
|
139
|
+
const _argv = process.argv.slice(2);
|
|
140
|
+
if (_argv[0] === 'compact-snapshot' && !_argv.includes('--help') && !_argv.includes('-h')) {
|
|
141
|
+
try {
|
|
142
|
+
const mod = await import('../dist/src/commands/compact-snapshot.js');
|
|
143
|
+
const cmd = mod.default ?? mod.compactSnapshotCommand;
|
|
144
|
+
const rest = _argv.slice(1);
|
|
145
|
+
const args = rest.filter((a) => !a.startsWith('-'));
|
|
146
|
+
const flags = {};
|
|
147
|
+
for (const a of rest) if (a.startsWith('--')) flags[a.replace(/^--/, '')] = true;
|
|
148
|
+
const res = await cmd.action({ cwd: process.cwd(), args, flags, rawArgs: rest });
|
|
149
|
+
process.exit(res && typeof res.exitCode === 'number' ? res.exitCode : 0);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
// Best-effort: a failure here must never block a turn (it runs in hooks).
|
|
152
|
+
process.exit(0);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
119
157
|
// Check if we should run in MCP server mode
|
|
120
158
|
// Conditions:
|
|
121
159
|
// 1. stdin is being piped AND no CLI arguments provided (auto-detect)
|
|
@@ -41,6 +41,12 @@ export interface HunkResult {
|
|
|
41
41
|
at?: number;
|
|
42
42
|
/** how many context lines were trimmed to make it fit */
|
|
43
43
|
fuzzUsed?: number;
|
|
44
|
+
/**
|
|
45
|
+
* True when the matched block occurs at MORE THAN ONE position in the file —
|
|
46
|
+
* the hunk landed at the nearest, but a duplicate/boilerplate block elsewhere
|
|
47
|
+
* means it may have modified the wrong occurrence. Callers should verify.
|
|
48
|
+
*/
|
|
49
|
+
ambiguous?: boolean;
|
|
44
50
|
}
|
|
45
51
|
export interface ApplyResult {
|
|
46
52
|
ok: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/apply/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,QAAQ;IACvB,6CAA6C;IAC7C,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/apply/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,QAAQ;IACvB,6CAA6C;IAC7C,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CAoDpD;AA8CD,MAAM,WAAW,YAAY;IAC3B,6FAA6F;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED,sGAAsG;AACtG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,GAAE,YAAiB,GAAG,WAAW,CAyEjG"}
|
package/dist/src/apply/apply.js
CHANGED
|
@@ -19,7 +19,10 @@ export function parsePatch(text) {
|
|
|
19
19
|
let hunk = null;
|
|
20
20
|
const stripPrefix = (p) => p.replace(/^[ab]\//, '').replace(/\t.*$/, '').trim();
|
|
21
21
|
for (let i = 0; i < lines.length; i++) {
|
|
22
|
-
|
|
22
|
+
// CRLF tolerance (#9): a diff generated on/for CRLF files carries \r on
|
|
23
|
+
// every line; strip it so hunk content compares EOL-agnostically.
|
|
24
|
+
const raw = lines[i];
|
|
25
|
+
const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
|
|
23
26
|
if (line.startsWith('diff --git')) {
|
|
24
27
|
cur = null;
|
|
25
28
|
hunk = null;
|
|
@@ -90,6 +93,16 @@ function blockMatchesAt(source, at, block) {
|
|
|
90
93
|
return false;
|
|
91
94
|
return true;
|
|
92
95
|
}
|
|
96
|
+
/** How many positions in `source` the `block` matches. Pure. */
|
|
97
|
+
function countMatches(source, block) {
|
|
98
|
+
if (block.length === 0)
|
|
99
|
+
return 0;
|
|
100
|
+
let n = 0;
|
|
101
|
+
for (let i = 0; i + block.length <= source.length; i++)
|
|
102
|
+
if (blockMatchesAt(source, i, block))
|
|
103
|
+
n++;
|
|
104
|
+
return n;
|
|
105
|
+
}
|
|
93
106
|
/**
|
|
94
107
|
* Find where `block` occurs in `source`, preferring the position nearest
|
|
95
108
|
* `expected` (0-based). Returns -1 if not found. Deterministic: on ties the
|
|
@@ -117,9 +130,19 @@ function findBlock(source, block, expected) {
|
|
|
117
130
|
export function applyPatch(source, patch, opts = {}) {
|
|
118
131
|
const fuzz = opts.fuzz ?? 2;
|
|
119
132
|
const trailingNewline = source.endsWith('\n');
|
|
133
|
+
// CRLF support (#9): match EOL-agnostically, then write inserted lines with
|
|
134
|
+
// the file's dominant EOL so CRLF sources stay CRLF. `lines` keeps each
|
|
135
|
+
// line's original bytes (untouched lines round-trip exactly); `matchLines`
|
|
136
|
+
// is the \r-stripped twin every comparison runs against. The two are spliced
|
|
137
|
+
// in lockstep so indices stay aligned.
|
|
138
|
+
const crlfCount = (source.match(/\r\n/g) ?? []).length;
|
|
139
|
+
const newlineCount = (source.match(/\n/g) ?? []).length;
|
|
140
|
+
const dominantCrlf = crlfCount > newlineCount - crlfCount;
|
|
120
141
|
const lines = source.split('\n');
|
|
121
142
|
if (trailingNewline)
|
|
122
143
|
lines.pop(); // drop the empty element from a trailing \n
|
|
144
|
+
const stripCr = (s) => (s.endsWith('\r') ? s.slice(0, -1) : s);
|
|
145
|
+
const matchLines = lines.map(stripCr);
|
|
123
146
|
let offset = 0;
|
|
124
147
|
const results = [];
|
|
125
148
|
// If a hunk that reaches EOF carries an explicit no-newline marker, it — not
|
|
@@ -142,7 +165,7 @@ export function applyPatch(source, patch, opts = {}) {
|
|
|
142
165
|
if (lead > leadTrimmable || tail > tailTrimmable)
|
|
143
166
|
continue;
|
|
144
167
|
const trimmed = oldBlock.slice(lead, oldBlock.length - tail);
|
|
145
|
-
const at = findBlock(
|
|
168
|
+
const at = findBlock(matchLines, trimmed, expected + lead);
|
|
146
169
|
if (at >= 0) {
|
|
147
170
|
placed = at - lead;
|
|
148
171
|
usedFuzz = f;
|
|
@@ -156,13 +179,18 @@ export function applyPatch(source, patch, opts = {}) {
|
|
|
156
179
|
results.push({ hunk, applied: false });
|
|
157
180
|
continue;
|
|
158
181
|
}
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
182
|
+
// A hunk is AMBIGUOUS if the block it matched on occurs elsewhere too — the
|
|
183
|
+
// nearest-match tiebreak may have picked the wrong duplicate. Check the
|
|
184
|
+
// matched (trimmed) block against the current lines BEFORE splicing.
|
|
185
|
+
const matchedBlock = oldBlock.slice(trimLead, oldBlock.length - trimTail);
|
|
186
|
+
const ambiguous = countMatches(matchLines, matchedBlock) > 1;
|
|
187
|
+
// Splice: remove oldBlock.length lines at `placed`, insert newBlock —
|
|
188
|
+
// raw lines get the file's dominant EOL, the match twin stays stripped.
|
|
189
|
+
const insertRaw = dominantCrlf ? newBlock.map((l) => l + '\r') : newBlock;
|
|
190
|
+
lines.splice(placed, oldBlock.length, ...insertRaw);
|
|
191
|
+
matchLines.splice(placed, oldBlock.length, ...newBlock);
|
|
164
192
|
offset += newBlock.length - oldBlock.length;
|
|
165
|
-
results.push({ hunk, applied: true, at: placed, fuzzUsed: usedFuzz });
|
|
193
|
+
results.push({ hunk, applied: true, at: placed, fuzzUsed: usedFuzz, ...(ambiguous && { ambiguous: true }) });
|
|
166
194
|
// If this hunk's new content is now the tail of the file, its markers
|
|
167
195
|
// determine whether the file ends with a newline.
|
|
168
196
|
if (placed + newBlock.length === lines.length)
|
|
@@ -173,6 +201,11 @@ export function applyPatch(source, patch, opts = {}) {
|
|
|
173
201
|
const endWithNewline = eofNoEol === undefined ? trailingNewline : !eofNoEol;
|
|
174
202
|
if (endWithNewline)
|
|
175
203
|
result += '\n';
|
|
204
|
+
// An inserted line that became the no-trailing-newline tail carries the
|
|
205
|
+
// dominant-EOL \r it was given for joining — a bare CR at EOF is never
|
|
206
|
+
// meaningful, so drop it.
|
|
207
|
+
else if (result.endsWith('\r'))
|
|
208
|
+
result = result.slice(0, -1);
|
|
176
209
|
return { ok: results.every((r) => r.applied), result, hunks: results };
|
|
177
210
|
}
|
|
178
211
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/apply/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAsBH,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,GAAG,GAAqB,IAAI,CAAC;IACjC,IAAI,IAAI,GAAgB,IAAI,CAAC;IAE7B,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,O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AAO,EAAiC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/commands/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;AAoG1E,eAAO,MAAM,YAAY,EAAE,OAe1B,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -32,6 +32,7 @@ async function run(ctx) {
|
|
|
32
32
|
const root = ctx.cwd || process.cwd();
|
|
33
33
|
const dryRun = ctx.flags['dry-run'] === true;
|
|
34
34
|
const partial = ctx.flags.partial === true;
|
|
35
|
+
const strict = ctx.flags.strict === true;
|
|
35
36
|
// The parser may deliver --fuzz as a number or a string; accept both.
|
|
36
37
|
const fuzz = typeof ctx.flags.fuzz === 'number' ? ctx.flags.fuzz
|
|
37
38
|
: typeof ctx.flags.fuzz === 'string' ? parseInt(ctx.flags.fuzz, 10)
|
|
@@ -61,6 +62,7 @@ async function run(ctx) {
|
|
|
61
62
|
}
|
|
62
63
|
let totalApplied = 0;
|
|
63
64
|
let totalRejected = 0;
|
|
65
|
+
let totalAmbiguous = 0;
|
|
64
66
|
const writes = [];
|
|
65
67
|
for (const fp of patches) {
|
|
66
68
|
const file = targetFile(root, fp);
|
|
@@ -85,8 +87,16 @@ async function run(ctx) {
|
|
|
85
87
|
totalApplied += applied;
|
|
86
88
|
totalRejected += rejected;
|
|
87
89
|
const fuzzy = res.hunks.filter((h) => h.applied && (h.fuzzUsed ?? 0) > 0).length;
|
|
90
|
+
const ambiguous = res.hunks.filter((h) => h.applied && h.ambiguous).length;
|
|
91
|
+
totalAmbiguous += ambiguous;
|
|
88
92
|
const tag = rejected === 0 ? output.dim('ok') : output.bold(`${rejected} rejected`);
|
|
89
|
-
|
|
93
|
+
const ambTag = ambiguous ? output.error(` ⚠ ${ambiguous} ambiguous`) : '';
|
|
94
|
+
output.writeln(`${rel} ${applied}/${res.hunks.length} hunks${fuzzy ? output.dim(` (${fuzzy} fuzzy)`) : ''} ${tag}${ambTag}`);
|
|
95
|
+
if (ambiguous) {
|
|
96
|
+
for (const h of res.hunks.filter((x) => x.applied && x.ambiguous)) {
|
|
97
|
+
output.writeln(output.dim(` ⚠ hunk @ line ${(h.at ?? 0) + 1}: matched a block that also appears elsewhere — verify it landed on the intended one`));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
90
100
|
if (rejected === 0 || partial) {
|
|
91
101
|
if (res.result !== source)
|
|
92
102
|
writes.push({ file, content: res.result });
|
|
@@ -97,9 +107,11 @@ async function run(ctx) {
|
|
|
97
107
|
fs.writeFileSync(w.file, w.content);
|
|
98
108
|
}
|
|
99
109
|
const verb = dryRun ? 'would apply' : 'applied';
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
const ambSummary = totalAmbiguous ? `, ${totalAmbiguous} ambiguous` : '';
|
|
111
|
+
output.writeln(output.dim(`${verb} ${totalApplied} hunks, ${totalRejected} rejected${ambSummary}${dryRun ? ' (dry run)' : ''}`));
|
|
112
|
+
// Exit 1 if anything was rejected — a CI/agent can branch on it. With --strict,
|
|
113
|
+
// an ambiguous match (possibly landed on the wrong duplicate) also fails.
|
|
114
|
+
const code = totalRejected > 0 || (strict && totalAmbiguous > 0) ? 1 : 0;
|
|
103
115
|
return { success: code === 0, exitCode: code };
|
|
104
116
|
}
|
|
105
117
|
export const applyCommand = {
|
|
@@ -109,6 +121,7 @@ export const applyCommand = {
|
|
|
109
121
|
{ name: 'dry-run', description: 'report what would apply/reject without writing', type: 'boolean' },
|
|
110
122
|
{ name: 'fuzz', description: 'max context lines to drop when matching a drifted hunk (default 2)', type: 'string' },
|
|
111
123
|
{ name: 'partial', description: 'write files even when some of their hunks are rejected', type: 'boolean' },
|
|
124
|
+
{ name: 'strict', description: 'exit 1 if any hunk matched an ambiguous (duplicated) block, even if it applied', type: 'boolean' },
|
|
112
125
|
],
|
|
113
126
|
examples: [
|
|
114
127
|
{ command: 'swarmdo apply changes.patch', description: 'Apply a patch file' },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/commands/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAC;AAE3E,SAAS,SAAS;IAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7D,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/E,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;AACL,CAAC;AAED,+EAA+E;AAC/E,SAAS,UAAU,CAAC,IAAY,EAAE,EAAa;IAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAA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EAAE,MAAM,EAAE,WAAW,EAAE,oEAAoE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACnH,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,wDAAwD,EAAE,IAAI,EAAE,SAAS,EAAE;QAC3G,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gFAAgF,EAAE,IAAI,EAAE,SAAS,EAAE;KACnI;IACD,QAAQ,EAAE;QACR,EAAE,OAAO,EAAE,6BAA6B,EAAE,WAAW,EAAE,oBAAoB,EAAE;QAC7E,EAAE,OAAO,EAAE,wCAAwC,EAAE,WAAW,EAAE,4BAA4B,EAAE;QAChG,EAAE,OAAO,EAAE,sCAAsC,EAAE,WAAW,EAAE,6BAA6B,EAAE;KAChG;IACD,MAAM,EAAE,GAAG;CACZ,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `swarmdo compact-snapshot` — capture / restore a compaction-survival digest.
|
|
3
|
+
*
|
|
4
|
+
* swarmdo compact-snapshot write # snapshot working state (call on PreCompact)
|
|
5
|
+
* swarmdo compact-snapshot read # print the digest, then consume it (first
|
|
6
|
+
* # prompt after compaction re-injects it)
|
|
7
|
+
* swarmdo compact-snapshot read --keep # print without consuming
|
|
8
|
+
*
|
|
9
|
+
* The digest (recently edited files, uncommitted changes, branch) lets an agent
|
|
10
|
+
* re-ground after context compaction instead of re-exploring. The engine is
|
|
11
|
+
* pure + tested (../compact-snapshot/compact-snapshot.ts); this wrapper does the
|
|
12
|
+
* fs read (edit ledger), git calls, and one-shot persistence.
|
|
13
|
+
*/
|
|
14
|
+
import type { Command } from '../types.js';
|
|
15
|
+
export declare const compactSnapshotCommand: Command;
|
|
16
|
+
export default compactSnapshotCommand;
|
|
17
|
+
//# sourceMappingURL=compact-snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-snapshot.d.ts","sourceRoot":"","sources":["../../../src/commands/compact-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;AA4F1E,eAAO,MAAM,sBAAsB,EAAE,OAWpC,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|