@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
@@ -4,15 +4,36 @@
4
4
  * no state; the workbench row and the `/harness` command both read through it.
5
5
  * @module @kirkchinese/harness-forge
6
6
  */
7
+ import { existsSync, readFileSync } from 'node:fs';
7
8
  import { createRequire } from 'node:module';
8
- import { resolve } from 'node:path';
9
- import { assess, discoverPlugins, pluginId } from '@kirkchinese/harness-forge-core';
10
- import { itemOf, overviewOf, unreadableItemOf } from './overview.js';
9
+ import { homedir } from 'node:os';
10
+ import { dirname, join, relative, resolve, isAbsolute } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { assess, claudeSettingsStatusLine, claudeStatusLineProvider, discoverPlugins, pluginId } from '@kirkchinese/harness-forge-core';
13
+ import { followedItemOf, itemOf, migratable, overviewOf, qualifyDuplicateNames, unreadableItemOf } from './overview.js';
11
14
  import { adapterCoverage, enabledAdapters } from './adapter-coverage.js';
12
15
  import { readSettings, writeSettings } from './settings.js';
13
16
  import { messageOf } from '../shared/util.js';
14
17
  import { dshService } from '../dsh/host.js';
15
18
  import { findBun } from '../opencode/bun.js';
19
+ /**
20
+ * Harness Forge's own version, from its package.json: the nearest one up
21
+ * from this module (`lib/workbench/` when built, `src/workbench/` in tests).
22
+ */
23
+ export function forgeVersion(from = fileURLToPath(import.meta.url)) {
24
+ for (let dir = dirname(from);; dir = dirname(dir)) {
25
+ try {
26
+ const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
27
+ if (manifest.name === '@kirkchinese/harness-forge' && typeof manifest.version === 'string')
28
+ return manifest.version;
29
+ }
30
+ catch {
31
+ // No package.json here: look one folder up.
32
+ }
33
+ if (dirname(dir) === dir)
34
+ return undefined;
35
+ }
36
+ }
16
37
  /** A package's version as this process resolves it, if it resolves. */
17
38
  function versionOf(specifier) {
18
39
  try {
@@ -74,40 +95,60 @@ export class Workbench {
74
95
  * an installed plugin's recorded ones, else those its scan shows.
75
96
  */
76
97
  findPlugin(id) {
77
- const record = this.installs.list().find(item => item.id === id);
78
- if (record !== undefined) {
79
- const plugin = this.installs.scan(record.root, record.source);
80
- return { plugin, gaps: record.compat?.gaps ?? assess(plugin).gaps };
81
- }
82
- // The overview lists a discovered plugin under its scanned id; the discovered name is only a hint.
83
- const found = this.discover().plugins.filter(item => !item.installed);
84
- for (const item of [...found.filter(item => pluginId(item.source, item.name) === id), ...found.filter(item => pluginId(item.source, item.name) !== id)]) {
85
- let plugin;
86
- try {
87
- plugin = this.installs.scan(item.root, item.source);
98
+ const { scanned, link } = this.overviewSources(id);
99
+ const found = scanned.find(({ plugin }) => plugin.id === id);
100
+ if (found !== undefined) {
101
+ const { plugin, record } = found;
102
+ const gaps = record?.compat?.gaps ?? assess(plugin).gaps;
103
+ if (link !== undefined && plugin.components.some(part => part.id === link.settingsId)) {
104
+ return { plugin: { ...plugin, components: plugin.components.filter(part => part.id !== link.settingsId) }, gaps: gaps.filter(gap => gap.componentId !== link.settingsId) };
88
105
  }
89
- catch {
90
- continue;
91
- }
92
- if (plugin.id === id)
93
- return { plugin, gaps: assess(plugin).gaps };
106
+ return { plugin, gaps };
94
107
  }
95
108
  throw new Error(`no plugin ${id} is installed or discovered`);
96
109
  }
97
- /** Discover plugin roots using the saved settings. */
110
+ /**
111
+ * Discover plugin roots using the saved settings: the plugins each harness
112
+ * installed and the person's own assets, never what a marketplace only offers.
113
+ */
98
114
  discover() {
99
115
  const settings = this.settings();
100
116
  const result = discoverPlugins(settings.discoveryRoots);
101
- const installedRoots = new Set([...this.installs.live.values()].map(install => resolve(install.record.root)));
102
117
  return {
103
118
  settings,
104
- plugins: result.plugins.map(plugin => ({
105
- ...plugin,
106
- installed: installedRoots.has(resolve(plugin.root)) || this.installs.live.has(pluginId(plugin.source, plugin.name)),
107
- })),
119
+ plugins: result.plugins.map(plugin => ({ ...plugin, installed: this.migrated(plugin) })),
120
+ marketplaces: result.marketplaces,
108
121
  missingRoots: result.missingRoots,
122
+ warnings: result.warnings,
109
123
  };
110
124
  }
125
+ /**
126
+ * Whether a discovered plugin is migrated already. A record that follows a harness install counts for that install
127
+ * only, wherever either's folder is (an update moves it to the harness's new folder); one of an install the harness
128
+ * no longer runs, or of one read through another harness, never makes a current install look migrated. A record
129
+ * that follows no harness counts by its folder, and (unless the person kept it as their own copy) by its id.
130
+ */
131
+ migrated(plugin) {
132
+ for (const { record, unrecorded } of this.installs.live.values()) {
133
+ if (unrecorded === true)
134
+ continue;
135
+ const followed = record.harnessInstall;
136
+ if (followed !== undefined) {
137
+ if (record.keptAt === undefined && plugin.installKey !== undefined && followed.harness === plugin.source && followed.key === plugin.installKey && record.source === plugin.source)
138
+ return true;
139
+ continue;
140
+ }
141
+ if (resolve(record.root) === resolve(plugin.root))
142
+ return true;
143
+ if (record.keptAt === undefined && record.id === pluginId(plugin.source, plugin.name))
144
+ return true;
145
+ }
146
+ return false;
147
+ }
148
+ /** The local marketplaces the harnesses added: under "Get plugins", each plugin installed on its own after the confirmation. */
149
+ localMarketplaces() {
150
+ return discoverPlugins(this.settings().discoveryRoots).marketplaces.map(market => ({ input: market.root, name: market.name, harness: market.source }));
151
+ }
111
152
  /** Aggregate capabilities and context cost for installed plugins. */
112
153
  capabilities() {
113
154
  const settings = this.settings();
@@ -132,7 +173,7 @@ export class Workbench {
132
173
  const description = 'description' in component ? component.description : undefined;
133
174
  return {
134
175
  pluginId: plugin.id,
135
- pluginName: plugin.name,
176
+ pluginName: plugin.displayName ?? plugin.name,
136
177
  kind: component.kind,
137
178
  name: component.name,
138
179
  ...(description !== undefined ? { description } : {}),
@@ -145,7 +186,7 @@ export class Workbench {
145
186
  ? sum + estimate(`${item.name}\n${item.description ?? ''}`)
146
187
  : sum), 0);
147
188
  residentTokens += measured;
148
- plugins.push({ pluginId: plugin.id, name: plugin.name, source: plugin.source, items, compat, residentTokens: measured });
189
+ plugins.push({ pluginId: plugin.id, name: plugin.displayName ?? plugin.name, source: plugin.source, items, compat, residentTokens: measured });
149
190
  }
150
191
  const budgetTokens = settings.contextBudgetTokens;
151
192
  const tools = dshService(this.installs.ctx, 'tools');
@@ -187,52 +228,109 @@ export class Workbench {
187
228
  enabledAdapters() {
188
229
  return enabledAdapters(this.adapters(), dshService(this.forge.ctx, 'pluginManager'));
189
230
  }
190
- /** The workbench's plain-language view of every harness: see `overview.ts`. */
191
- async overview() {
192
- const adapters = await this.enabledAdapters();
193
- const items = [];
194
- const seen = new Set();
231
+ /** Scan the roots the overview lists, and attribute the user's configured status line. */
232
+ overviewSources(requiredId) {
233
+ const scanned = [];
234
+ const unreadable = [];
195
235
  for (const record of this.installs.list()) {
196
- seen.add(resolve(record.root).toLowerCase());
236
+ if (!existsSync(record.root)) {
237
+ // Its folder is gone (the harness deleted an old version, say): a fault, never a plugin ready with no parts.
238
+ if (record.id === requiredId)
239
+ throw new Error(`the plugin's folder is gone: ${record.root}`);
240
+ unreadable.push(unreadableItemOf(record, record.root, 'folder-gone'));
241
+ continue;
242
+ }
197
243
  try {
198
- items.push(itemOf(this.installs.scan(record.root, record.source), record, adapters));
244
+ scanned.push({ plugin: this.installs.scan(record.root, record.source), record });
199
245
  }
200
246
  catch (error) {
247
+ if (record.id === requiredId)
248
+ throw error;
201
249
  // Its files are gone or unreadable: it stays listed, every part an error, with why.
202
- items.push(unreadableItemOf(record, messageOf(error)));
250
+ unreadable.push(unreadableItemOf(record, messageOf(error)));
203
251
  }
204
252
  }
205
253
  for (const found of this.discover().plugins) {
206
- if (found.installed || seen.has(resolve(found.root).toLowerCase()))
254
+ if (found.installed)
207
255
  continue;
208
256
  try {
209
- items.push(itemOf(this.installs.scan(found.root, found.source), undefined, adapters));
257
+ scanned.push({
258
+ plugin: this.installs.scan(found.root, found.source),
259
+ ...(found.enabled !== undefined ? { enabled: found.enabled } : {}),
260
+ ...(found.enabledUnknown !== undefined ? { enabledUnknown: found.enabledUnknown } : {}),
261
+ });
210
262
  }
211
263
  catch {
212
264
  // An unreadable root has nothing to show.
213
265
  }
214
266
  }
215
- return overviewOf(items);
267
+ const settings = scanned.map(({ plugin }) => claudeSettingsStatusLine(plugin)).find(item => item !== undefined);
268
+ const provider = settings === undefined ? undefined : claudeStatusLineProvider(settings.command, scanned.map(({ plugin }) => plugin), homedir());
269
+ if (provider === undefined || settings === undefined)
270
+ return { scanned, unreadable };
271
+ const source = scanned.find(item => item.plugin === provider.plugin);
272
+ if (!source.plugin.components.some(part => part.id === provider.component.id)) {
273
+ source.plugin = { ...source.plugin, components: [...source.plugin.components, provider.component] };
274
+ if (source.record?.compat !== undefined) {
275
+ const gap = assess(source.plugin).gaps.find(item => item.componentId === provider.component.id);
276
+ if (gap !== undefined)
277
+ source.record = { ...source.record, compat: { ...source.record.compat, gaps: [...source.record.compat.gaps, gap] } };
278
+ }
279
+ }
280
+ return { scanned, unreadable, link: { settingsId: settings.component.id, providerId: provider.component.id, name: provider.plugin.name } };
281
+ }
282
+ /** Whether an installed plugin was fetched from the network: its files are in Harness Forge's own download folders. */
283
+ fetched(root) {
284
+ const dataRoot = this.installs.dataRoot;
285
+ if (dataRoot === undefined)
286
+ return false;
287
+ // `marketplace-cache` held the clones of the retired one-step marketplace install; plugins installed from it before 0.4.1 still live there.
288
+ return [join(dataRoot, 'remote'), join(dataRoot, 'marketplace-cache')].some((dir) => {
289
+ const path = relative(resolve(dir), resolve(root));
290
+ return path.length > 0 && !path.startsWith('..') && !isAbsolute(path);
291
+ });
292
+ }
293
+ /** The workbench's plain-language view of every harness: see `overview.ts`. */
294
+ async overview() {
295
+ const adapters = await this.enabledAdapters();
296
+ const { scanned, unreadable, link } = this.overviewSources();
297
+ const items = scanned.map(({ plugin, record, enabled, enabledUnknown }) => {
298
+ const item = itemOf(plugin, record, adapters);
299
+ if (item.installed)
300
+ return item;
301
+ return enabled === false ? { ...item, enabled: false } : enabledUnknown !== undefined ? { ...item, enabledUnknown } : item;
302
+ });
303
+ const marked = [...items, ...unreadable].map((item) => {
304
+ if (!item.installed)
305
+ return item;
306
+ const followed = followedItemOf(item, this.installs.live.get(item.id)?.record, !existsSync(item.root));
307
+ return this.fetched(item.root) ? { ...followed, fetched: true } : followed;
308
+ });
309
+ return overviewOf(qualifyDuplicateNames(marked), link);
216
310
  }
217
311
  /** Read-only workbench diagnostics: host services, mounts, tool budget and row failures. */
218
312
  diagnostics() {
219
313
  const catalog = this.capabilities();
314
+ const faults = this.forge.faults();
315
+ const failedMounts = this.installs.list().flatMap(plugin => (plugin.mounts ?? [])
316
+ .filter(mount => mount.status === 'failed')
317
+ .map(mount => ({ pluginId: plugin.id, plugin: plugin.displayName ?? plugin.name, kind: mount.kind, name: mount.name, ...(mount.events !== undefined ? { events: mount.events } : {}), error: mount.error ?? '' })));
220
318
  return {
319
+ // What the page says first: Harness Forge's own parts (rows) and the migrated parts are counted apart.
320
+ summary: { ok: faults.length === 0 && failedMounts.length === 0, faults: faults.length, failedMounts: failedMounts.length },
221
321
  host: this.hostCapabilities(),
222
322
  hookShell: { bash: this.forge.shell.bash ?? null, powershell: this.forge.shell.powershell, default: this.forge.shell.defaultKind },
223
323
  bun: findBun(this.installs.dataRoot) ?? null,
224
324
  versions: {
225
- forge: versionOf('../package.json') ?? null,
325
+ forge: forgeVersion() ?? null,
226
326
  dsh: versionOf('@deepseek-ai/dsh-session/package.json') ?? null,
227
327
  node: process.versions.node,
228
328
  },
229
329
  platform: process.platform,
230
- faults: this.forge.faults(),
330
+ faults,
231
331
  tools: { count: catalog.toolCount ?? 0, tokens: catalog.toolTokens ?? 0, residentTokens: catalog.residentTokens },
232
332
  skillRoots: this.listSkillRoots(),
233
- failedMounts: this.installs.list().flatMap(plugin => (plugin.mounts ?? [])
234
- .filter(mount => mount.status === 'failed')
235
- .map(mount => ({ pluginId: plugin.id, kind: mount.kind, name: mount.name, error: mount.error ?? '' }))),
333
+ failedMounts,
236
334
  plugins: this.installs.list().map(plugin => ({ id: plugin.id, source: plugin.source, root: plugin.root, installedAt: plugin.installedAt })),
237
335
  statePath: this.installs.statePath,
238
336
  dataRoot: this.installs.dataRoot,
@@ -242,14 +340,17 @@ export class Workbench {
242
340
  listSkillRoots() {
243
341
  return this.forge.lookup('skills')?.roots() ?? [];
244
342
  }
245
- /** Migrate everything of one harness that is not migrated yet: its plugins and the person's own assets. */
343
+ /**
344
+ * "Migrate all" of one harness: its plugins and the person's own assets that {@link migratable} takes, the
345
+ * rule the overview counts by. A plugin switched off in its harness stays where it is; it can be migrated alone.
346
+ */
246
347
  async migrate(source) {
247
348
  const installed = [];
248
349
  const failed = [];
249
- for (const found of this.discover().plugins.filter(item => item.source === source && !item.installed)) {
350
+ for (const found of this.discover().plugins.filter(item => item.source === source && migratable(item))) {
250
351
  try {
251
352
  const report = await this.forge.install(found.root, found.source);
252
- installed.push(report.plugin.name);
353
+ installed.push(report.plugin.displayName ?? report.plugin.name);
253
354
  }
254
355
  catch (error) {
255
356
  failed.push({ name: found.name, error: messageOf(error) });
package/locale/zh.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Harness Forge",
4
- "description": "在 DSH 中使用 Claude Code、Codex 和 OpenCode 的插件、设置与会话。在侧边栏打开 Harness Forge,即可查看这台电脑上找到的内容并迁移。其他 Harness Forge 行各自运行一类部分,可以单独关闭。"
4
+ "description": "在 DSH 中使用 Claude Code、Codex 和 OpenCode 的插件、设置与会话。在侧边栏打开 Harness Forge,即可查看这台电脑上找到的内容并迁移。其他 Harness Forge 行各自运行一类部分,可以单独关闭。",
5
+ "detail": "docs/DETAIL.zh.md"
5
6
  }
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirkchinese/harness-forge",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Use Claude Code, Codex and OpenCode plugins, settings and sessions in DSH",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -98,6 +98,7 @@
98
98
  "locale",
99
99
  "cordis.patch.yml",
100
100
  "README.md",
101
+ "docs/DETAIL.zh.md",
101
102
  "LICENSE"
102
103
  ],
103
104
  "dsh": {
@@ -117,7 +118,7 @@
117
118
  "@opencode-ai/sdk": "1.19.6",
118
119
  "js-yaml": "^4.3.2",
119
120
  "yaml": "^2.8.1",
120
- "@kirkchinese/harness-forge-core": "0.4.0"
121
+ "@kirkchinese/harness-forge-core": "0.5.0"
121
122
  },
122
123
  "peerDependencies": {
123
124
  "@deepseek-ai/cordis": ">=4.1.0 <5",
@@ -1,3 +0,0 @@
1
- import { type MarketplaceSource } from '@kirkchinese/harness-forge-core';
2
- /** Fetch one git marketplace source and return the plugin root inside it. */
3
- export declare function fetchGitSource(source: MarketplaceSource, cacheRoot: string): Promise<string>;
@@ -1,64 +0,0 @@
1
- /**
2
- * Git marketplace source fetcher. It is deliberately narrow: clone a URL,
3
- * optionally pin a ref/SHA, cache by content key, and return a local plugin
4
- * root. No arbitrary command sources and no lifecycle scripts are executed.
5
- * @module @kirkchinese/harness-forge
6
- */
7
- import { createHash } from 'node:crypto';
8
- import { execFile } from 'node:child_process';
9
- import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
10
- import { join, resolve } from 'node:path';
11
- import { promisify } from 'node:util';
12
- import { isInside, HarnessError, } from '@kirkchinese/harness-forge-core';
13
- import { messageOf } from '../shared/util.js';
14
- const run = promisify(execFile);
15
- /** Fetch one git marketplace source and return the plugin root inside it. */
16
- export async function fetchGitSource(source, cacheRoot) {
17
- if (source.kind !== 'git' || source.url === undefined) {
18
- throw new HarnessError('marketplace-failed', 'not a git marketplace source');
19
- }
20
- const url = source.url;
21
- if (!/^(?:https:\/\/|file:\/\/|ssh:\/\/|git@)/u.test(url)) {
22
- throw new HarnessError('marketplace-failed', `unsupported git URL: ${url}`);
23
- }
24
- const key = createHash('sha256')
25
- .update(url)
26
- .update('\0')
27
- .update(source.ref ?? '')
28
- .update('\0')
29
- .update(source.sha ?? '')
30
- .digest('hex')
31
- .slice(0, 24);
32
- const target = join(cacheRoot, key);
33
- if (!existsSync(target)) {
34
- mkdirSync(cacheRoot, { recursive: true });
35
- const temporary = `${target}.tmp-${String(process.pid)}`;
36
- rmSync(temporary, { recursive: true, force: true });
37
- try {
38
- const args = ['clone', '--depth', '1'];
39
- if (source.ref !== undefined && source.sha === undefined)
40
- args.push('--branch', source.ref);
41
- args.push(url, temporary);
42
- await run('git', args, { timeout: 120_000, windowsHide: true, maxBuffer: 4 * 1024 * 1024 });
43
- if (source.sha !== undefined) {
44
- await run('git', ['-C', temporary, 'fetch', '--depth', '1', 'origin', source.sha], { timeout: 120_000, windowsHide: true });
45
- await run('git', ['-C', temporary, 'checkout', '--detach', 'FETCH_HEAD'], { timeout: 60_000, windowsHide: true });
46
- }
47
- writeFileSync(join(temporary, '.harness-forge-source.json'), `${JSON.stringify({ url, ref: source.ref, sha: source.sha, fetchedAt: new Date().toISOString() }, null, 2)}\n`, 'utf8');
48
- rmSync(target, { recursive: true, force: true });
49
- renameSync(temporary, target);
50
- }
51
- catch (error) {
52
- rmSync(temporary, { recursive: true, force: true });
53
- throw new HarnessError('marketplace-failed', `git clone failed: ${messageOf(error)}`, {
54
- cause: error,
55
- suggestion: 'Check the repository URL, ref/SHA, and network access.',
56
- });
57
- }
58
- }
59
- const pluginRoot = source.subpath === undefined ? target : resolve(target, source.subpath);
60
- if (!isInside(target, pluginRoot)) {
61
- throw new HarnessError('path-escape', `marketplace subpath escapes the repository: ${source.subpath ?? ''}`);
62
- }
63
- return pluginRoot;
64
- }