@wrongstack/cli 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/data/providers.json +44 -0
  2. package/dist/{acp-AJWSKWE5.js → acp-LI665LO2.js} +5 -5
  3. package/dist/ascii-mode-SG4PRNLP.js +7 -0
  4. package/dist/{auth-GRBZ7Y3D.js → auth-TE55JF4Z.js} +14 -14
  5. package/dist/{bench-N5K7Z5O3.js → bench-GTLPM22B.js} +2 -2
  6. package/dist/boot/append-system-prompt.d.ts +10 -0
  7. package/dist/boot/ascii-mode.d.ts +12 -0
  8. package/dist/boot/container-wiring.d.ts +4 -2
  9. package/dist/boot/dispatch-singleshot.d.ts +4 -1
  10. package/dist/boot/mcp-config-flag.d.ts +22 -0
  11. package/dist/boot/piped-stdin.d.ts +40 -0
  12. package/dist/boot/restricted-mode.d.ts +15 -0
  13. package/dist/boot/safe-mode.d.ts +30 -0
  14. package/dist/boot/single-shot-budget.d.ts +30 -0
  15. package/dist/boot/stream-json.d.ts +36 -0
  16. package/dist/boot/structured-output.d.ts +16 -0
  17. package/dist/boot/system-prompt-builder.d.ts +2 -0
  18. package/dist/boot/tool-restriction-flags.d.ts +36 -0
  19. package/dist/boot/worktree-sessions.d.ts +21 -0
  20. package/dist/boot-provider-selection.d.ts +67 -0
  21. package/dist/boot.d.ts +1 -38
  22. package/dist/{chunk-LFMVHT3R.js → chunk-2ERX3RPN.js} +11 -13
  23. package/dist/chunk-4TVYGG6G.js +62 -0
  24. package/dist/chunk-5JYDKG5B.js +154 -0
  25. package/dist/{chunk-3VXYY5JC.js → chunk-5UZBUV2H.js} +3 -19
  26. package/dist/chunk-BEHGRNOQ.js +58 -0
  27. package/dist/chunk-CZTXF6HY.js +140 -0
  28. package/dist/{chunk-SKPDE62W.js → chunk-EPR42SWM.js} +36 -6
  29. package/dist/{chunk-YBUCXXYZ.js → chunk-F5DCFAKI.js} +1 -1
  30. package/dist/chunk-HLSHFXTO.js +97 -0
  31. package/dist/{chunk-BLD5DSVA.js → chunk-KJS5543T.js} +2 -2
  32. package/dist/{chunk-QFPQXKCG.js → chunk-KOEO4CJG.js} +21 -6
  33. package/dist/chunk-LBPLTTZ6.js +105 -0
  34. package/dist/{chunk-3OCUS3VN.js → chunk-LDCGZJTC.js} +4 -4
  35. package/dist/chunk-LKPEBZBE.js +143 -0
  36. package/dist/{chunk-DRM7PSW7.js → chunk-OAVBM55Q.js} +3 -3
  37. package/dist/chunk-PZQBGUVZ.js +18 -0
  38. package/dist/{chunk-MHEBWVXL.js → chunk-Q4INH2DG.js} +46 -2
  39. package/dist/{chunk-ZZRSG7VK.js → chunk-RZ4ZDRYA.js} +3 -3
  40. package/dist/{chunk-U46QR4WR.js → chunk-TI7KLHYX.js} +132 -3
  41. package/dist/{chunk-PGKJ2OQP.js → chunk-WQV2NP57.js} +5 -5
  42. package/dist/chunk-X756ZS72.js +329 -0
  43. package/dist/{chunk-JF2MULWF.js → chunk-YHYINL47.js} +47 -15
  44. package/dist/{cli-context-34Q5IJRA.js → cli-context-UVGAN3NO.js} +407 -327
  45. package/dist/{cli-main-AELJDBGU.js → cli-main-TN3KZ2P6.js} +2652 -1978
  46. package/dist/cli-update-notice.d.ts +2 -1
  47. package/dist/config-doctor.d.ts +1 -1
  48. package/dist/{diag-doctor-WIFJH3XH.js → diag-doctor-BIZAFIAT.js} +2 -2
  49. package/dist/{execution-PYC5FCS4.js → execution-7QIP6GRY.js} +1948 -1666
  50. package/dist/fleet/host-types.d.ts +3 -1
  51. package/dist/goal-commands.d.ts +47 -0
  52. package/dist/goal-host.d.ts +1 -14
  53. package/dist/{hq-JTUTFI4L.js → hq-GLZ7QESM.js} +6 -6
  54. package/dist/{hq-server-PC7GZMPT.js → hq-server-YTKDVQPY.js} +2 -2
  55. package/dist/{hq-service-NW56MUP2.js → hq-service-BMMJAHRT.js} +4 -4
  56. package/dist/import-claude-code-32PCSIQI.js +236 -0
  57. package/dist/index.js +12 -8
  58. package/dist/{mailbox-serve-WDOCH6KR.js → mailbox-serve-NW5VZG7R.js} +3 -3
  59. package/dist/{modeldiag-36OGAL5C.js → modeldiag-36VODVIH.js} +8 -8
  60. package/dist/{per-subcommand-help-XE77MTGJ.js → per-subcommand-help-QDAQASPZ.js} +2 -2
  61. package/dist/permission-prompt.d.ts +14 -0
  62. package/dist/permission-rules-view.d.ts +18 -0
  63. package/dist/{permissions-CFDLXETM.js → permissions-PL27UHYD.js} +67 -45
  64. package/dist/{plugin-usage-S5LVGMBW.js → plugin-usage-CIGOOTX3.js} +2 -2
  65. package/dist/{plugins-RHBIVLI7.js → plugins-HQTXUD6A.js} +4 -2
  66. package/dist/preflight.d.ts +1 -1
  67. package/dist/{projects-LMNAGGEU.js → projects-T4CZCA25.js} +3 -6
  68. package/dist/provider-helpers.d.ts +7 -11
  69. package/dist/{providers-models-2CFG46RD.js → providers-models-5Z2PJTEW.js} +5 -5
  70. package/dist/release-asset-download.d.ts +10 -0
  71. package/dist/release-attestation.d.ts +28 -0
  72. package/dist/remote/remote-session.d.ts +64 -0
  73. package/dist/remote/remote-target.d.ts +69 -0
  74. package/dist/remote-O5WXHLWV.js +561 -0
  75. package/dist/{replay-Z3FTJEMM.js → replay-DEI566CW.js} +2 -2
  76. package/dist/services/commit-message.d.ts +2 -1
  77. package/dist/session-move-P2EC2COA.js +44 -0
  78. package/dist/session-move.d.ts +20 -0
  79. package/dist/session-stats.d.ts +10 -0
  80. package/dist/{sessions-config-IQUH2GXT.js → sessions-config-SXTTLNXA.js} +35 -5
  81. package/dist/short-circuit-flags-74Y5N6CF.js +10 -0
  82. package/dist/slash-commands/command-context.d.ts +15 -5
  83. package/dist/slash-commands/goal-refiner.d.ts +4 -49
  84. package/dist/slash-commands/mcp.d.ts +2 -1
  85. package/dist/slash-commands/permissions.d.ts +4 -0
  86. package/dist/slash-commands/settings-context-mutations.d.ts +5 -0
  87. package/dist/slash-commands/settings-limits-mutations.d.ts +12 -0
  88. package/dist/standalone-auto-update-TOTRGCSA.js +249 -0
  89. package/dist/standalone-auto-update.d.ts +65 -0
  90. package/dist/standalone-update-LZO3MNLH.js +24 -0
  91. package/dist/standalone-update.d.ts +37 -1
  92. package/dist/subcommands/handlers/import-claude-code.d.ts +42 -0
  93. package/dist/subcommands/handlers/permissions.d.ts +9 -3
  94. package/dist/subcommands/handlers/remote.d.ts +6 -0
  95. package/dist/subcommands/handlers/version-help.d.ts +5 -0
  96. package/dist/{subcommands-ZTSIN7LG.js → subcommands-Q6ORSB2E.js} +2 -2
  97. package/dist/tui-resume-callback.d.ts +18 -0
  98. package/dist/{typesafe-HVEVPA6R.js → typesafe-U7YB2RRV.js} +5 -5
  99. package/dist/{typesafe-topic-replay-4W73BOLV.js → typesafe-topic-replay-ZILIU3WS.js} +18 -2
  100. package/dist/{update-7XIOEXTD.js → update-TDZX4IL2.js} +4 -4
  101. package/dist/{update-check-2POMBHFB.js → update-check-J5ZVKS73.js} +3 -3
  102. package/dist/version-JB2UAV2A.js +11 -0
  103. package/dist/version-help-XJJQ7YSH.js +10 -0
  104. package/dist/webui-server/route-contexts.d.ts +1 -1
  105. package/dist/webui-server/session-start-payload.d.ts +5 -1
  106. package/dist/{webui-server-L2SICPTB.js → webui-server-YTHLRFD2.js} +509 -366
  107. package/dist/webui-server-lifecycle.d.ts +57 -0
  108. package/dist/webui-server.d.ts +0 -14
  109. package/dist/wiring/brain-and-orchestration.d.ts +3 -1
  110. package/dist/wiring/cli-prompt-and-tools-setup.d.ts +9 -0
  111. package/dist/wiring/cli-slash-commands-setup.d.ts +1 -0
  112. package/dist/wiring/lifecycle-plugins.d.ts +4 -2
  113. package/dist/wiring/metrics.d.ts +9 -1
  114. package/dist/wiring/pipeline.d.ts +2 -7
  115. package/dist/wiring/plugins.d.ts +3 -0
  116. package/dist/wiring/provider-status.d.ts +1 -0
  117. package/dist/wiring/provider-utility-tools.d.ts +3 -1
  118. package/package.json +28 -28
  119. package/dist/chunk-2BKFWIER.js +0 -98
  120. package/dist/chunk-424ORSE7.js +0 -56
  121. package/dist/chunk-QBBF7GIK.js +0 -65
  122. package/dist/short-circuit-flags-SDT53OML.js +0 -10
  123. package/dist/standalone-update-MW47J3AK.js +0 -164
  124. package/dist/version-help-WZ623NWM.js +0 -10
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  activeProfileConfigPath
3
3
  } from "./chunk-YMXXOOFN.js";
4
+ import {
5
+ restoreFlags
6
+ } from "./chunk-CSAPOCBP.js";
4
7
  import {
5
8
  backupCurrent,
6
9
  getHistoryEntry,
@@ -8,11 +11,9 @@ import {
8
11
  restoreFromHistory,
9
12
  restoreLast
10
13
  } from "./chunk-WSTVGC2C.js";
11
- import {
12
- restoreFlags
13
- } from "./chunk-CSAPOCBP.js";
14
14
 
15
15
  // src/subcommands/handlers/sessions-config.ts
16
+ import * as path2 from "node:path";
16
17
  import { color as color2, expectDefined } from "@wrongstack/core/utils";
17
18
 
18
19
  // src/subcommands/handlers/helpers.ts
@@ -296,6 +297,35 @@ var sessionsCmd = async (args, deps) => {
296
297
  } catch (err) {
297
298
  deps.renderer.writeError(
298
299
  `Fork failed: ${err instanceof Error ? err.message : String(err)}
300
+ `
301
+ );
302
+ return 1;
303
+ }
304
+ }
305
+ if (sub === "move") {
306
+ const moveArgs = args.slice(1);
307
+ const sessionId = moveArgs[0] && !moveArgs[0].startsWith("-") ? moveArgs[0] : void 0;
308
+ const targetPath = extractArg(moveArgs, "--to");
309
+ if (!sessionId || !targetPath) {
310
+ deps.renderer.writeError(
311
+ "Usage: wstack sessions move <id> --to <project or worktree path>\n"
312
+ );
313
+ return 1;
314
+ }
315
+ try {
316
+ const { moveSessionTo, describeSessionMove } = await import("./session-move-P2EC2COA.js");
317
+ const result = await moveSessionTo({
318
+ store: deps.sessionStore,
319
+ sessionId,
320
+ targetPath: path2.resolve(deps.cwd, targetPath),
321
+ globalRoot: deps.paths.globalRoot
322
+ });
323
+ deps.renderer.write(`${describeSessionMove(result)}
324
+ `);
325
+ return 0;
326
+ } catch (err) {
327
+ deps.renderer.writeError(
328
+ `Move failed: ${err instanceof Error ? err.message : String(err)}
299
329
  `
300
330
  );
301
331
  return 1;
@@ -308,7 +338,7 @@ var sessionsCmd = async (args, deps) => {
308
338
  }
309
339
  for (const s of list)
310
340
  deps.renderer.write(
311
- ` ${s.id} ${color2.dim(s.startedAt)} ${color2.dim(`${s.tokenTotal} tok`)} ${s.title}
341
+ ` ${s.id} ${color2.dim(s.startedAt)} ${color2.dim(`${s.tokenTotal} tok`)} ${s.name ? `${color2.cyan(s.name)} ${color2.dim(s.title)}` : s.title}
312
342
  `
313
343
  );
314
344
  return 0;
@@ -426,4 +456,4 @@ export {
426
456
  configCmd,
427
457
  sessionsCmd
428
458
  };
429
- //# sourceMappingURL=sessions-config-IQUH2GXT.js.map
459
+ //# sourceMappingURL=sessions-config-SXTTLNXA.js.map
@@ -0,0 +1,10 @@
1
+ import {
2
+ handleHelpVersionShortCircuit
3
+ } from "./chunk-WQV2NP57.js";
4
+ import "./chunk-5JYDKG5B.js";
5
+ import "./chunk-F5DCFAKI.js";
6
+ import "./chunk-Q4INH2DG.js";
7
+ export {
8
+ handleHelpVersionShortCircuit
9
+ };
10
+ //# sourceMappingURL=short-circuit-flags-74Y5N6CF.js.map
@@ -1,7 +1,7 @@
1
1
  import type { Context } from '@wrongstack/core/agent';
2
2
  import type { EventBus } from '@wrongstack/core/kernel';
3
3
  import type { SlashCommandRegistry, ToolRegistry } from '@wrongstack/core/registry';
4
- import type { CompactReport, HealthRegistry, MemoryPort, MetricsRuntimeStatus, MetricsSink, ModeStore, Renderer, SessionStore, SkillLoader, TokenCounter } from '@wrongstack/core/types';
4
+ import type { CompactOptions, CompactReport, HealthRegistry, MemoryPort, MetricsRuntimeStatus, MetricsSink, ModeStore, PermissionPolicy, Renderer, SessionStore, SkillLoader, TokenCounter } from '@wrongstack/core/types';
5
5
  import type { WstackPaths } from '@wrongstack/core/utils';
6
6
  import type { SummarizerPort } from '@wrongstack/tools';
7
7
  import type { VectorMemoryStore } from '@wrongstack/vector-memory';
@@ -9,6 +9,12 @@ import type { VectorMemoryStore } from '@wrongstack/vector-memory';
9
9
  export interface SlashCommandContext {
10
10
  registry: SlashCommandRegistry;
11
11
  toolRegistry: ToolRegistry;
12
+ /**
13
+ * The agent's permission policy: `/permissions rules|explain` read it, and
14
+ * it reads each session's `/permissions allow|deny` rules from that
15
+ * session's context.
16
+ */
17
+ permissionPolicy?: PermissionPolicy | undefined;
12
18
  /** Run one tool through the active ToolExecutor and its permission policy. */
13
19
  executeTool?: ((name: string, input: Record<string, unknown>, ctx: Context) => Promise<{
14
20
  detail: string;
@@ -19,9 +25,7 @@ export interface SlashCommandContext {
19
25
  /** Explicit legacy SDD session codec for compatibility tests/old hosts. */
20
26
  sddSessionTransport?: 'kanban' | 'legacy-file' | undefined;
21
27
  compactor?: {
22
- compact(ctx: Context, opts?: {
23
- aggressive?: boolean | undefined;
24
- }): Promise<CompactReport>;
28
+ compact(ctx: Context, opts?: CompactOptions): Promise<CompactReport>;
25
29
  };
26
30
  sessionStore?: SessionStore | undefined;
27
31
  skillLoader?: SkillLoader | undefined;
@@ -536,7 +540,13 @@ export interface SlashCommandContext {
536
540
  * Resume a persisted PhaseGraph. The host creates a new orchestrator for
537
541
  * the loaded graph and starts executing pending tasks.
538
542
  */
539
- onGoalResumeFromGraph?: ((graph: import('@wrongstack/core/goal').PhaseGraph) => Promise<void>) | undefined;
543
+ onGoalResumeFromGraph?: ((graph: import('@wrongstack/core/goal').PhaseGraph) => Promise<{
544
+ ok: true;
545
+ graph: import('@wrongstack/core/goal').PhaseGraph;
546
+ } | {
547
+ ok: false;
548
+ error: string;
549
+ }>) | undefined;
540
550
  /** Live, read-only view of the running Goal (null when idle). */
541
551
  getGoalRunner?: () => {
542
552
  graph: import('@wrongstack/core/goal').PhaseGraph;
@@ -1,14 +1,11 @@
1
1
  import type { OneShotOrchestrator } from '@wrongstack/core/execution';
2
- import type { Config, Provider } from '@wrongstack/core/types';
2
+ import { type RefinedMission } from '@wrongstack/core/goal';
3
+ import type { Provider } from '@wrongstack/core/types';
4
+ export { refineGoalHeuristic, resolveRefinerTarget } from '@wrongstack/core/goal';
3
5
  /**
4
6
  * Result of refining a user's raw goal into a clear, actionable mission.
5
7
  */
6
- interface RefinedGoal {
7
- /** Unambiguous, detailed goal statement. */
8
- refinedGoal: string;
9
- /** Concrete, verifiable deliverables (one per entry). */
10
- deliverables: string[];
11
- }
8
+ type RefinedGoal = RefinedMission;
12
9
  /**
13
10
  * Options for goal refinement with fallback tiers.
14
11
  */
@@ -31,42 +28,6 @@ interface GoalRefinerOptions {
31
28
  */
32
29
  oneShotOrchestrator?: OneShotOrchestrator | undefined;
33
30
  }
34
- /**
35
- * Resolved refiner target after validating against available providers,
36
- * favorite models, and the currently active session model.
37
- * Both `provider` and `model` are defined when a viable dedicated refiner
38
- * is found; otherwise the caller should use the primary session defaults.
39
- */
40
- interface ResolvedRefinerTarget {
41
- /** Resolved provider instance, ready for `provider.complete()`. */
42
- provider: Provider;
43
- /** Resolved model id on that provider. */
44
- model: string;
45
- }
46
- /**
47
- * Validate and resolve a dedicated refiner provider+model from the user
48
- * config. Returns undefined when:
49
- * - refinerFallbackProfile resolves to a valid profile entry (tried first)
50
- * - Neither refinerProvider nor refinerModel is configured
51
- * - The configured provider is unavailable (createProvider returns
52
- * undefined, meaning the provider doesn't exist or has no credentials)
53
- * - The configured model is not a favorite model AND is not the
54
- * currently active session model
55
- *
56
- * Precedence (first wins):
57
- * 1. refinerFallbackProfile → first valid entry from the named profile chain
58
- * 2. refinerProvider + refinerModel (both set)
59
- * 3. refinerModel on the active session provider
60
- *
61
- * When only `refinerModel` is set (no provider), the model is used on
62
- * the active session provider — validated against the same constraints.
63
- *
64
- * @param cfg — live Config from configStore
65
- * @param createProvider— factory: providerId → Provider | undefined
66
- * @param activeProviderId — the session's active provider id (config.provider)
67
- * @param activeModel — the session's active model (config.model)
68
- */
69
- export declare function resolveRefinerTarget(cfg: Config, createProvider: ((providerId: string) => Provider | undefined) | undefined, activeProviderId: string, activeModel: string): ResolvedRefinerTarget | undefined;
70
31
  /**
71
32
  * Refine a raw goal using the best available model/provider, with a
72
33
  * four-tier fallback chain:
@@ -85,10 +46,4 @@ export declare function refineGoalWithFallback(rawGoal: string, opts: GoalRefine
85
46
  * or the call fails.
86
47
  */
87
48
  export declare function refineGoal(rawGoal: string, provider: Provider, model: string, oneShotOrchestrator?: OneShotOrchestrator | undefined): Promise<RefinedGoal | null>;
88
- /**
89
- * Heuristic-only refinement — used when no LLM is available.
90
- * Produces a basic structure from the raw goal.
91
- */
92
- export declare function refineGoalHeuristic(rawGoal: string): RefinedGoal;
93
- export {};
94
49
  //# sourceMappingURL=goal-refiner.d.ts.map
@@ -18,7 +18,8 @@ export { parseMcpArgs, runMcpManagementCommand } from '../services/mcp-managemen
18
18
  * /mcp prompts <name> — discover cached/live prompts
19
19
  * /mcp read <name> <uri> — explicitly insert a selected resource
20
20
  * /mcp get <name> <prompt> [key=value...] — explicitly insert a selected prompt
21
- * /mcp auth start <name> <client-id> <redirect-uri> [scopes...] — begin OAuth
21
+ * /mcp auth login <name> [--client-id <id>] [--port <n>] [scopes...] — one-step OAuth
22
+ * /mcp auth start <name> --redirect-uri <url> [--client-id <id>] [scopes...] — manual OAuth
22
23
  * /mcp auth complete <name> <callback-url> — finish OAuth from a callback URL
23
24
  * /mcp auth status <name> — show non-secret authorization state
24
25
  * /mcp auth logout <name> — remove stored OAuth credentials
@@ -0,0 +1,4 @@
1
+ import type { SlashCommand } from '@wrongstack/core/types';
2
+ import type { SlashCommandContext } from './command-context.js';
3
+ export declare function buildPermissionsCommand(opts: SlashCommandContext): SlashCommand;
4
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { persistConfigSetting } from '../settings-menu.js';
2
+ export declare function executeContextSettings(sub: string, rest: string[], persistDeps: Parameters<typeof persistConfigSetting>[0]): Promise<{
3
+ message: string;
4
+ } | undefined>;
5
+ //# sourceMappingURL=settings-context-mutations.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { type LimitsConfig } from '@wrongstack/core/types';
2
+ import { persistConfigSetting } from '../settings-menu.js';
3
+ /** Render `/settings limits` — every limit, whether the user set it, and its range. */
4
+ export declare function renderLimitsView(limits: LimitsConfig | undefined): string;
5
+ /**
6
+ * `/settings limits [<name> <n|off>]`. Limits are user config only (denied to
7
+ * in-project config), so writes always go to the active profile.
8
+ */
9
+ export declare function executeLimitsSettings(sub: string, rest: string[], persistDeps: Parameters<typeof persistConfigSetting>[0], current: LimitsConfig | undefined): Promise<{
10
+ message: string;
11
+ } | undefined>;
12
+ //# sourceMappingURL=settings-limits-mutations.d.ts.map
@@ -0,0 +1,249 @@
1
+ import {
2
+ MAX_BINARY_BYTES,
3
+ downloadReleaseAssetToFile,
4
+ findStandaloneRelease,
5
+ installExecutableFrom,
6
+ verifyStandaloneDigest
7
+ } from "./chunk-X756ZS72.js";
8
+ import {
9
+ isNewer
10
+ } from "./chunk-RZ4ZDRYA.js";
11
+ import {
12
+ CLI_VERSION,
13
+ STANDALONE_TARGET
14
+ } from "./chunk-F5DCFAKI.js";
15
+
16
+ // src/standalone-auto-update.ts
17
+ import { randomBytes } from "node:crypto";
18
+ import * as fs from "node:fs";
19
+ import * as path from "node:path";
20
+ import { isStandaloneBinary, wstackGlobalRoot } from "@wrongstack/core/utils";
21
+ var PENDING_FILE = "pending.json";
22
+ var APPLIED_FILE = "last-applied.json";
23
+ var LOCK_FILE = "update.lock";
24
+ var LOCK_STALE_MS = 45 * 6e4;
25
+ var DOWNLOAD_TIMEOUT_MS = 30 * 6e4;
26
+ function updatesDir(root = wstackGlobalRoot()) {
27
+ return path.join(root, "updates");
28
+ }
29
+ function autoUpdateEnabled(config, env = process.env) {
30
+ const off = env["WRONGSTACK_NO_AUTO_UPDATE"];
31
+ if (off !== void 0 && off !== "" && off !== "0") return false;
32
+ return config?.update?.autoDownload !== false;
33
+ }
34
+ function readPendingUpdate(dir = updatesDir()) {
35
+ let raw;
36
+ try {
37
+ raw = JSON.parse(fs.readFileSync(path.join(dir, PENDING_FILE), "utf8"));
38
+ } catch {
39
+ return void 0;
40
+ }
41
+ const p = raw;
42
+ if (!p || typeof p.version !== "string" || typeof p.file !== "string" || typeof p.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(p.sha256) || typeof p.target !== "string" || typeof p.executable !== "string" || // Only ever install from the staging directory itself.
43
+ path.dirname(path.resolve(p.file)) !== path.resolve(dir) || !fs.existsSync(p.file)) {
44
+ return void 0;
45
+ }
46
+ return {
47
+ version: p.version,
48
+ file: p.file,
49
+ sha256: p.sha256,
50
+ target: p.target,
51
+ executable: p.executable,
52
+ stagedAt: typeof p.stagedAt === "string" ? p.stagedAt : ""
53
+ };
54
+ }
55
+ function discardPending(dir, pending) {
56
+ fs.rmSync(path.join(dir, PENDING_FILE), { force: true });
57
+ if (pending) fs.rmSync(pending.file, { force: true });
58
+ }
59
+ function writeJsonAtomic(file, value) {
60
+ const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
61
+ fs.writeFileSync(tmp, `${JSON.stringify(value, null, 2)}
62
+ `, { mode: 384, flag: "wx" });
63
+ fs.renameSync(tmp, file);
64
+ }
65
+ function pidAlive(pid) {
66
+ try {
67
+ process.kill(pid, 0);
68
+ return true;
69
+ } catch (err) {
70
+ return err.code === "EPERM";
71
+ }
72
+ }
73
+ function acquireLock(dir) {
74
+ const lock = path.join(dir, LOCK_FILE);
75
+ for (let attempt = 0; attempt < 2; attempt++) {
76
+ try {
77
+ fs.writeFileSync(lock, JSON.stringify({ pid: process.pid, at: Date.now() }), { flag: "wx" });
78
+ return () => fs.rmSync(lock, { force: true });
79
+ } catch (err) {
80
+ if (err.code !== "EEXIST") throw err;
81
+ let owner = {};
82
+ try {
83
+ owner = JSON.parse(fs.readFileSync(lock, "utf8"));
84
+ } catch {
85
+ }
86
+ const fresh = typeof owner.pid === "number" && pidAlive(owner.pid) && typeof owner.at === "number" && Date.now() - owner.at < LOCK_STALE_MS;
87
+ if (fresh) return void 0;
88
+ fs.rmSync(lock, { force: true });
89
+ }
90
+ }
91
+ return void 0;
92
+ }
93
+ function applyPending(install, platform) {
94
+ const { dir, current, executable } = install;
95
+ const pending = readPendingUpdate(dir);
96
+ if (!pending) return void 0;
97
+ if (!isNewer(pending.version, current)) {
98
+ discardPending(dir, pending);
99
+ return void 0;
100
+ }
101
+ if (pending.executable !== executable) return void 0;
102
+ const release = acquireLock(dir);
103
+ if (!release) return void 0;
104
+ try {
105
+ try {
106
+ installExecutableFrom(executable, pending.file, pending.sha256, platform);
107
+ } catch (err) {
108
+ if (/does not match its digest/.test(String(err))) discardPending(dir, pending);
109
+ throw err;
110
+ }
111
+ discardPending(dir, pending);
112
+ writeJsonAtomic(path.join(dir, APPLIED_FILE), {
113
+ from: current,
114
+ to: pending.version,
115
+ at: (/* @__PURE__ */ new Date()).toISOString()
116
+ });
117
+ return pending.version;
118
+ } finally {
119
+ release();
120
+ }
121
+ }
122
+ function takeAppliedUpdate(dir = updatesDir()) {
123
+ const file = path.join(dir, APPLIED_FILE);
124
+ try {
125
+ const raw = JSON.parse(fs.readFileSync(file, "utf8"));
126
+ fs.rmSync(file, { force: true });
127
+ if (typeof raw.from === "string" && typeof raw.to === "string") {
128
+ return { from: raw.from, to: raw.to };
129
+ }
130
+ } catch {
131
+ }
132
+ return void 0;
133
+ }
134
+ async function stageLatest(install, signal) {
135
+ const { dir } = install;
136
+ const release = await findStandaloneRelease(install.target, signal);
137
+ if (!isNewer(release.version, install.current)) return void 0;
138
+ const already = readPendingUpdate(dir);
139
+ if (already?.version === release.version && already.target === install.target && already.executable === install.executable) {
140
+ return already;
141
+ }
142
+ fs.mkdirSync(dir, { recursive: true, mode: 448 });
143
+ const unlock = acquireLock(dir);
144
+ if (!unlock) return void 0;
145
+ const partial = path.join(dir, `.partial-${randomBytes(9).toString("hex")}`);
146
+ try {
147
+ const sha256 = await downloadReleaseAssetToFile(release.asset.browser_download_url, partial, {
148
+ timeoutMs: DOWNLOAD_TIMEOUT_MS,
149
+ maxBytes: MAX_BINARY_BYTES,
150
+ signal
151
+ });
152
+ await verifyStandaloneDigest(release, sha256, signal);
153
+ const file = path.join(dir, `${release.version}-${release.assetName}`);
154
+ fs.rmSync(file, { force: true });
155
+ fs.renameSync(partial, file);
156
+ const pending = {
157
+ version: release.version,
158
+ file,
159
+ sha256,
160
+ target: install.target,
161
+ executable: install.executable,
162
+ stagedAt: (/* @__PURE__ */ new Date()).toISOString()
163
+ };
164
+ writeJsonAtomic(path.join(dir, PENDING_FILE), pending);
165
+ for (const name of fs.readdirSync(dir)) {
166
+ const keep = [PENDING_FILE, APPLIED_FILE, LOCK_FILE, path.basename(file)];
167
+ if (!keep.includes(name)) fs.rmSync(path.join(dir, name), { force: true, recursive: true });
168
+ }
169
+ return pending;
170
+ } finally {
171
+ fs.rmSync(partial, { force: true });
172
+ unlock();
173
+ }
174
+ }
175
+ function standaloneUpdater(install) {
176
+ const bound = { ...install, dir: install.dir ?? updatesDir() };
177
+ const pending = () => {
178
+ const found = readPendingUpdate(bound.dir);
179
+ return found?.executable === bound.executable ? found : void 0;
180
+ };
181
+ return {
182
+ pending,
183
+ stage: (signal) => stageLatest(bound, signal),
184
+ apply: (platform) => applyPending(bound, platform),
185
+ clear: () => {
186
+ const found = pending();
187
+ if (found) discardPending(bound.dir, found);
188
+ }
189
+ };
190
+ }
191
+ function startStandaloneAutoUpdate(options) {
192
+ if (!isStandaloneBinary() || !STANDALONE_TARGET) return void 0;
193
+ if (!autoUpdateEnabled(options.getConfig())) return void 0;
194
+ let updater;
195
+ try {
196
+ updater = standaloneUpdater({
197
+ executable: fs.realpathSync(process.execPath),
198
+ target: STANDALONE_TARGET,
199
+ current: CLI_VERSION
200
+ });
201
+ } catch {
202
+ return void 0;
203
+ }
204
+ const listeners = /* @__PURE__ */ new Set();
205
+ let ready;
206
+ const markReady = (version) => {
207
+ ready = version;
208
+ for (const listener of listeners) listener(version);
209
+ };
210
+ process.once("exit", () => {
211
+ if (!autoUpdateEnabled(options.getConfig())) return;
212
+ try {
213
+ updater.apply();
214
+ } catch {
215
+ }
216
+ });
217
+ const found = updater.pending();
218
+ const pending = found && isNewer(found.version, CLI_VERSION) ? found : void 0;
219
+ const latest = options.updateInfo?.outdated ? options.updateInfo.latest : void 0;
220
+ const controller = new AbortController();
221
+ if (pending && (latest === void 0 || !isNewer(latest, pending.version))) {
222
+ ready = pending.version;
223
+ } else if (latest !== void 0) {
224
+ void updater.stage(controller.signal).then((staged) => {
225
+ if (staged) markReady(staged.version);
226
+ }).catch((err) => {
227
+ if (controller.signal.aborted) return;
228
+ options.onError?.(err instanceof Error ? err.message : String(err));
229
+ });
230
+ }
231
+ return {
232
+ subscribe(listener) {
233
+ listeners.add(listener);
234
+ if (ready) listener(ready);
235
+ return () => listeners.delete(listener);
236
+ },
237
+ dispose() {
238
+ controller.abort();
239
+ listeners.clear();
240
+ }
241
+ };
242
+ }
243
+ export {
244
+ autoUpdateEnabled,
245
+ standaloneUpdater,
246
+ startStandaloneAutoUpdate,
247
+ takeAppliedUpdate
248
+ };
249
+ //# sourceMappingURL=standalone-auto-update-TOTRGCSA.js.map
@@ -0,0 +1,65 @@
1
+ import type { Config } from '@wrongstack/core/types';
2
+ import { type StagedStandaloneUpdate } from './standalone-update.js';
3
+ import { type UpdateInfo } from './update-check.js';
4
+ /** A verified build waiting to be swapped in. */
5
+ export interface PendingUpdate extends StagedStandaloneUpdate {
6
+ /** `bun build --target` it was built for. */
7
+ target: string;
8
+ /** Real path of the executable it replaces. */
9
+ executable: string;
10
+ stagedAt: string;
11
+ }
12
+ /** `update.autoDownload` (default on) and the `WRONGSTACK_NO_AUTO_UPDATE` switch. */
13
+ export declare function autoUpdateEnabled(config: Config | undefined, env?: NodeJS.ProcessEnv): boolean;
14
+ /** The swap a previous session made, reported once. */
15
+ export declare function takeAppliedUpdate(dir?: string): {
16
+ from: string;
17
+ to: string;
18
+ } | undefined;
19
+ /** The updates of one install of the executable. */
20
+ export interface StandaloneUpdater {
21
+ /** Its verified build waiting to be swapped in, if any. */
22
+ pending(): PendingUpdate | undefined;
23
+ /**
24
+ * Download, verify and stage the latest release when it is newer. Returns
25
+ * the pending update (possibly one staged earlier), or undefined when there
26
+ * is nothing newer or another session is downloading.
27
+ */
28
+ stage(signal?: AbortSignal): Promise<PendingUpdate | undefined>;
29
+ /**
30
+ * Swap the pending build in over the executable. Synchronous (it runs from
31
+ * the process `exit` handler); returns the installed version, or undefined
32
+ * when there was nothing to install. A pending build that is not newer, or
33
+ * whose file no longer matches its digest, is thrown away.
34
+ */
35
+ apply(platform?: NodeJS.Platform): string | undefined;
36
+ /**
37
+ * Drop the pending build after `wstack update` brought the executable to
38
+ * the latest release: it is either the build just installed or an older one.
39
+ */
40
+ clear(): void;
41
+ }
42
+ export declare function standaloneUpdater(install: {
43
+ executable: string;
44
+ target: string;
45
+ current: string;
46
+ dir?: string | undefined;
47
+ }): StandaloneUpdater;
48
+ /** What an interactive session sees of the background update. */
49
+ export interface StandaloneAutoUpdate {
50
+ /** Called once the update is ready (immediately, when it already is). */
51
+ subscribe(listener: (version: string) => void): () => void;
52
+ /** Stop a download in progress. The exit swap stays armed. */
53
+ dispose(): void;
54
+ }
55
+ /**
56
+ * Start the background update for an interactive session: arm the exit swap,
57
+ * and download the latest release when `updateInfo` says one is newer.
58
+ * Undefined for the npm install or when switched off.
59
+ */
60
+ export declare function startStandaloneAutoUpdate(options: {
61
+ getConfig: () => Config | undefined;
62
+ updateInfo: UpdateInfo | undefined;
63
+ onError?: ((message: string) => void) | undefined;
64
+ }): StandaloneAutoUpdate | undefined;
65
+ //# sourceMappingURL=standalone-auto-update.d.ts.map
@@ -0,0 +1,24 @@
1
+ import {
2
+ MAX_BINARY_BYTES,
3
+ fetchLatestStandaloneVersion,
4
+ findStandaloneRelease,
5
+ installExecutableFrom,
6
+ parseSha256Sums,
7
+ replaceExecutable,
8
+ standaloneAssetName,
9
+ updateStandaloneBinary,
10
+ verifyStandaloneDigest
11
+ } from "./chunk-X756ZS72.js";
12
+ import "./chunk-F5DCFAKI.js";
13
+ export {
14
+ MAX_BINARY_BYTES,
15
+ fetchLatestStandaloneVersion,
16
+ findStandaloneRelease,
17
+ installExecutableFrom,
18
+ parseSha256Sums,
19
+ replaceExecutable,
20
+ standaloneAssetName,
21
+ updateStandaloneBinary,
22
+ verifyStandaloneDigest
23
+ };
24
+ //# sourceMappingURL=standalone-update-LZO3MNLH.js.map
@@ -1,7 +1,28 @@
1
1
  import type { TerminalRenderer } from './renderer.js';
2
- export declare const RELEASES_REPO = "WrongStack/WrongStack";
2
+ export declare const MAX_BINARY_BYTES: number;
3
+ interface ReleaseAsset {
4
+ name: string;
5
+ browser_download_url: string;
6
+ /** `sha256:<hex>`, computed by GitHub when the asset was uploaded. */
7
+ digest?: string | null | undefined;
8
+ }
3
9
  /** Asset name a build target publishes under (mirrors build-binaries.mjs `outputName`). */
4
10
  export declare function standaloneAssetName(target: string): string;
11
+ /** The latest release's executable for `target`, with its SHA256SUMS. */
12
+ export interface StandaloneRelease {
13
+ version: string;
14
+ assetName: string;
15
+ asset: ReleaseAsset;
16
+ sums: ReleaseAsset;
17
+ }
18
+ /** Throws when the latest release has no build for `target`. */
19
+ export declare function findStandaloneRelease(target: string, signal?: AbortSignal): Promise<StandaloneRelease>;
20
+ /**
21
+ * Throws unless `sha256` is the release's own build of the asset: listed in
22
+ * its SHA256SUMS, equal to the digest GitHub computed at upload, and vouched
23
+ * for by the release workflow's build attestation.
24
+ */
25
+ export declare function verifyStandaloneDigest(release: StandaloneRelease, sha256: string, signal?: AbortSignal): Promise<void>;
5
26
  /** Latest released version, for the update check. */
6
27
  export declare function fetchLatestStandaloneVersion(timeoutMs?: number, signal?: AbortSignal): Promise<string>;
7
28
  /** `<sha256> <name>` lines → map. */
@@ -11,9 +32,24 @@ export declare function parseSha256Sums(text: string): Map<string, string>;
11
32
  * is a same-filesystem rename.
12
33
  */
13
34
  export declare function replaceExecutable(target: string, bytes: Buffer, platform?: NodeJS.Platform): void;
35
+ /**
36
+ * Replace `target` with the file at `source` (a downloaded update), refusing
37
+ * unless the copy that is about to become the executable hashes to `sha256`.
38
+ * Synchronous: it runs from the process `exit` handler.
39
+ */
40
+ export declare function installExecutableFrom(target: string, source: string, sha256: string, platform?: NodeJS.Platform): void;
41
+ /** A verified download the background updater left waiting (standalone-auto-update.ts). */
42
+ export interface StagedStandaloneUpdate {
43
+ version: string;
44
+ file: string;
45
+ sha256: string;
46
+ }
14
47
  /** `wstack update` for the standalone binary. Returns the process exit code. */
15
48
  export declare function updateStandaloneBinary(options: {
16
49
  current: string;
17
50
  renderer: Pick<TerminalRenderer, 'write'>;
51
+ /** Installed instead of downloading again when it is the latest release. */
52
+ staged?: StagedStandaloneUpdate | undefined;
18
53
  }): Promise<number>;
54
+ export {};
19
55
  //# sourceMappingURL=standalone-update.d.ts.map
@@ -0,0 +1,42 @@
1
+ import type { MCPServerConfig } from '@wrongstack/core/types';
2
+ import type { SubcommandHandler } from '../contracts.js';
3
+ export type McpImportSource = 'claude-user' | 'claude-project-local' | 'repository';
4
+ export interface McpImportCandidate {
5
+ name: string;
6
+ source: McpImportSource;
7
+ config: Partial<MCPServerConfig>;
8
+ action: 'add' | 'overwrite' | 'skip-exists' | 'skip-invalid';
9
+ enabled: boolean;
10
+ note?: string | undefined;
11
+ }
12
+ export interface ClaudeCodeImportPlan {
13
+ mcp: McpImportCandidate[];
14
+ notes: string[];
15
+ }
16
+ export interface ClaudeCodeSources {
17
+ /** Parsed `~/.claude.json`, or undefined when absent. */
18
+ userState?: Record<string, unknown> | undefined;
19
+ /** Parsed `<project>/.mcp.json`, or undefined when absent. */
20
+ projectMcp?: Record<string, unknown> | undefined;
21
+ /** Settings files that exist, with their parsed content. */
22
+ settings: Array<{
23
+ file: string;
24
+ content: Record<string, unknown>;
25
+ }>;
26
+ /** CLAUDE.md files that exist. */
27
+ instructionFiles: string[];
28
+ /** Skill directories that exist. */
29
+ skillDirs: string[];
30
+ }
31
+ /** Decide what an import would do. Pure: no reads, no writes. */
32
+ export declare function planClaudeCodeImport(opts: {
33
+ sources: ClaudeCodeSources;
34
+ projectRoot: string;
35
+ existingServers: Readonly<Record<string, unknown>>;
36
+ overwrite: boolean;
37
+ enableProjectServers: boolean;
38
+ }): ClaudeCodeImportPlan;
39
+ /** Read everything the importer looks at. Missing files are simply absent. */
40
+ export declare function readClaudeCodeSources(projectRoot: string, userHome?: string): Promise<ClaudeCodeSources>;
41
+ export declare const importClaudeCodeCmd: SubcommandHandler;
42
+ //# sourceMappingURL=import-claude-code.d.ts.map