@kirkchinese/harness-forge 0.4.0 → 0.5.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 (125) hide show
  1. package/README.md +4 -0
  2. package/docs/DETAIL.zh.md +47 -0
  3. package/lib/agents/presets.d.ts +7 -0
  4. package/lib/agents/presets.js +11 -1
  5. package/lib/agents/profiles.js +3 -2
  6. package/lib/agents/row.js +3 -1
  7. package/lib/client/paths.d.ts +12 -0
  8. package/lib/client/paths.js +68 -0
  9. package/lib/client/typert.d.ts +12 -1
  10. package/lib/client/typert.js +54 -6
  11. package/lib/client.js +1593 -270
  12. package/lib/commands/row.js +1 -1
  13. package/lib/context/instructions.js +5 -5
  14. package/lib/dsh/host.d.ts +3 -0
  15. package/lib/dsh/host.js +3 -0
  16. package/lib/forge/contract.d.ts +42 -2
  17. package/lib/forge/contract.js +3 -1
  18. package/lib/forge/follow.d.ts +30 -0
  19. package/lib/forge/follow.js +73 -0
  20. package/lib/forge/ledger.d.ts +70 -7
  21. package/lib/forge/ledger.js +314 -42
  22. package/lib/forge/projects.d.ts +5 -2
  23. package/lib/forge/projects.js +23 -16
  24. package/lib/forge/remote/archive.d.ts +65 -0
  25. package/lib/forge/remote/archive.js +565 -0
  26. package/lib/forge/remote/code-parts.d.ts +18 -0
  27. package/lib/forge/remote/code-parts.js +76 -0
  28. package/lib/forge/remote/fetch.d.ts +265 -0
  29. package/lib/forge/remote/fetch.js +1133 -0
  30. package/lib/forge/remote/service.d.ts +256 -0
  31. package/lib/forge/remote/service.js +868 -0
  32. package/lib/forge/service.d.ts +19 -9
  33. package/lib/forge/service.js +47 -31
  34. package/lib/forge/settings.d.ts +5 -3
  35. package/lib/forge/settings.js +11 -4
  36. package/lib/forge/state.d.ts +60 -0
  37. package/lib/forge/state.js +174 -58
  38. package/lib/hooks/broker/engine.js +2 -8
  39. package/lib/hooks/broker/session-events.d.ts +5 -0
  40. package/lib/hooks/broker/session-events.js +12 -3
  41. package/lib/hooks/broker/types.d.ts +7 -5
  42. package/lib/hooks/condition.d.ts +78 -2
  43. package/lib/hooks/condition.js +494 -73
  44. package/lib/hooks/config.d.ts +1 -1
  45. package/lib/hooks/config.js +4 -0
  46. package/lib/hooks/glob.d.ts +41 -0
  47. package/lib/hooks/glob.js +114 -0
  48. package/lib/hooks/permissions.d.ts +8 -3
  49. package/lib/hooks/permissions.js +119 -26
  50. package/lib/hooks/powershell-aliases.d.ts +19 -0
  51. package/lib/hooks/powershell-aliases.js +58 -0
  52. package/lib/hooks/process.d.ts +17 -0
  53. package/lib/hooks/process.js +156 -1
  54. package/lib/hooks/row.js +2 -0
  55. package/lib/hooks/runner.d.ts +17 -4
  56. package/lib/hooks/runner.js +42 -13
  57. package/lib/hooks/shell-commands.d.ts +10 -1
  58. package/lib/hooks/shell-commands.js +74 -10
  59. package/lib/hooks/shell.d.ts +3 -2
  60. package/lib/hooks/shell.js +5 -2
  61. package/lib/hooks/vocabulary.js +3 -1
  62. package/lib/mcp/catalog.d.ts +5 -2
  63. package/lib/mcp/catalog.js +18 -10
  64. package/lib/mcp/mount.d.ts +40 -2
  65. package/lib/mcp/mount.js +131 -31
  66. package/lib/mcp/policy.d.ts +42 -0
  67. package/lib/mcp/policy.js +43 -0
  68. package/lib/mcp/remote.js +5 -15
  69. package/lib/mcp/row.js +111 -17
  70. package/lib/mods/loader.js +4 -0
  71. package/lib/mods/service/turns.d.ts +8 -7
  72. package/lib/mods/service/turns.js +10 -35
  73. package/lib/opencode/bun.js +14 -2
  74. package/lib/opencode/row.d.ts +14 -1
  75. package/lib/opencode/row.js +38 -20
  76. package/lib/opencode/runtime/server.js +2 -1
  77. package/lib/porting/adapter-paths.d.ts +13 -0
  78. package/lib/porting/adapter-paths.js +120 -0
  79. package/lib/porting/port-gap.d.ts +10 -4
  80. package/lib/porting/port-gap.js +43 -7
  81. package/lib/porting/prompt.js +9 -7
  82. package/lib/porting/row.js +7 -5
  83. package/lib/porting/verify-port.d.ts +3 -10
  84. package/lib/porting/verify-port.js +12 -34
  85. package/lib/sessions/chat-import.d.ts +48 -0
  86. package/lib/sessions/chat-import.js +44 -0
  87. package/lib/sessions/claude.d.ts +16 -10
  88. package/lib/sessions/claude.js +76 -55
  89. package/lib/sessions/codex-discover.d.ts +34 -0
  90. package/lib/sessions/codex-discover.js +205 -0
  91. package/lib/sessions/codex-meta.d.ts +63 -0
  92. package/lib/sessions/codex-meta.js +148 -0
  93. package/lib/sessions/codex-text.d.ts +9 -0
  94. package/lib/sessions/codex-text.js +44 -0
  95. package/lib/sessions/codex.d.ts +34 -22
  96. package/lib/sessions/codex.js +150 -183
  97. package/lib/sessions/opencode.d.ts +15 -9
  98. package/lib/sessions/opencode.js +77 -58
  99. package/lib/sessions/persist.d.ts +162 -0
  100. package/lib/sessions/persist.js +377 -0
  101. package/lib/sessions/row.d.ts +2 -1
  102. package/lib/sessions/row.js +75 -9
  103. package/lib/sessions/turns.d.ts +31 -0
  104. package/lib/sessions/turns.js +63 -0
  105. package/lib/sessions/zstd.d.ts +15 -0
  106. package/lib/sessions/zstd.js +152 -0
  107. package/lib/shared/render.d.ts +30 -1
  108. package/lib/shared/render.js +813 -48
  109. package/lib/skills/provider.d.ts +2 -0
  110. package/lib/skills/provider.js +8 -2
  111. package/lib/skills/row.js +1 -1
  112. package/lib/workbench/adapter-coverage.d.ts +20 -2
  113. package/lib/workbench/adapter-coverage.js +46 -7
  114. package/lib/workbench/overview.d.ts +77 -27
  115. package/lib/workbench/overview.js +99 -12
  116. package/lib/workbench/remote.d.ts +64 -21
  117. package/lib/workbench/remote.js +181 -42
  118. package/lib/workbench/settings.d.ts +5 -1
  119. package/lib/workbench/settings.js +6 -2
  120. package/lib/workbench/workbench.d.ts +34 -4
  121. package/lib/workbench/workbench.js +147 -46
  122. package/locale/zh.json +2 -1
  123. package/package.json +3 -2
  124. package/lib/forge/marketplace-install.d.ts +0 -3
  125. package/lib/forge/marketplace-install.js +0 -64
@@ -122,7 +122,7 @@ export function startCommands(ctx, forge) {
122
122
  }));
123
123
  // A command registry that starts after this row retries the commands that needed it.
124
124
  parts.add('command registry', () => {
125
- const fiber = ctx.inject(['commands'], () => { forge.ledger.reapply(); });
125
+ const fiber = ctx.inject(['commands'], () => { forge.ledger.reapply('command'); });
126
126
  return () => fiber.dispose();
127
127
  });
128
128
  parts.add('api', () => forge.provide('commands', api));
@@ -36,8 +36,7 @@ export class ContextInstructions {
36
36
  }
37
37
  load(cwd) {
38
38
  const home = homedir();
39
- const { files, hostFiles } = loadInstructions({ cwd, home, codexHome: codexHome(home), hostLoads: HOST_LOADS, skipCodex: this.codexMounted() });
40
- return { files, hostFiles };
39
+ return loadInstructions({ cwd, home, codexHome: codexHome(home), hostLoads: HOST_LOADS, skipCodex: this.codexMounted() });
41
40
  }
42
41
  /** What the instructions of `cwd` are, for the workbench. */
43
42
  status(cwd) {
@@ -45,8 +44,8 @@ export class ContextInstructions {
45
44
  if (yielding !== undefined)
46
45
  return { active: false, yieldingTo: yielding, files: [] };
47
46
  const directory = cwd ?? dshService(this.ctx, 'workingDirectory')?.defaultDirectory ?? process.cwd();
48
- const { files, hostFiles } = this.load(directory);
49
- return { active: true, files: files.map(file => ({ path: file.path, bytes: file.bytes })), hostFiles };
47
+ const { files, hostFiles, stopped } = this.load(directory);
48
+ return { active: true, files: files.map(file => ({ path: file.path, bytes: file.bytes })), hostFiles, ...(stopped !== undefined ? { stopped } : {}) };
50
49
  }
51
50
  /** The prompt text for one assembly: empty while yielding, and when a failure keeps it from being read. */
52
51
  text(assembly) {
@@ -54,7 +53,8 @@ export class ContextInstructions {
54
53
  return '';
55
54
  const directory = this.directoryOf(assembly);
56
55
  try {
57
- return renderInstructions(this.load(directory).files, MAX_BYTES).text;
56
+ const { files, stopped } = this.load(directory);
57
+ return renderInstructions(files, MAX_BYTES, stopped).text;
58
58
  }
59
59
  catch (error) {
60
60
  // Once per directory: a step runs this again and again.
package/lib/dsh/host.d.ts CHANGED
@@ -21,6 +21,8 @@ export declare const DSH_SERVICES: {
21
21
  readonly approval: "@deepseek-ai/dsh-user-approval";
22
22
  readonly capabilityCatalog: "@kirkchinese/dsh-capability-catalog";
23
23
  readonly capabilityCatalogServers: "@kirkchinese/dsh-capability-catalog";
24
+ /** Not DSH's: dsh-chat-import's session import; Harness Forge yields its own to it. */
25
+ readonly chatImport: "dsh-chat-import";
24
26
  readonly commands: "@deepseek-ai/dsh-commands";
25
27
  readonly deepseekAccount: "@deepseek-ai/dsh-deepseek-account";
26
28
  readonly llm: "@deepseek-ai/dsh-llm";
@@ -41,6 +43,7 @@ export declare const DSH_SERVICES: {
41
43
  readonly userQuestions: "@deepseek-ai/dsh-user-questions";
42
44
  readonly webServer: "@deepseek-ai/dsh-host-webserver";
43
45
  readonly workingDirectory: "@deepseek-ai/dsh-working-directory";
46
+ readonly workspaceRegistry: "@deepseek-ai/dsh-workspace";
44
47
  };
45
48
  /** Events listened to with `ctx.on`, by the DSH package that declares them. */
46
49
  export declare const DSH_EVENTS: {
package/lib/dsh/host.js CHANGED
@@ -21,6 +21,8 @@ export const DSH_SERVICES = {
21
21
  approval: '@deepseek-ai/dsh-user-approval',
22
22
  capabilityCatalog: '@kirkchinese/dsh-capability-catalog',
23
23
  capabilityCatalogServers: '@kirkchinese/dsh-capability-catalog',
24
+ /** Not DSH's: dsh-chat-import's session import; Harness Forge yields its own to it. */
25
+ chatImport: 'dsh-chat-import',
24
26
  commands: '@deepseek-ai/dsh-commands',
25
27
  deepseekAccount: '@deepseek-ai/dsh-deepseek-account',
26
28
  llm: '@deepseek-ai/dsh-llm',
@@ -41,6 +43,7 @@ export const DSH_SERVICES = {
41
43
  userQuestions: '@deepseek-ai/dsh-user-questions',
42
44
  webServer: '@deepseek-ai/dsh-host-webserver',
43
45
  workingDirectory: '@deepseek-ai/dsh-working-directory',
46
+ workspaceRegistry: '@deepseek-ai/dsh-workspace',
44
47
  };
45
48
  /** Events listened to with `ctx.on`, by the DSH package that declares them. */
46
49
  export const DSH_EVENTS = {
@@ -13,6 +13,7 @@ import type { Context } from '@deepseek-ai/cordis';
13
13
  import type { ComponentOutcome, ForeignComponent, ForeignPlugin, Gap, PlanAction } from '@kirkchinese/harness-forge-core';
14
14
  import type { HookConfigSource } from '../hooks/config.js';
15
15
  import type { RemoteMcpHost } from '../mcp/mount.js';
16
+ import type { OpenedSession } from '../sessions/persist.js';
16
17
  /** What a row's start returns: its teardown. */
17
18
  export type Disposer = () => unknown;
18
19
  /**
@@ -160,6 +161,29 @@ export interface McpApi {
160
161
  startSignIn(serverName: string, sessionId?: string): string;
161
162
  /** The remote-MCP host a component's servers use: its sign-in state becomes the component's evidence. */
162
163
  remoteHost(componentId: string, scope?: MountScope): RemoteMcpHost;
164
+ /**
165
+ * A server's own filters and approval modes for one call (`mcp__<server>__<tool>`, or `capability_call` with
166
+ * `mcp:<server>/<tool>`): `deny` for a tool filtered out, `ask` for one that needs approval, undefined otherwise.
167
+ * The one decision the row's pre-execute check and hook-initiated calls both use.
168
+ */
169
+ toolPolicy(call: McpToolCall): McpToolVerdict | undefined;
170
+ /**
171
+ * The registered name of the server an `mcp_tool` hook of plugin `pluginId` names: among that plugin's own
172
+ * servers by the name it declared them under (`plugin:<plugin>:<server>`: among that plugin's), else among the
173
+ * user's own servers (config.toml, the user `.mcp.json`); the session's own first. Undefined when none is mounted.
174
+ */
175
+ hookServer(pluginId: string, server: string, sessionId?: string): string | undefined;
176
+ }
177
+ /** A tool call as the MCP tool policy reads it. */
178
+ export interface McpToolCall {
179
+ readonly name: string;
180
+ readonly arguments?: unknown;
181
+ readonly agent?: unknown;
182
+ }
183
+ /** What a server's tool policy says about one call. */
184
+ export interface McpToolVerdict {
185
+ readonly kind: 'deny' | 'ask';
186
+ readonly reason: string;
163
187
  }
164
188
  /** What the mods row offers. */
165
189
  export interface ModsApi {
@@ -170,12 +194,26 @@ export interface ModsApi {
170
194
  }
171
195
  /** A harness whose sessions can be imported. */
172
196
  export type SessionSource = 'claude-code' | 'codex' | 'opencode';
197
+ /** Sessions per page when the caller names no limit. */
198
+ export declare const SESSION_PAGE_SIZE = 50;
199
+ /** Which page of a harness's sessions to read: `cursor` is the `next` of the previous page. */
200
+ export interface SessionPageRequest {
201
+ readonly cursor?: number;
202
+ readonly limit?: number;
203
+ }
204
+ /** One page of sessions, newest first; `next` is the cursor of the following page, absent on the last. */
205
+ export interface SessionPage<T = unknown> {
206
+ readonly sessions: readonly T[];
207
+ readonly next?: number;
208
+ }
173
209
  /** What the sessions row offers. */
174
210
  export interface SessionsApi {
175
- /** The sessions of one harness available for import. */
176
- sessions(root: string | undefined, source: SessionSource): Promise<readonly unknown[]>;
211
+ /** One page of the sessions of one harness available for import, newest first; each says which DSH session already holds it (`importedId`). */
212
+ sessions(root: string | undefined, source: SessionSource, page?: SessionPageRequest): Promise<SessionPage>;
177
213
  /** Import one session into DSH. */
178
214
  importSession(path: string, targetId: string | undefined, source: SessionSource, sourceId: string | undefined): Promise<unknown>;
215
+ /** Open a session an import stored: known to DSH again (workspace, live) and out of its archive. */
216
+ open(id: string): Promise<OpenedSession>;
179
217
  }
180
218
  /** What the instruction files of a workspace are, for the workbench. */
181
219
  export interface ContextStatus {
@@ -193,6 +231,8 @@ export interface ContextStatus {
193
231
  readonly path: string;
194
232
  readonly bytes: number;
195
233
  }[];
234
+ /** Set when reading stopped at a limit: why, and where. */
235
+ readonly stopped?: string;
196
236
  }
197
237
  /** What the context row offers. */
198
238
  export interface ContextApi {
@@ -12,12 +12,14 @@ export const ROW_OF_KIND = {
12
12
  'opencode-plugin': 'opencode',
13
13
  'settings': 'harness-forge',
14
14
  };
15
+ /** Sessions per page when the caller names no limit. */
16
+ export const SESSION_PAGE_SIZE = 50;
15
17
  /** A plugin component's planned action, as the kind of mount it needs; `undefined` when DSH has nothing for it. */
16
18
  export function mountKindOf(action, component) {
17
19
  switch (action.kind) {
18
20
  case 'link-skill-root': return 'skill';
19
21
  case 'register-command': return 'command';
20
- case 'mount-mcp': return 'mcp';
22
+ case 'mount-mcp': return component.kind === 'mcp' && component.notStarted !== undefined ? { skipped: component.notStarted.detail } : 'mcp';
21
23
  case 'mount-hooks': return 'hooks';
22
24
  case 'register-agent': return 'agent';
23
25
  case 'apply-settings': return 'settings';
@@ -0,0 +1,30 @@
1
+ import { type HarnessInstalls } from '@kirkchinese/harness-forge-core';
2
+ import type { DetachedReason, HarnessInstallRecord, InstalledPluginRecord } from './state.js';
3
+ /** What following a plugin's harness asks of it now. */
4
+ export type Following =
5
+ /** No harness install to follow, or its harness cannot tell. */
6
+ {
7
+ readonly kind: 'none';
8
+ }
9
+ /** The harness runs it from the recorded folder; `identity` is the install as seen now. */
10
+ | {
11
+ readonly kind: 'current';
12
+ readonly identity: HarnessInstallRecord;
13
+ }
14
+ /** The harness updated it into another folder. */
15
+ | {
16
+ readonly kind: 'moved';
17
+ readonly identity: HarnessInstallRecord;
18
+ readonly root: string;
19
+ } | {
20
+ readonly kind: 'detached';
21
+ readonly reason: DetachedReason;
22
+ };
23
+ /** What the person's record says it follows, learnt from its folder when the record predates install keys. */
24
+ export declare function withHarnessInstall(record: InstalledPluginRecord, current: HarnessInstalls, home?: string): InstalledPluginRecord;
25
+ /** The harness install a plugin newly migrated from `root` follows: only one its harness lists there. */
26
+ export declare function newHarnessInstall(root: string, name: string, source: string, current: HarnessInstalls, home?: string): HarnessInstallRecord | undefined;
27
+ /** What following the record's harness install asks of it (see the module table). */
28
+ export declare function followingOf(record: InstalledPluginRecord, current: HarnessInstalls): Following;
29
+ /** Whether following asks anything of the record: a move, a new detachment, or a detachment or identity to clear. */
30
+ export declare function followingChanges(record: InstalledPluginRecord, following: Following): boolean;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * How a migrated plugin follows the harness that installed it. Claude Code
3
+ * and Codex put each version of a plugin in a folder of its own and may delete
4
+ * the old one; the ledger records the folder it migrated. Its harness install
5
+ * (`HarnessInstallRecord`) is matched against what the harness lists now:
6
+ *
7
+ * | The harness lists it | Then |
8
+ * | --- | --- |
9
+ * | at the same folder | nothing to do (a plugin that was detached is applied again) |
10
+ * | at another folder | the plugin moves there, keeping the parts the person switched off |
11
+ * | not at all, or switched off | detached: nothing of it runs until the person removes or keeps it |
12
+ *
13
+ * A harness whose record cannot be read in full (malformed, or cut off while
14
+ * the harness writes it) proves nothing by leaving a plugin out, nor does one
15
+ * that records the plugin at a folder that is not there: nothing changes, and
16
+ * the next read decides.
17
+ * @module @kirkchinese/harness-forge
18
+ */
19
+ import { resolve } from 'node:path';
20
+ import { identifyHarnessInstall } from '@kirkchinese/harness-forge-core';
21
+ /** What the person's record says it follows, learnt from its folder when the record predates install keys. */
22
+ export function withHarnessInstall(record, current, home) {
23
+ if (record.harnessInstall !== undefined || record.keptAt !== undefined)
24
+ return record;
25
+ const identity = identifyHarnessInstall(record.root, record.displayName ?? record.name, current, home);
26
+ return identity === undefined ? record : { ...record, harnessInstall: identity };
27
+ }
28
+ /** The harness install a plugin newly migrated from `root` follows: only one its harness lists there. */
29
+ export function newHarnessInstall(root, name, source, current, home) {
30
+ const identity = identifyHarnessInstall(root, name, current, home);
31
+ if (identity === undefined || identity.inferred === true || identity.harness !== source)
32
+ return undefined;
33
+ const install = current.installs.find(item => item.harness === identity.harness && item.key === identity.key);
34
+ // Migrated while off in its harness: the person chose it, so the harness switching it off does not stop it.
35
+ return { harness: identity.harness, key: identity.key, ...(install?.enabled === false ? { enabled: false } : {}) };
36
+ }
37
+ /** What following the record's harness install asks of it (see the module table). */
38
+ export function followingOf(record, current) {
39
+ const identity = record.harnessInstall;
40
+ if (identity === undefined || record.keptAt !== undefined)
41
+ return { kind: 'none' };
42
+ const install = current.installs.find(item => item.harness === identity.harness && item.key === identity.key);
43
+ if (install === undefined) {
44
+ // Absent only proves it is gone from a complete read, and from it entirely: not one whose files are missing now.
45
+ if (current.uncertain.has(identity.harness))
46
+ return { kind: 'none' };
47
+ if (current.unresolved.some(item => item.harness === identity.harness && item.key === identity.key))
48
+ return { kind: 'none' };
49
+ return { kind: 'detached', reason: identity.inferred === true ? 'never-installed' : 'uninstalled' };
50
+ }
51
+ // An earlier Harness Forge read this harness's install through another dialect: it is not the plugin the harness runs.
52
+ if (record.source !== identity.harness)
53
+ return { kind: 'detached', reason: 'misread' };
54
+ if (install.enabled === false && identity.enabled !== false)
55
+ return { kind: 'detached', reason: 'switched-off' };
56
+ const seen = { harness: identity.harness, key: identity.key, ...(install.enabled === false ? { enabled: false } : {}) };
57
+ return samePath(install.root, record.root) ? { kind: 'current', identity: seen } : { kind: 'moved', identity: seen, root: install.root };
58
+ }
59
+ /** Whether following asks anything of the record: a move, a new detachment, or a detachment or identity to clear. */
60
+ export function followingChanges(record, following) {
61
+ switch (following.kind) {
62
+ case 'none': return false;
63
+ case 'moved': return true;
64
+ case 'detached': return record.detached?.reason !== following.reason;
65
+ case 'current': return record.detached !== undefined || !sameIdentity(record.harnessInstall, following.identity);
66
+ }
67
+ }
68
+ function sameIdentity(a, b) {
69
+ return a !== undefined && a.harness === b.harness && a.key === b.key && a.inferred === b.inferred && a.enabled === b.enabled;
70
+ }
71
+ function samePath(a, b) {
72
+ return process.platform === 'win32' ? resolve(a).toLowerCase() === resolve(b).toLowerCase() : resolve(a) === resolve(b);
73
+ }
@@ -58,6 +58,15 @@ export declare function switchedOff(componentId: string): ComponentOutcome;
58
58
  export declare function failedToSwitchOff(componentId: string, reason: string): ComponentOutcome;
59
59
  /** The outcome of a component a failed install could not withdraw: it stays live until removing the plugin (or installing it again) withdraws it. */
60
60
  export declare function failedToCleanUp(componentId: string, reason: string): ComponentOutcome;
61
+ /** What an outcome's message says when the plugin's harness no longer runs it (see `follow.ts`). */
62
+ export declare const NOT_FOLLOWED = "not run: its harness no longer runs this plugin";
63
+ /** The outcome of a component of a detached plugin: off until the person removes or keeps the plugin. */
64
+ export declare function notFollowed(componentId: string): ComponentOutcome;
65
+ /** How far applying the ledger's records has got: every record at startup, those a harness changed later. */
66
+ export interface ApplyProgress {
67
+ readonly done: number;
68
+ readonly total: number;
69
+ }
61
70
  /**
62
71
  * The installations: the in-memory registry, plan application, undo and
63
72
  * teardown, runtime evidence and the durable ledger, every mutation through
@@ -67,7 +76,7 @@ export declare class Ledger {
67
76
  readonly ctx: Context;
68
77
  readonly statePath: string;
69
78
  readonly dataRoot: string;
70
- /** Where a withdrawal that failed is recorded (the shared service's faults). */
79
+ /** Where a withdrawal that failed, or a ledger read only in part, is recorded (the shared service's faults). */
71
80
  private readonly fault?;
72
81
  readonly live: Map<string, LiveInstall>;
73
82
  readonly plans: Map<string, Plan>;
@@ -75,10 +84,16 @@ export declare class Ledger {
75
84
  disposed: boolean;
76
85
  queue: Promise<unknown>;
77
86
  persistTimer: NodeJS.Timeout | undefined;
78
- /** Why the ledger could not be read at startup; while set, it is never written. */
79
- private unreadLedger;
87
+ /** Records being applied (restored at startup, or followed to their harness's change) and how many are done. */
88
+ private progress;
89
+ /** The last unreadable-record problem reported per harness, so each is said once, not at every page load. */
90
+ private readonly unreadReported;
91
+ /** The follow pass queued and not yet run: another request joins it instead of queueing its own. */
92
+ private following;
93
+ /** Why the ledger may not be written (unreadable at startup, or a newer Harness Forge's); while set, it never is. */
94
+ private writeRefusal;
80
95
  constructor(ctx: Context, statePath: string, dataRoot: string,
81
- /** Where a withdrawal that failed is recorded (the shared service's faults). */
96
+ /** Where a withdrawal that failed, or a ledger read only in part, is recorded (the shared service's faults). */
82
97
  fault?: ((error: unknown) => void) | undefined);
83
98
  private readonly faultOf;
84
99
  /**
@@ -88,9 +103,11 @@ export declare class Ledger {
88
103
  registerMounter(kind: MountKind, mounter: Mounter): () => void;
89
104
  /**
90
105
  * Re-apply installed plans; only actions without a live registration run.
91
- * Called when a mounter appears.
106
+ * Called when a mounter appears: with its kind, only that kind's actions
107
+ * mount, so a part that failed (a server that cannot start) is tried again
108
+ * when its own row comes back, not once for every row that starts at boot.
92
109
  */
93
- reapply(): void;
110
+ reapply(kind?: MountKind): void;
94
111
  /**
95
112
  * Withdraw every mount of one kind (its row went away): those components
96
113
  * wait as inactive. The live registrations say what to withdraw, so a source
@@ -110,10 +127,46 @@ export declare class Ledger {
110
127
  list(): readonly InstalledPluginRecord[];
111
128
  exclusive<T>(operation: () => Promise<T>): Promise<T>;
112
129
  restoreNow(): Promise<void>;
130
+ /** Restore one record, following its harness: to the folder of a new version, or detached when no longer run. */
131
+ private restoreRecord;
113
132
  /** Keep a record that could not be restored visible, with the reason. */
114
133
  private keepUnrestored;
134
+ /** Keep a record its harness no longer runs listed, nothing of it mounted. */
135
+ private keepDetached;
136
+ /** Detach a live plugin its harness no longer runs: its registrations are withdrawn, the record kept. */
137
+ private detachNow;
138
+ /**
139
+ * Move a followed plugin to the folder its harness now runs (an update), as Get plugins' Update moves a fetched
140
+ * one (see {@link rerootNow}): the parts the person switched off stay off, and the move is noted on the record.
141
+ */
142
+ private moveNow;
143
+ /**
144
+ * Follow every harness's changes since the last pass (see `follow.ts`). Queued behind the ledger's other work;
145
+ * nothing is queued when no record needs anything, and a pass already waiting is joined. Settles when it has run.
146
+ */
147
+ follow(): Promise<void>;
148
+ /**
149
+ * What every harness has installed now. A harness whose record could not be read in full, while plugins migrated
150
+ * from it follow it, is reported once per distinct problem: nothing of those plugins changes until it reads whole.
151
+ */
152
+ private readHarnesses;
153
+ /** Follow one live plugin's harness install. */
154
+ private followOne;
155
+ /**
156
+ * Keep a plugin its harness no longer runs as the person's own copy, in the folder it is in: it follows no harness
157
+ * any more and its parts mount again.
158
+ */
159
+ keepNow(id: string): Promise<ApplyResult>;
160
+ /** How far applying records has got, while any are still being applied. */
161
+ applying(): ApplyProgress | undefined;
162
+ private begin;
163
+ private step;
115
164
  planNow(root: string, source?: string): Plan;
116
- applyNow(plan: Plan): Promise<ApplyResult>;
165
+ /**
166
+ * Apply a plan: every action without a live registration mounts.
167
+ * @param only - mount only this kind's actions; the others keep their outcome.
168
+ */
169
+ applyNow(plan: Plan, only?: MountKind): Promise<ApplyResult>;
117
170
  undoNow(receiptId: string): Promise<boolean>;
118
171
  /**
119
172
  * Switch one component of an installed plugin off (its registrations are
@@ -121,6 +174,14 @@ export declare class Ledger {
121
174
  * install). Returns whether anything changed.
122
175
  */
123
176
  setEnabledNow(pluginId: string, componentId: string, enabled: boolean): Promise<boolean>;
177
+ /**
178
+ * Move an installed plugin to a new copy of its source (an update fetched
179
+ * into a directory of its own): its registrations are withdrawn and the new
180
+ * copy applied under the same id, keeping the parts the person switched off,
181
+ * its install time and its receipts. When the new copy does not apply, the
182
+ * old one is applied again and the failure is thrown.
183
+ */
184
+ rerootNow(id: string, root: string, source?: string): Promise<ApplyResult>;
124
185
  /** Release one installation without deciding whether the ledger survives. */
125
186
  teardown(id: string): Promise<boolean>;
126
187
  /** Record one runtime observation; the component's status follows its evidence. */
@@ -129,6 +190,8 @@ export declare class Ledger {
129
190
  }): void;
130
191
  scanRoot(root: string, source?: string): ForeignPlugin;
131
192
  private buildRecord;
193
+ /** What a record follows: kept from its earlier record, else the harness install it was migrated from, if any. */
194
+ private followed;
132
195
  report(result: ApplyResult): InstallReport;
133
196
  allCommandNames(excludePluginId?: string): Set<string>;
134
197
  private assertAlive;