@moxxy/plugin-self-update 0.26.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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/dist/classify.d.ts +33 -0
  3. package/dist/classify.d.ts.map +1 -0
  4. package/dist/classify.js +177 -0
  5. package/dist/classify.js.map +1 -0
  6. package/dist/core-tools/apply.d.ts +4 -0
  7. package/dist/core-tools/apply.d.ts.map +1 -0
  8. package/dist/core-tools/apply.js +43 -0
  9. package/dist/core-tools/apply.js.map +1 -0
  10. package/dist/core-tools/begin.d.ts +4 -0
  11. package/dist/core-tools/begin.d.ts.map +1 -0
  12. package/dist/core-tools/begin.js +76 -0
  13. package/dist/core-tools/begin.js.map +1 -0
  14. package/dist/core-tools/edit.d.ts +4 -0
  15. package/dist/core-tools/edit.d.ts.map +1 -0
  16. package/dist/core-tools/edit.js +33 -0
  17. package/dist/core-tools/edit.js.map +1 -0
  18. package/dist/core-tools/index.d.ts +11 -0
  19. package/dist/core-tools/index.d.ts.map +1 -0
  20. package/dist/core-tools/index.js +28 -0
  21. package/dist/core-tools/index.js.map +1 -0
  22. package/dist/core-tools/preflight.d.ts +4 -0
  23. package/dist/core-tools/preflight.d.ts.map +1 -0
  24. package/dist/core-tools/preflight.js +14 -0
  25. package/dist/core-tools/preflight.js.map +1 -0
  26. package/dist/core-tools/rollback.d.ts +4 -0
  27. package/dist/core-tools/rollback.d.ts.map +1 -0
  28. package/dist/core-tools/rollback.js +30 -0
  29. package/dist/core-tools/rollback.js.map +1 -0
  30. package/dist/core-tools/shared.d.ts +16 -0
  31. package/dist/core-tools/shared.d.ts.map +1 -0
  32. package/dist/core-tools/shared.js +12 -0
  33. package/dist/core-tools/shared.js.map +1 -0
  34. package/dist/core-tools/status.d.ts +4 -0
  35. package/dist/core-tools/status.d.ts.map +1 -0
  36. package/dist/core-tools/status.js +25 -0
  37. package/dist/core-tools/status.js.map +1 -0
  38. package/dist/core-tools/verify.d.ts +4 -0
  39. package/dist/core-tools/verify.d.ts.map +1 -0
  40. package/dist/core-tools/verify.js +39 -0
  41. package/dist/core-tools/verify.js.map +1 -0
  42. package/dist/core-tools/write.d.ts +4 -0
  43. package/dist/core-tools/write.d.ts.map +1 -0
  44. package/dist/core-tools/write.js +28 -0
  45. package/dist/core-tools/write.js.map +1 -0
  46. package/dist/core-update.d.ts +173 -0
  47. package/dist/core-update.d.ts.map +1 -0
  48. package/dist/core-update.js +626 -0
  49. package/dist/core-update.js.map +1 -0
  50. package/dist/deps.d.ts +49 -0
  51. package/dist/deps.d.ts.map +1 -0
  52. package/dist/deps.js +30 -0
  53. package/dist/deps.js.map +1 -0
  54. package/dist/index.d.ts +22 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +349 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/transaction.d.ts +80 -0
  59. package/dist/transaction.d.ts.map +1 -0
  60. package/dist/transaction.js +188 -0
  61. package/dist/transaction.js.map +1 -0
  62. package/dist/verify.d.ts +23 -0
  63. package/dist/verify.d.ts.map +1 -0
  64. package/dist/verify.js +164 -0
  65. package/dist/verify.js.map +1 -0
  66. package/package.json +61 -0
  67. package/src/classify.test.ts +176 -0
  68. package/src/classify.ts +221 -0
  69. package/src/core-tools/apply.ts +44 -0
  70. package/src/core-tools/begin.ts +94 -0
  71. package/src/core-tools/edit.ts +33 -0
  72. package/src/core-tools/index.ts +33 -0
  73. package/src/core-tools/preflight.ts +15 -0
  74. package/src/core-tools/rollback.ts +30 -0
  75. package/src/core-tools/shared.test.ts +16 -0
  76. package/src/core-tools/shared.ts +24 -0
  77. package/src/core-tools/status.ts +26 -0
  78. package/src/core-tools/verify.ts +39 -0
  79. package/src/core-tools/write.ts +30 -0
  80. package/src/core-update.test.ts +542 -0
  81. package/src/core-update.ts +744 -0
  82. package/src/deps.ts +84 -0
  83. package/src/discovery.test.ts +40 -0
  84. package/src/index.test.ts +299 -0
  85. package/src/index.ts +441 -0
  86. package/src/transaction.test.ts +143 -0
  87. package/src/transaction.ts +254 -0
  88. package/src/verify.test.ts +82 -0
  89. package/src/verify.ts +200 -0
@@ -0,0 +1,25 @@
1
+ import { defineTool, z } from '@moxxy/sdk';
2
+ import { listCoreTxns } from '../core-update.js';
3
+ // ── self_update_core_status ─────────────────────────────────────────────────
4
+ export function coreStatusTool(cd) {
5
+ const { deps } = cd;
6
+ return defineTool({
7
+ name: 'self_update_core_status',
8
+ description: 'List Tier-2 core-update transactions and their state.',
9
+ inputSchema: z.object({}),
10
+ permission: { action: 'allow' },
11
+ handler: async () => {
12
+ const all = await listCoreTxns(deps.moxxyDir);
13
+ return {
14
+ transactions: all.map((j) => ({
15
+ coreTxnId: j.txnId,
16
+ state: j.state,
17
+ packages: j.packages,
18
+ version: j.version,
19
+ updatedAt: j.updatedAt,
20
+ })),
21
+ };
22
+ },
23
+ });
24
+ }
25
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/core-tools/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,CAAC,EAAgB,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,EAAgB;IAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACpB,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,yBAAyB;QAC/B,WAAW,EAAE,uDAAuD;QACpE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,UAAU,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAC/B,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9C,OAAO;gBACL,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAC5B,SAAS,EAAE,CAAC,CAAC,KAAK;oBAClB,KAAK,EAAE,CAAC,CAAC,KAAK;oBACd,QAAQ,EAAE,CAAC,CAAC,QAAQ;oBACpB,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,SAAS,EAAE,CAAC,CAAC,SAAS;iBACvB,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type ToolDef } from '@moxxy/sdk';
2
+ import { type CoreToolDeps } from './shared.js';
3
+ export declare function coreVerifyTool(cd: CoreToolDeps): ToolDef;
4
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/core-tools/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAG3E,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAG7D,wBAAgB,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAgCxD"}
@@ -0,0 +1,39 @@
1
+ import { defineTool, z } from '@moxxy/sdk';
2
+ import { readCoreJournal, verifyCorePackages, writeCoreJournal } from '../core-update.js';
3
+ import { emitSafe } from '../deps.js';
4
+ import { resolveCore } from './shared.js';
5
+ // ── self_update_core_verify ─────────────────────────────────────────────────
6
+ export function coreVerifyTool(cd) {
7
+ const { deps } = cd;
8
+ return defineTool({
9
+ name: 'self_update_core_verify',
10
+ description: 'Build, typecheck and test the affected core packages (and their dependents) in the clone, and confirm the patch adds no new runtime dependency. Returns stage results. Run AFTER edits; nothing in the live install changes here.',
11
+ inputSchema: z.object({ coreTxnId: z.string().min(1) }),
12
+ permission: { action: 'prompt' },
13
+ handler: async (input, ctx) => {
14
+ const journal = await readCoreJournal(deps.moxxyDir, input.coreTxnId);
15
+ const install = resolveCore(cd);
16
+ if (!install)
17
+ throw new Error('could not resolve @moxxy/core');
18
+ const res = await verifyCorePackages(journal.repoDir, install, journal.packages);
19
+ journal.attempts.push({
20
+ at: new Date().toISOString(),
21
+ stage: 'verify',
22
+ ok: res.ok,
23
+ message: res.ok ? 'build/typecheck/test ok' : res.stages.find((s) => !s.ok)?.message ?? 'failed',
24
+ });
25
+ journal.state = res.ok ? 'verified' : journal.state;
26
+ await writeCoreJournal(deps.moxxyDir, journal);
27
+ await emitSafe(deps, ctx, res.ok ? 'core_verify_ok' : 'core_verify_failed', { txnId: input.coreTxnId });
28
+ return {
29
+ ok: res.ok,
30
+ stages: res.stages,
31
+ newDeps: res.newDeps,
32
+ next: res.ok
33
+ ? 'Passed — call self_update_core_apply to overlay it into the live install (a restart is then required).'
34
+ : 'Fix the errors and re-verify, or escalate to the user.',
35
+ };
36
+ },
37
+ });
38
+ }
39
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/core-tools/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,CAAC,EAAkC,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAC;AAE7D,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,EAAgB;IAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACpB,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,yBAAyB;QAC/B,WAAW,EACT,mOAAmO;QACrO,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,UAAU,EAAE,EAAE,MA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EAAE,GAAG,CAAC,MAAM;gBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,IAAI,EAAE,GAAG,CAAC,EAAE;oBACV,CAAC,CAAC,wGAAwG;oBAC1G,CAAC,CAAC,wDAAwD;aAC7D,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type ToolDef } from '@moxxy/sdk';
2
+ import type { CoreToolDeps } from './shared.js';
3
+ export declare function coreWriteTool(cd: CoreToolDeps): ToolDef;
4
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/core-tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmC,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAG3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,wBAAgB,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO,CAqBvD"}
@@ -0,0 +1,28 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { defineTool, z } from '@moxxy/sdk';
4
+ import { readCoreJournal, safeRepoPath } from '../core-update.js';
5
+ import { emitSafe } from '../deps.js';
6
+ // ── self_update_core_write ──────────────────────────────────────────────────
7
+ export function coreWriteTool(cd) {
8
+ const { deps } = cd;
9
+ return defineTool({
10
+ name: 'self_update_core_write',
11
+ description: 'Write a file inside the provisioned core clone for a transaction (paths are relative to the repo root and cannot escape it). This is an approval-gated code write — show the user the content first.',
12
+ inputSchema: z.object({
13
+ coreTxnId: z.string().min(1),
14
+ file: z.string().min(1).describe('Path relative to the repo root, e.g. packages/core/src/foo.ts'),
15
+ content: z.string(),
16
+ }),
17
+ permission: { action: 'prompt' },
18
+ handler: async (input, ctx) => {
19
+ const journal = await readCoreJournal(deps.moxxyDir, input.coreTxnId);
20
+ const abs = safeRepoPath(journal.repoDir, input.file);
21
+ await fs.mkdir(path.dirname(abs), { recursive: true });
22
+ await fs.writeFile(abs, input.content, 'utf8');
23
+ await emitSafe(deps, ctx, 'core_write', { txnId: input.coreTxnId, file: input.file });
24
+ return { ok: true, wrote: input.file };
25
+ },
26
+ });
27
+ }
28
+ //# sourceMappingURL=write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.js","sourceRoot":"","sources":["../../src/core-tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAkC,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,EAAgB;IAC5C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACpB,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EACT,sMAAsM;QACxM,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,+DAA+D,CAAC;YACjG,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;SACpB,CAAC;QACF,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;QAChC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAgB,EAAE,EAAE;YACzC,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;YACtE,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACtD,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvD,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC/C,MAAM,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACtF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QACzC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,173 @@
1
+ export declare function shortName(pkg: string): string;
2
+ export interface RunResult {
3
+ readonly code: number;
4
+ readonly output: string;
5
+ }
6
+ export declare function run(cmd: string, args: ReadonlyArray<string>, cwd: string, timeoutMs?: number): Promise<RunResult>;
7
+ export interface CoreInstallInfo {
8
+ readonly version: string;
9
+ readonly gitHead?: string;
10
+ readonly repoUrl?: string;
11
+ /** The `@moxxy` scope dir under node_modules (where every @moxxy/* package sits). */
12
+ readonly scopeDir: string;
13
+ }
14
+ /**
15
+ * Resolve the live `@moxxy/core` install to learn its version, the commit it
16
+ * was published from (npm writes `gitHead` on publish), and the on-disk root
17
+ * to overlay into.
18
+ */
19
+ export declare function detectCoreInstall(fromUrl: string): CoreInstallInfo | null;
20
+ export interface PreflightReport {
21
+ readonly ok: boolean;
22
+ readonly checks: ReadonlyArray<{
23
+ id: string;
24
+ ok: boolean;
25
+ detail: string;
26
+ }>;
27
+ }
28
+ export declare function corePreflight(install: CoreInstallInfo | null): Promise<PreflightReport>;
29
+ export type CoreState = 'open' | 'provisioned' | 'verified' | 'staged_restart' | 'committed' | 'rolled_back' | 'escalated';
30
+ export interface CoreJournal {
31
+ readonly txnId: string;
32
+ readonly createdAt: string;
33
+ updatedAt: string;
34
+ packages: string[];
35
+ readonly version: string;
36
+ readonly gitHead?: string;
37
+ readonly repoDir: string;
38
+ state: CoreState;
39
+ attempts: {
40
+ at: string;
41
+ stage: string;
42
+ ok: boolean;
43
+ message: string;
44
+ }[];
45
+ }
46
+ export declare function coreTxnRoot(moxxyDir: string): string;
47
+ export declare function coreTxnDir(moxxyDir: string, txnId: string): string;
48
+ export declare function repoDir(moxxyDir: string): string;
49
+ export declare function writeCoreJournal(moxxyDir: string, j: CoreJournal): Promise<void>;
50
+ export declare function readCoreJournal(moxxyDir: string, txnId: string): Promise<CoreJournal>;
51
+ export declare function listCoreTxns(moxxyDir: string): Promise<ReadonlyArray<CoreJournal>>;
52
+ /**
53
+ * Count core-txn dirs whose `journal.json` is present but unparseable. A corrupt
54
+ * (or hand-edited / half-written) journal would silently VANISH from
55
+ * listCoreTxns — making the begin serialization guard fail OPEN and let a second
56
+ * concurrent core txn clobber the shared repoDir. The guard uses this to instead
57
+ * fail CLOSED. A missing journal.json (a dir mid-create) is NOT corruption and
58
+ * is ignored.
59
+ */
60
+ export declare function countCorruptCoreTxns(moxxyDir: string): Promise<number>;
61
+ export interface ProvisionResult {
62
+ readonly ok: boolean;
63
+ readonly message: string;
64
+ readonly repoDir: string;
65
+ }
66
+ /**
67
+ * Ensure a buildable clone exists at exactly `install.gitHead`. Clones on first
68
+ * use, otherwise fetches; always checks out the pinned commit and verifies HEAD
69
+ * matches — this is the integrity guarantee that the source equals the binary.
70
+ */
71
+ export declare function provisionWorkspace(opts: {
72
+ readonly moxxyDir: string;
73
+ readonly install: CoreInstallInfo;
74
+ readonly repoUrlOverride?: string;
75
+ }): Promise<ProvisionResult>;
76
+ /** Find the clone's package directory whose package.json `name` === pkgName. */
77
+ export declare function findRepoPkgDir(repo: string, pkgName: string): Promise<string | null>;
78
+ export interface CoreVerifyResult {
79
+ readonly ok: boolean;
80
+ readonly stages: ReadonlyArray<{
81
+ stage: string;
82
+ ok: boolean;
83
+ message: string;
84
+ }>;
85
+ readonly newDeps: ReadonlyArray<string>;
86
+ }
87
+ export declare function verifyCorePackages(repo: string, install: CoreInstallInfo, pkgNames: ReadonlyArray<string>): Promise<CoreVerifyResult>;
88
+ /** Runtime deps the patched clone declares that aren't present in the live install. */
89
+ export declare function detectNewDeps(repo: string, install: CoreInstallInfo, pkgNames: ReadonlyArray<string>): Promise<ReadonlyArray<string>>;
90
+ /**
91
+ * Swap each package's freshly-built `dist/` into the live install, keeping the
92
+ * previous dist as a snapshot for rollback. Renames are atomic on the same fs.
93
+ *
94
+ * Crash-atomicity across packages: a multi-package overlay must not leave the
95
+ * install with a NEW core dist but an OLD cli dist (a version-skewed, possibly
96
+ * non-bootable combo) if the process is killed mid-loop. So we work in phases:
97
+ * 1. validate every package + snapshot every old dist,
98
+ * 2. stage every new dist (`dist.new`) — nothing live is touched yet,
99
+ * 3. write a `pending.json` intent recording the full set + staged paths,
100
+ * 4. swap all dists in a tight loop, then write `applied.json`.
101
+ * If the process dies between 3 and the final `applied.json`, a leftover
102
+ * `pending.json` lets {@link reconcileOverlay} (run on boot) complete or undo
103
+ * the partial set instead of stranding a mixed core.
104
+ */
105
+ export declare function overlayPackages(opts: {
106
+ readonly repo: string;
107
+ readonly install: CoreInstallInfo;
108
+ readonly pkgNames: ReadonlyArray<string>;
109
+ readonly snapshotDir: string;
110
+ }): Promise<{
111
+ ok: boolean;
112
+ message: string;
113
+ applied: string[];
114
+ }>;
115
+ /**
116
+ * Reconcile an overlay that was interrupted between intent and completion. If a
117
+ * `pending.json` exists without a matching `applied.json`, the swap loop may
118
+ * have run partially (some live dists new, some old) and left orphaned
119
+ * `dist.new`/`dist.bak`. Restoring from the snapshot returns every package to
120
+ * its pre-overlay dist so the install is internally consistent again; the caller
121
+ * marks the txn rolled_back. No-op when the overlay completed cleanly.
122
+ */
123
+ export declare function reconcileOverlay(opts: {
124
+ readonly install: CoreInstallInfo;
125
+ readonly pkgNames: ReadonlyArray<string>;
126
+ readonly snapshotDir: string;
127
+ }): Promise<{
128
+ reconciled: boolean;
129
+ }>;
130
+ /** Reverse an overlay: restore each package's dist from the snapshot. */
131
+ export declare function restoreOverlay(opts: {
132
+ readonly install: CoreInstallInfo;
133
+ readonly pkgNames: ReadonlyArray<string>;
134
+ readonly snapshotDir: string;
135
+ }): Promise<void>;
136
+ /**
137
+ * Called early on every CLI boot. Reaching this point means the (possibly
138
+ * overlaid) core code imported successfully, so a cleanly-applied
139
+ * `staged_restart` txn is committed. The primary defense against a bad patch is
140
+ * the pre-overlay build+typecheck+test in verify; this adds two boot-time
141
+ * safety nets when an `install` is supplied:
142
+ * - reconcile an overlay interrupted mid-swap (partial dist set) by restoring
143
+ * the snapshot, and mark that txn rolled_back rather than committing a mixed
144
+ * core that merely imported far enough to reach this hook;
145
+ * - refuse to commit unless `applied.json` records every journal package, so an
146
+ * inconsistent overlay keeps its rollback snapshot instead of GC-ing it.
147
+ * Without `install` it stays best-effort (commits any staged txn) for callers
148
+ * that cannot resolve the live install.
149
+ */
150
+ export declare function finalizeStagedCoreUpdate(moxxyDir: string, install?: CoreInstallInfo | null, keepTerminal?: number): Promise<ReadonlyArray<string>>;
151
+ export declare function newCoreTxnId(now?: Date): string;
152
+ /**
153
+ * Prune old terminal core transactions. Each core txn parks a full pre-overlay
154
+ * `dist` snapshot of every patched package (tens of MB), and nothing else ever
155
+ * deletes them — left unbounded they accumulate on disk across every
156
+ * apply/rollback cycle. Keep only the most recent `keep` terminal
157
+ * (committed / rolled_back) txns; never touch a non-terminal one (an open /
158
+ * provisioned / verified / staged_restart txn whose snapshot finalize or a
159
+ * rollback may still need). Best-effort: a failed delete is ignored.
160
+ */
161
+ export declare function gcCoreTxns(moxxyDir: string, keep: number): Promise<void>;
162
+ /**
163
+ * Resolve a clone-relative path, refusing anything that escapes the repo —
164
+ * including via a symlink. `path.resolve` collapses literal `..`, but the clone
165
+ * is git-controlled and can contain symlinks, and core_write/core_edit follow
166
+ * them (fs.writeFile/readFile dereference), so a path that textually stays inside
167
+ * the repo but traverses a symlink could read or clobber files outside the clone
168
+ * (the live install, ~/.ssh, …). We therefore (1) keep the cheap textual gate,
169
+ * then (2) re-check against the realpath of the repo root and reject if any
170
+ * existing component of the target is a symlink.
171
+ */
172
+ export declare function safeRepoPath(repo: string, rel: string): string;
173
+ //# sourceMappingURL=core-update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-update.d.ts","sourceRoot":"","sources":["../src/core-update.ts"],"names":[],"mappings":"AAgCA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,GAAG,CACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAC3B,GAAG,EAAE,MAAM,EACX,SAAS,SAAmB,GAC3B,OAAO,CAAC,SAAS,CAAC,CAuBpB;AAuCD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAWD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAKzE;AAoDD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,OAAO,CAAC;QAAC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