@shrkcrft/cli 0.1.0-alpha.16 → 0.1.0-alpha.18

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 (45) hide show
  1. package/dist/command-registry.d.ts +28 -0
  2. package/dist/command-registry.d.ts.map +1 -1
  3. package/dist/command-registry.js +91 -1
  4. package/dist/commands/apply.command.d.ts.map +1 -1
  5. package/dist/commands/apply.command.js +10 -2
  6. package/dist/commands/command-catalog.d.ts.map +1 -1
  7. package/dist/commands/command-catalog.js +14 -0
  8. package/dist/commands/compress.command.d.ts +0 -7
  9. package/dist/commands/compress.command.d.ts.map +1 -1
  10. package/dist/commands/compress.command.js +35 -13
  11. package/dist/commands/delegate.command.d.ts +65 -0
  12. package/dist/commands/delegate.command.d.ts.map +1 -0
  13. package/dist/commands/delegate.command.js +657 -0
  14. package/dist/commands/deps-audit.command.js +5 -1
  15. package/dist/commands/dev.command.d.ts.map +1 -1
  16. package/dist/commands/dev.command.js +5 -1
  17. package/dist/commands/doctor.command.d.ts.map +1 -1
  18. package/dist/commands/doctor.command.js +24 -3
  19. package/dist/commands/graph-code-subverbs.d.ts +22 -0
  20. package/dist/commands/graph-code-subverbs.d.ts.map +1 -1
  21. package/dist/commands/graph-code-subverbs.js +450 -54
  22. package/dist/commands/graph.command.d.ts.map +1 -1
  23. package/dist/commands/graph.command.js +9 -3
  24. package/dist/commands/move-plan.command.js +1 -1
  25. package/dist/commands/smart-context.command.d.ts +26 -17
  26. package/dist/commands/smart-context.command.d.ts.map +1 -1
  27. package/dist/commands/smart-context.command.js +113 -16
  28. package/dist/commands/tests.command.d.ts.map +1 -1
  29. package/dist/commands/tests.command.js +13 -2
  30. package/dist/dashboard/code-intelligence-data.d.ts.map +1 -1
  31. package/dist/dashboard/code-intelligence-data.js +25 -3
  32. package/dist/main.d.ts.map +1 -1
  33. package/dist/main.js +21 -3
  34. package/dist/output/ccr-store-config.d.ts +18 -0
  35. package/dist/output/ccr-store-config.d.ts.map +1 -0
  36. package/dist/output/ccr-store-config.js +41 -0
  37. package/dist/output/output-compression.d.ts +15 -0
  38. package/dist/output/output-compression.d.ts.map +1 -0
  39. package/dist/output/output-compression.js +60 -0
  40. package/dist/output/resolve-compress-type.d.ts +22 -0
  41. package/dist/output/resolve-compress-type.d.ts.map +1 -0
  42. package/dist/output/resolve-compress-type.js +21 -0
  43. package/dist/validation/run-validation-loop.d.ts.map +1 -1
  44. package/dist/validation/run-validation-loop.js +5 -1
  45. package/package.json +33 -33
@@ -10,6 +10,14 @@ export interface ICommandHandler {
10
10
  name: string;
11
11
  description: string;
12
12
  usage: string;
13
+ /**
14
+ * Flags that take NO value (e.g. `json`, `no-enhance`). Listed here so the
15
+ * parser doesn't greedily swallow the following token as the flag's value —
16
+ * `compress --json <file>` / `smart-context --no-enhance "<task>"` keep the
17
+ * token as a positional regardless of argument order (the order an LLM
18
+ * naturally emits). Optional; commands without it parse exactly as before.
19
+ */
20
+ booleanFlags?: ReadonlySet<string>;
13
21
  run(args: ParsedArgs): Promise<number> | number;
14
22
  }
15
23
  /**
@@ -101,6 +109,8 @@ export declare class CommandRegistry {
101
109
  export interface ParseArgsOptions {
102
110
  /** Global cwd resolved during pre-parse, propagated to the command. */
103
111
  globalCwd?: string;
112
+ /** Flags that take no value — they never consume the following token. */
113
+ booleanFlags?: ReadonlySet<string>;
104
114
  }
105
115
  export declare function parseArgs(argv: readonly string[], options?: ParseArgsOptions): ParsedArgs;
106
116
  /**
@@ -111,6 +121,24 @@ export declare function extractGlobalCwd(argv: readonly string[]): {
111
121
  cwd?: string;
112
122
  rest: string[];
113
123
  };
124
+ /** A request to compress a command's stdout, parsed from the global flags. */
125
+ export interface IGlobalCompressDirective {
126
+ /** Force a content type for the compressor (else auto-detect). */
127
+ type?: string;
128
+ /** Query text that biases which lines/matches the compressor keeps. */
129
+ query?: string;
130
+ }
131
+ /**
132
+ * Extracts the global output-compression flags from anywhere in argv:
133
+ * `--compress` / `--ccr` (synonyms; turn it on) plus optional
134
+ * `--compress-type <t>` and `--compress-query <q>`. Returns the directive (when
135
+ * any was present) and the remaining argv with those flags removed — so the
136
+ * underlying command can be re-run cleanly without them (and never recurses).
137
+ */
138
+ export declare function extractGlobalCompress(argv: readonly string[]): {
139
+ directive?: IGlobalCompressDirective;
140
+ rest: string[];
141
+ };
114
142
  /**
115
143
  * Returns the absolute cwd for the current command:
116
144
  * 1. Command-level --cwd flag (if passed after the command)
@@ -1 +1 @@
1
- {"version":3,"file":"command-registry.d.ts","sourceRoot":"","sources":["../src/command-registry.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IACrC,0EAA0E;IAC1E,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACjD;AAED;;;;;GAKG;AACH,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAMD,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IACjC,mFAAmF;IACnF,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,sEAAsE;IACtE,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0EAA0E;IAC1E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
222
  else {
223
223
  key = arg.slice(2);
224
224
  const next = argv[i + 1];
225
- if (next !== undefined && !next.startsWith('-')) {
225
+ // A known boolean flag never consumes the following token, so
226
+ // flag-first ordering (`--json <file>`, `--no-enhance "<task>"`) keeps
227
+ // the token as a positional instead of swallowing it as the value.
228
+ if (options.booleanFlags?.has(key)) {
229
+ value = true;
230
+ }
231
+ else if (next !== undefined && !next.startsWith('-')) {
226
232
  value = next;
227
233
  i += 1;
228
234
  }
@@ -256,6 +262,13 @@ export function extractGlobalCwd(argv) {
256
262
  let cwd;
257
263
  for (let i = 0; i < argv.length; i += 1) {
258
264
  const t = argv[i];
265
+ // Honor the POSIX `--` end-of-options separator (as parseArgs does):
266
+ // everything after it is a literal positional, so a `--cwd` there must not
267
+ // be intercepted. Preserve `--` and the remainder verbatim.
268
+ if (t === '--') {
269
+ rest.push(...argv.slice(i));
270
+ break;
271
+ }
259
272
  if (t === '--cwd') {
260
273
  const next = argv[i + 1];
261
274
  if (next !== undefined && !next.startsWith('-')) {
@@ -277,6 +290,83 @@ export function extractGlobalCwd(argv) {
277
290
  cwd = nodePath.resolve(process.cwd(), cwd);
278
291
  return cwd === undefined ? { rest } : { cwd, rest };
279
292
  }
293
+ /**
294
+ * Extracts the global output-compression flags from anywhere in argv:
295
+ * `--compress` / `--ccr` (synonyms; turn it on) plus optional
296
+ * `--compress-type <t>` and `--compress-query <q>`. Returns the directive (when
297
+ * any was present) and the remaining argv with those flags removed — so the
298
+ * underlying command can be re-run cleanly without them (and never recurses).
299
+ */
300
+ export function extractGlobalCompress(argv) {
301
+ const rest = [];
302
+ let active = false;
303
+ let type;
304
+ let query;
305
+ const valued = (token, flag, set, i) => {
306
+ if (token === flag) {
307
+ const next = argv[i + 1];
308
+ if (next !== undefined && !next.startsWith('-')) {
309
+ set(next);
310
+ return true; // caller skips next
311
+ }
312
+ return false;
313
+ }
314
+ return false;
315
+ };
316
+ for (let i = 0; i < argv.length; i += 1) {
317
+ const t = argv[i];
318
+ // Honor the POSIX `--` end-of-options separator exactly as parseArgs does:
319
+ // everything after it is a literal positional, so a compress-flag-shaped
320
+ // token there must NOT be intercepted (and the next token must not be
321
+ // swallowed as a value). Preserve `--` and the remainder verbatim for the
322
+ // child to re-parse.
323
+ if (t === '--') {
324
+ rest.push(...argv.slice(i));
325
+ break;
326
+ }
327
+ if (t === '--compress' || t === '--ccr') {
328
+ active = true;
329
+ continue;
330
+ }
331
+ if (t.startsWith('--compress-type=')) {
332
+ type = t.slice('--compress-type='.length);
333
+ active = true;
334
+ continue;
335
+ }
336
+ if (t.startsWith('--compress-query=')) {
337
+ query = t.slice('--compress-query='.length);
338
+ active = true;
339
+ continue;
340
+ }
341
+ if (t === '--compress-type') {
342
+ if (valued(t, '--compress-type', (v) => (type = v), i)) {
343
+ active = true;
344
+ i += 1;
345
+ continue;
346
+ }
347
+ active = true;
348
+ continue;
349
+ }
350
+ if (t === '--compress-query') {
351
+ if (valued(t, '--compress-query', (v) => (query = v), i)) {
352
+ active = true;
353
+ i += 1;
354
+ continue;
355
+ }
356
+ active = true;
357
+ continue;
358
+ }
359
+ rest.push(t);
360
+ }
361
+ if (!active)
362
+ return { rest };
363
+ const directive = {};
364
+ if (type !== undefined)
365
+ directive.type = type;
366
+ if (query !== undefined)
367
+ directive.query = query;
368
+ return { directive, rest };
369
+ }
280
370
  /**
281
371
  * Returns the absolute cwd for the current command:
282
372
  * 1. Command-level --cwd flag (if passed after the command)
@@ -1 +1 @@
1
- {"version":3,"file":"apply.command.d.ts","sourceRoot":"","sources":["../../src/commands/apply.command.ts"],"names":[],"mappings":"AAqDA,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAC;AAyLhC,eAAO,MAAM,YAAY,EAAE,eAyrB1B,CAAC"}
1
+ {"version":3,"file":"apply.command.d.ts","sourceRoot":"","sources":["../../src/commands/apply.command.ts"],"names":[],"mappings":"AAqDA,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAC;AAyLhC,eAAO,MAAM,YAAY,EAAE,eAisB1B,CAAC"}
@@ -179,7 +179,7 @@ async function runApplyBatchFromCli(args, batchPath) {
179
179
  export const applyCommand = {
180
180
  name: 'apply',
181
181
  description: 'Apply a previously-saved generation plan (sharkcraft.plan/v1 JSON). The CLI is the only write path; MCP never writes. Plans that live under .sharkcraft/sessions/<id>/plans/ automatically update the session metadata (signature + divergence + applied + validation).',
182
- usage: 'shrk [--cwd <dir>] apply <plan.json> [--session <id>] [--force] [--allow-divergent] [--verify-signature] [--require-signature] [--dry-run] [--validate] [--report] [--json] [--trace] [--explain-dispatch] | shrk apply --asset-preview <draft.ts> --target <file> [--write] [--allow-unknown-target] [--reason <text>] | shrk apply --batch <plan.json> [--allow-divergent] [--dry-run] [--json]',
182
+ usage: 'shrk [--cwd <dir>] apply <plan.json> [--session <id>] [--force] [--allow-divergent] [--verify-signature] [--require-signature] [--no-verify-signature] [--dry-run] [--validate] [--report] [--json] [--trace] [--explain-dispatch] | shrk apply --asset-preview <draft.ts> --target <file> [--write] [--allow-unknown-target] [--reason <text>] | shrk apply --batch <plan.json> [--allow-divergent] [--dry-run] [--json]',
183
183
  async run(args) {
184
184
  // Asset-preview flow: paste-with-review for authoring drafts.
185
185
  // Distinct from the plan-based apply path: takes a TS draft and a
@@ -222,7 +222,15 @@ export const applyCommand = {
222
222
  const explainOnly = flagBool(args, 'explain-dispatch');
223
223
  let signatureStatus = DevSessionSignatureStatus.NotChecked;
224
224
  let signatureMessage;
225
- if (verifySig) {
225
+ // A plan that CARRIES a signature self-enforces verification: the signature
226
+ // is the producer's tamper-evidence declaration, so a signed plan must not
227
+ // apply unverified just because the caller forgot --verify-signature
228
+ // (contract: "Apply requires --verify-signature for signed plans"). A
229
+ // tampered/invalid signature then refuses below. `--no-verify-signature` is
230
+ // the explicit escape hatch for sign-here / apply-there-without-the-secret.
231
+ const isSigned = Boolean(saved.signature);
232
+ const skipSig = flagBool(args, 'no-verify-signature') && !verifySig;
233
+ if (verifySig || (isSigned && !skipSig)) {
226
234
  const result = verifyPlan(saved);
227
235
  if (result.ok === true) {
228
236
  signatureStatus = DevSessionSignatureStatus.Verified;
@@ -1 +1 @@
1
- {"version":3,"file":"command-catalog.d.ts","sourceRoot":"","sources":["../../src/commands/command-catalog.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,QAAQ,cAAc;IACtB,iBAAiB,mBAAmB;IACpC,gBAAgB,kBAAkB;IAClC,YAAY,kBAAkB;IAC9B,SAAS,eAAe;IACxB,cAAc,oBAAoB;CACnC;AAED;;;;;;GAMG;AACH,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAED,8BAA8B;AAC9B,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,EAAE,OAAO;IACT,UAAU,gBAAgB;IAC1B,UAAU,eAAe;CAC1B;AAED;;;;;;GAMG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED;;;;;;GAMG;AACH,oBAAY,gBAAgB;IAC1B,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,OAAO,YAAY;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,oBAAY,WAAW;IACrB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,YAAY,iBAAiB;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,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AAgB,wBAAwB,IAAI,SAAS,uBAAuB,EAAE,CAsB7E;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,SAAS,uBAAuB,EAAE,GACvC,MAAM,CAaR"}
1
+ {"version":3,"file":"command-catalog.d.ts","sourceRoot":"","sources":["../../src/commands/command-catalog.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,QAAQ,cAAc;IACtB,iBAAiB,mBAAmB;IACpC,gBAAgB,kBAAkB;IAClC,YAAY,kBAAkB;IAC9B,SAAS,eAAe;IACxB,cAAc,oBAAoB;CACnC;AAED;;;;;;GAMG;AACH,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAED,8BAA8B;AAC9B,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,EAAE,OAAO;IACT,UAAU,gBAAgB;IAC1B,UAAU,eAAe;CAC1B;AAED;;;;;;GAMG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED;;;;;;GAMG;AACH,oBAAY,gBAAgB;IAC1B,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,OAAO,YAAY;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,oBAAY,WAAW;IACrB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,YAAY,iBAAiB;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAA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E,OAAO,CAAC;CACrB;AAED,wBAAgB,wBAAwB,IAAI,SAAS,uBAAuB,EAAE,CAsB7E;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,SAAS,uBAAuB,EAAE,GACvC,MAAM,CAaR"}
@@ -438,6 +438,18 @@ export const COMMAND_CATALOG = Object.freeze([
438
438
  surface: CommandSurface.Common,
439
439
  taskRole: CommandTaskRole.Apply,
440
440
  }),
441
+ entry({
442
+ command: 'delegate',
443
+ description: 'Hand a mechanical edit to a local-LLM worker; the engine verifies the result and auto-reverts on failure (run|brief). Writes source only via --apply through the signed-plan + verify gate.',
444
+ category: 'core',
445
+ safetyLevel: SafetyLevel.WritesSource,
446
+ writesFiles: true,
447
+ writesSource: true,
448
+ requiresReview: true,
449
+ surface: CommandSurface.Advanced,
450
+ intendedAudience: [CommandAudience.Human, CommandAudience.Agent],
451
+ taskRole: CommandTaskRole.Apply,
452
+ }),
441
453
  // `shrk spec` intent artifact over plan/review/apply.
442
454
  entry({
443
455
  command: 'spec',
@@ -3402,6 +3414,8 @@ const PRIMARY_VERBS_ALLOWLIST = new Set([
3402
3414
  'impact',
3403
3415
  'graph',
3404
3416
  'code-intel',
3417
+ 'compress',
3418
+ 'expand',
3405
3419
  // Generate code safely
3406
3420
  'gen',
3407
3421
  'apply',
@@ -1,11 +1,4 @@
1
1
  import { type ICommandHandler } from '../command-registry.js';
2
- /**
3
- * `shrk compress` — deterministically compress a blob (file or stdin) before
4
- * it re-enters an agent prompt. Same information, fewer tokens. Lossy passes
5
- * cache the original under `.sharkcraft/ccr/` so `shrk expand <key>` can get
6
- * it back. The compressed text goes to stdout (pipeable); the savings summary
7
- * goes to stderr unless `--json` is set.
8
- */
9
2
  export declare const compressCommand: ICommandHandler;
10
3
  /**
11
4
  * `shrk expand` — the retrieve half of CCR. Print the full original that
@@ -1 +1 @@
1
- {"version":3,"file":"compress.command.d.ts","sourceRoot":"","sources":["../../src/commands/compress.command.ts"],"names":[],"mappings":"AAQA,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAC;AAgBhC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,eAkE7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,eA0B3B,CAAC"}
1
+ {"version":3,"file":"compress.command.d.ts","sourceRoot":"","sources":["../../src/commands/compress.command.ts"],"names":[],"mappings":"AAQA,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAC;AA2BhC,eAAO,MAAM,eAAe,EAAE,eAgF7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,eA4B3B,CAAC"}
@@ -1,12 +1,10 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import * as nodePath from 'node:path';
3
- import { compressContent, EContentType, FileCcrStore, } from '@shrkcrft/compress';
2
+ import { Buffer } from 'node:buffer';
3
+ import { compressContent, ECompressionStrategy, EContentType, } from '@shrkcrft/compress';
4
4
  import { flagBool, flagNumber, flagString, resolveCwd, } from "../command-registry.js";
5
5
  import { asJson } from "../output/format-output.js";
6
+ import { ccrDir, openCcrStore } from "../output/ccr-store-config.js";
6
7
  const CONTENT_TYPES = new Set(Object.values(EContentType));
7
- function ccrDir(cwd) {
8
- return nodePath.join(cwd, '.sharkcraft', 'ccr');
9
- }
10
8
  function readInput(args) {
11
9
  const positional = args.positional[0];
12
10
  const useStdin = flagBool(args, 'stdin') || positional === undefined || positional === '-';
@@ -21,10 +19,17 @@ function readInput(args) {
21
19
  * it back. The compressed text goes to stdout (pipeable); the savings summary
22
20
  * goes to stderr unless `--json` is set.
23
21
  */
22
+ const COMPRESS_BOOLEAN_FLAGS = new Set([
23
+ 'stdin',
24
+ 'lossless',
25
+ 'no-cache',
26
+ 'json',
27
+ ]);
24
28
  export const compressCommand = {
25
29
  name: 'compress',
26
30
  description: 'Compress a blob (file or stdin) deterministically to cut tokens — JSON→table, logs/search/diffs→signal. Reversible via `shrk expand`.',
27
- usage: 'shrk [--cwd <dir>] compress [<file>|-] [--stdin] [--type <content-type>] [--query <text>] [--max <n>] [--no-cache] [--json]',
31
+ usage: 'shrk [--cwd <dir>] compress [<file>|-] [--stdin] [--type <content-type>] [--query <text>] [--max <n>] [--lossless] [--no-cache] [--json]',
32
+ booleanFlags: COMPRESS_BOOLEAN_FLAGS,
28
33
  run(args) {
29
34
  const cwd = resolveCwd(args);
30
35
  let content;
@@ -41,13 +46,15 @@ export const compressCommand = {
41
46
  }
42
47
  const opts = {};
43
48
  if (!flagBool(args, 'no-cache'))
44
- opts.store = new FileCcrStore(ccrDir(cwd));
49
+ opts.store = openCcrStore(cwd);
45
50
  const query = flagString(args, 'query');
46
51
  if (query)
47
52
  opts.query = query;
48
53
  const max = flagNumber(args, 'max');
49
54
  if (max !== undefined && max > 0)
50
55
  opts.maxItems = Math.floor(max);
56
+ if (flagBool(args, 'lossless'))
57
+ opts.lossless = true;
51
58
  const type = flagString(args, 'type');
52
59
  if (type && CONTENT_TYPES.has(type))
53
60
  opts.contentType = type;
@@ -59,8 +66,11 @@ export const compressCommand = {
59
66
  process.stderr.write('warning: compressed lossily but the original was NOT cached (--no-cache) — ' +
60
67
  'detail is unrecoverable; omit --no-cache to keep it retrievable via `shrk expand`.\n');
61
68
  }
69
+ const queryApplied = query !== undefined && query.length > 0;
62
70
  if (flagBool(args, 'json')) {
63
- process.stdout.write(asJson({
71
+ // tokens are a deterministic ESTIMATE (chars/divisor heuristic), not a
72
+ // real BPE count — flagged so callers don't treat savedRatio as exact.
73
+ const base = {
64
74
  contentType: result.contentType,
65
75
  strategy: result.strategy,
66
76
  lossy: result.lossy,
@@ -68,15 +78,25 @@ export const compressCommand = {
68
78
  tokensAfter: result.savings.after,
69
79
  tokensSaved: result.savings.saved,
70
80
  savedRatio: result.savings.ratio,
81
+ tokensAreEstimated: true,
82
+ queryApplied,
71
83
  ccrKey: result.ccrKey ?? null,
72
84
  note: result.note,
73
- compressed: result.compressed,
74
- }) + '\n');
85
+ };
86
+ // Net-loss guard: on a passthrough/no-win blob the engine returns the
87
+ // VERBATIM original as `compressed`. Echoing it back inside the JSON
88
+ // envelope (plus scaffold) costs more tokens than the input. Signal
89
+ // passthrough and omit the duplicated content — the caller still has it.
90
+ const noWin = result.strategy === ECompressionStrategy.Passthrough || result.savings.saved <= 0;
91
+ const payload = noWin
92
+ ? { ...base, passthrough: true, inputBytes: Buffer.byteLength(content, 'utf8') }
93
+ : { ...base, compressed: result.compressed };
94
+ process.stdout.write(asJson(payload) + '\n');
75
95
  return 0;
76
96
  }
77
97
  process.stdout.write(result.compressed + '\n');
78
98
  const cached = result.ccrKey ? ` · original cached as ${result.ccrKey} (shrk expand ${result.ccrKey})` : '';
79
- process.stderr.write(`${result.strategy}: ${result.savings.before} → ${result.savings.after} tokens (−${pct}%)${cached}\n`);
99
+ process.stderr.write(`${result.strategy}: ~${result.savings.before} → ~${result.savings.after} tokens (−${pct}%, est.)${cached}\n`);
80
100
  return 0;
81
101
  },
82
102
  };
@@ -95,7 +115,7 @@ export const expandCommand = {
95
115
  process.stderr.write('expand: a CCR key is required (e.g. `shrk expand a1b2c3d4e5f60718`).\n');
96
116
  return 1;
97
117
  }
98
- const store = new FileCcrStore(ccrDir(cwd));
118
+ const store = openCcrStore(cwd);
99
119
  const entry = store.get(key);
100
120
  if (!entry) {
101
121
  process.stderr.write(`expand: no cached original for key "${key}" under ${ccrDir(cwd)}.\n`);
@@ -105,7 +125,9 @@ export const expandCommand = {
105
125
  process.stdout.write(asJson({ key: entry.key, bytes: entry.bytes, content: entry.content }) + '\n');
106
126
  return 0;
107
127
  }
108
- process.stdout.write(entry.content + '\n');
128
+ // Write the cached original VERBATIM — appending a newline broke byte-for-byte
129
+ // round-trip (`compress … ; expand` must reproduce the input exactly).
130
+ process.stdout.write(entry.content);
109
131
  return 0;
110
132
  },
111
133
  };
@@ -0,0 +1,65 @@
1
+ import { type IAiProvider } from '@shrkcrft/ai';
2
+ import { type IDelegateRecipe } from '@shrkcrft/config';
3
+ import { type IDroppedOp } from '@shrkcrft/generator';
4
+ import { type ICommandHandler } from '../command-registry.js';
5
+ export type DelegateRunStatus = 'no-provider' | 'generate-failed' | 'guardrail-refused' | 'package-error' | 'conflicts' | 'sign-failed' | 'no-verification' | 'generated' | 'applied' | 'apply-failed' | 'verify-failed';
6
+ export interface IExecuteDelegateRunInput {
7
+ task: string;
8
+ recipe: IDelegateRecipe;
9
+ projectRoot: string;
10
+ /** Injectable for tests; `null` means no local LLM is reachable. */
11
+ provider: IAiProvider | null;
12
+ apply: boolean;
13
+ /** Where to write the signed plan. Default `.sharkcraft/delegate/<id>.plan.json`. */
14
+ planPath?: string;
15
+ /** Explicit HMAC secret. Falls back to `SHARKCRAFT_PLAN_SECRET`. */
16
+ planSecret?: string;
17
+ /** Validation report dir. Default `.sharkcraft/delegate/reports`. */
18
+ reportDir?: string;
19
+ }
20
+ export interface IExecuteDelegateRunResult {
21
+ status: DelegateRunStatus;
22
+ recipeId: string;
23
+ message: string;
24
+ planPath?: string;
25
+ ops?: number;
26
+ droppedOps?: readonly IDroppedOp[];
27
+ refused?: readonly string[];
28
+ conflicts?: readonly string[];
29
+ written?: readonly string[];
30
+ reverted?: boolean;
31
+ verification?: {
32
+ passed: boolean;
33
+ commandsFailed: readonly string[];
34
+ };
35
+ usage?: {
36
+ inputTokens?: number;
37
+ outputTokens?: number;
38
+ };
39
+ retried?: boolean;
40
+ /** How many generate→verify attempts ran before this result (1-based). */
41
+ attempts?: number;
42
+ /** Compressed unified diff of what the edit changed (compact result hand-back). */
43
+ diff?: string;
44
+ /** CCR key when the diff was lossily compressed (recover via `shrk expand`). */
45
+ diffCcrKey?: string;
46
+ }
47
+ /**
48
+ * The in-scope files (current contents, compressed to signatures via the
49
+ * code-outline pass) handed to the LOCAL worker so it can pick the right
50
+ * targetPath, check idempotency, and find exact text to replace — instead of
51
+ * guessing. This goes in the WORKER's prompt, read locally, so it costs the
52
+ * orchestrator (Claude) NOTHING. Bounded to keep a small local model's context
53
+ * focused. Returns '' when there's nothing in scope / on any error.
54
+ */
55
+ export declare function gatherRecipeContext(projectRoot: string, recipe: IDelegateRecipe): string;
56
+ /**
57
+ * The testable orchestration core: a bounded GENERATE→VERIFY retry loop. On a
58
+ * retryable failure (parse / guardrail / bad-op / conflict / verification) the
59
+ * worker is re-prompted with the failure injected, up to `recipe.maxAttempts`,
60
+ * then the run escalates. A provider / signing / environment failure is NOT
61
+ * retried. Takes an already-resolved recipe + provider so tests inject a fake.
62
+ */
63
+ export declare function executeDelegateRun(input: IExecuteDelegateRunInput): Promise<IExecuteDelegateRunResult>;
64
+ export declare const delegateCommand: ICommandHandler;
65
+ //# sourceMappingURL=delegate.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegate.command.d.ts","sourceRoot":"","sources":["../../src/commands/delegate.command.ts"],"names":[],"mappings":"AAgBA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAqB,KAAK,eAAe,EAA0B,MAAM,kBAAkB,CAAC;AASnG,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAC;AAMhC,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,GACf,WAAW,GACX,aAAa,GACb,iBAAiB,GACjB,WAAW,GACX,SAAS,GACT,cAAc,GACd,eAAe,CAAC;AAEpB,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAA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