@kirkchinese/harness-forge 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/assets/icon.svg +12 -0
- package/cordis.patch.yml +28 -0
- package/docs/DETAIL.zh.md +47 -0
- package/lib/agents/presets.d.ts +98 -0
- package/lib/agents/presets.js +292 -0
- package/lib/agents/profiles.d.ts +58 -0
- package/lib/agents/profiles.js +279 -0
- package/lib/agents/row.d.ts +17 -0
- package/lib/agents/row.js +148 -0
- package/lib/client/paths.d.ts +12 -0
- package/lib/client/paths.js +68 -0
- package/lib/client/styles.d.ts +8 -0
- package/lib/client/styles.js +89 -0
- package/lib/client/typert.d.ts +25 -0
- package/lib/client/typert.js +158 -0
- package/lib/client.js +23823 -0
- package/lib/commands/definition.d.ts +40 -0
- package/lib/commands/definition.js +113 -0
- package/lib/commands/output-styles.d.ts +42 -0
- package/lib/commands/output-styles.js +152 -0
- package/lib/commands/row.d.ts +9 -0
- package/lib/commands/row.js +157 -0
- package/lib/context/instructions.d.ts +32 -0
- package/lib/context/instructions.js +88 -0
- package/lib/context/row.d.ts +16 -0
- package/lib/context/row.js +17 -0
- package/lib/dsh/commands.d.ts +30 -0
- package/lib/dsh/commands.js +61 -0
- package/lib/dsh/host.d.ts +110 -0
- package/lib/dsh/host.js +217 -0
- package/lib/dsh/model-route.d.ts +21 -0
- package/lib/dsh/model-route.js +37 -0
- package/lib/dsh/session-records.d.ts +78 -0
- package/lib/dsh/session-records.js +36 -0
- package/lib/dsh/subagents.d.ts +46 -0
- package/lib/dsh/subagents.js +14 -0
- package/lib/forge/contract.d.ts +271 -0
- package/lib/forge/contract.js +45 -0
- package/lib/forge/follow.d.ts +30 -0
- package/lib/forge/follow.js +73 -0
- package/lib/forge/ledger.d.ts +206 -0
- package/lib/forge/ledger.js +1005 -0
- package/lib/forge/live-mounts.d.ts +45 -0
- package/lib/forge/live-mounts.js +78 -0
- package/lib/forge/npm.d.ts +31 -0
- package/lib/forge/npm.js +60 -0
- package/lib/forge/projects.d.ts +97 -0
- package/lib/forge/projects.js +343 -0
- package/lib/forge/receipts.d.ts +5 -0
- package/lib/forge/receipts.js +31 -0
- package/lib/forge/remote/archive.d.ts +65 -0
- package/lib/forge/remote/archive.js +565 -0
- package/lib/forge/remote/code-parts.d.ts +18 -0
- package/lib/forge/remote/code-parts.js +76 -0
- package/lib/forge/remote/fetch.d.ts +265 -0
- package/lib/forge/remote/fetch.js +1133 -0
- package/lib/forge/remote/service.d.ts +256 -0
- package/lib/forge/remote/service.js +868 -0
- package/lib/forge/row.d.ts +32 -0
- package/lib/forge/row.js +59 -0
- package/lib/forge/service.d.ts +115 -0
- package/lib/forge/service.js +290 -0
- package/lib/forge/settings.d.ts +43 -0
- package/lib/forge/settings.js +122 -0
- package/lib/forge/state.d.ts +129 -0
- package/lib/forge/state.js +266 -0
- package/lib/forge/trust.d.ts +48 -0
- package/lib/forge/trust.js +107 -0
- package/lib/forge/turns.d.ts +13 -0
- package/lib/forge/turns.js +56 -0
- package/lib/hooks/broker/engine.d.ts +112 -0
- package/lib/hooks/broker/engine.js +722 -0
- package/lib/hooks/broker/helpers.d.ts +10 -0
- package/lib/hooks/broker/helpers.js +22 -0
- package/lib/hooks/broker/lifecycle.d.ts +65 -0
- package/lib/hooks/broker/lifecycle.js +342 -0
- package/lib/hooks/broker/session-events.d.ts +27 -0
- package/lib/hooks/broker/session-events.js +205 -0
- package/lib/hooks/broker/tools.d.ts +52 -0
- package/lib/hooks/broker/tools.js +424 -0
- package/lib/hooks/broker/types.d.ts +264 -0
- package/lib/hooks/broker/types.js +1 -0
- package/lib/hooks/broker.d.ts +80 -0
- package/lib/hooks/broker.js +95 -0
- package/lib/hooks/codex-user.d.ts +5 -0
- package/lib/hooks/codex-user.js +109 -0
- package/lib/hooks/condition.d.ts +87 -0
- package/lib/hooks/condition.js +602 -0
- package/lib/hooks/config.d.ts +85 -0
- package/lib/hooks/config.js +154 -0
- package/lib/hooks/glob.d.ts +41 -0
- package/lib/hooks/glob.js +114 -0
- package/lib/hooks/matcher.d.ts +20 -0
- package/lib/hooks/matcher.js +39 -0
- package/lib/hooks/notice.d.ts +17 -0
- package/lib/hooks/notice.js +39 -0
- package/lib/hooks/output.d.ts +56 -0
- package/lib/hooks/output.js +214 -0
- package/lib/hooks/permissions.d.ts +19 -0
- package/lib/hooks/permissions.js +202 -0
- package/lib/hooks/powershell-aliases.d.ts +19 -0
- package/lib/hooks/powershell-aliases.js +58 -0
- package/lib/hooks/process.d.ts +64 -0
- package/lib/hooks/process.js +289 -0
- package/lib/hooks/row.d.ts +17 -0
- package/lib/hooks/row.js +96 -0
- package/lib/hooks/runner.d.ts +98 -0
- package/lib/hooks/runner.js +322 -0
- package/lib/hooks/shell-commands.d.ts +28 -0
- package/lib/hooks/shell-commands.js +241 -0
- package/lib/hooks/shell.d.ts +44 -0
- package/lib/hooks/shell.js +129 -0
- package/lib/hooks/transcript.d.ts +28 -0
- package/lib/hooks/transcript.js +141 -0
- package/lib/hooks/vocabulary.d.ts +57 -0
- package/lib/hooks/vocabulary.js +366 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +287 -0
- package/lib/mcp/auth.d.ts +35 -0
- package/lib/mcp/auth.js +178 -0
- package/lib/mcp/catalog.d.ts +39 -0
- package/lib/mcp/catalog.js +69 -0
- package/lib/mcp/mount.d.ts +113 -0
- package/lib/mcp/mount.js +317 -0
- package/lib/mcp/policy.d.ts +42 -0
- package/lib/mcp/policy.js +43 -0
- package/lib/mcp/remote.d.ts +45 -0
- package/lib/mcp/remote.js +133 -0
- package/lib/mcp/row.d.ts +9 -0
- package/lib/mcp/row.js +225 -0
- package/lib/mods/bundler.d.ts +38 -0
- package/lib/mods/bundler.js +157 -0
- package/lib/mods/chain.d.ts +103 -0
- package/lib/mods/chain.js +436 -0
- package/lib/mods/claude.d.ts +27 -0
- package/lib/mods/claude.js +56 -0
- package/lib/mods/engine.d.ts +160 -0
- package/lib/mods/engine.js +701 -0
- package/lib/mods/expect.d.ts +8 -0
- package/lib/mods/expect.js +248 -0
- package/lib/mods/host.d.ts +105 -0
- package/lib/mods/host.js +462 -0
- package/lib/mods/loader.d.ts +53 -0
- package/lib/mods/loader.js +231 -0
- package/lib/mods/ops.d.ts +13 -0
- package/lib/mods/ops.js +117 -0
- package/lib/mods/row.d.ts +9 -0
- package/lib/mods/row.js +77 -0
- package/lib/mods/runtime.d.ts +60 -0
- package/lib/mods/runtime.js +133 -0
- package/lib/mods/service/commands.d.ts +17 -0
- package/lib/mods/service/commands.js +121 -0
- package/lib/mods/service/drawings.d.ts +36 -0
- package/lib/mods/service/drawings.js +64 -0
- package/lib/mods/service/sessions.d.ts +63 -0
- package/lib/mods/service/sessions.js +345 -0
- package/lib/mods/service/tools.d.ts +32 -0
- package/lib/mods/service/tools.js +253 -0
- package/lib/mods/service/turns.d.ts +33 -0
- package/lib/mods/service/turns.js +136 -0
- package/lib/mods/service/types.d.ts +151 -0
- package/lib/mods/service/types.js +1 -0
- package/lib/mods/service.d.ts +72 -0
- package/lib/mods/service.js +104 -0
- package/lib/mods/surfaces.d.ts +93 -0
- package/lib/mods/surfaces.js +309 -0
- package/lib/mods/values.d.ts +30 -0
- package/lib/mods/values.js +95 -0
- package/lib/opencode/bun.d.ts +40 -0
- package/lib/opencode/bun.js +168 -0
- package/lib/opencode/convert.d.ts +53 -0
- package/lib/opencode/convert.js +255 -0
- package/lib/opencode/row.d.ts +22 -0
- package/lib/opencode/row.js +104 -0
- package/lib/opencode/runtime/core.d.ts +74 -0
- package/lib/opencode/runtime/core.js +249 -0
- package/lib/opencode/runtime/events.d.ts +80 -0
- package/lib/opencode/runtime/events.js +281 -0
- package/lib/opencode/runtime/mount.d.ts +27 -0
- package/lib/opencode/runtime/mount.js +283 -0
- package/lib/opencode/runtime/server.d.ts +27 -0
- package/lib/opencode/runtime/server.js +354 -0
- package/lib/opencode/runtime/types.d.ts +109 -0
- package/lib/opencode/runtime/types.js +1 -0
- package/lib/opencode/runtime.d.ts +55 -0
- package/lib/opencode/runtime.js +79 -0
- package/lib/porting/adapter-paths.d.ts +13 -0
- package/lib/porting/adapter-paths.js +120 -0
- package/lib/porting/port-gap.d.ts +36 -0
- package/lib/porting/port-gap.js +158 -0
- package/lib/porting/port-sessions.d.ts +41 -0
- package/lib/porting/port-sessions.js +98 -0
- package/lib/porting/prompt.d.ts +23 -0
- package/lib/porting/prompt.js +51 -0
- package/lib/porting/row.d.ts +16 -0
- package/lib/porting/row.js +27 -0
- package/lib/porting/verify-port.d.ts +46 -0
- package/lib/porting/verify-port.js +82 -0
- package/lib/presets/fs-search.d.ts +25 -0
- package/lib/presets/fs-search.js +17 -0
- package/lib/presets/tool-filter.d.ts +35 -0
- package/lib/presets/tool-filter.js +91 -0
- package/lib/sessions/chat-import.d.ts +48 -0
- package/lib/sessions/chat-import.js +44 -0
- package/lib/sessions/claude.d.ts +35 -0
- package/lib/sessions/claude.js +104 -0
- package/lib/sessions/codex-discover.d.ts +34 -0
- package/lib/sessions/codex-discover.js +205 -0
- package/lib/sessions/codex-meta.d.ts +63 -0
- package/lib/sessions/codex-meta.js +148 -0
- package/lib/sessions/codex-text.d.ts +9 -0
- package/lib/sessions/codex-text.js +44 -0
- package/lib/sessions/codex.d.ts +42 -0
- package/lib/sessions/codex.js +270 -0
- package/lib/sessions/opencode.d.ts +38 -0
- package/lib/sessions/opencode.js +339 -0
- package/lib/sessions/persist.d.ts +162 -0
- package/lib/sessions/persist.js +377 -0
- package/lib/sessions/row.d.ts +15 -0
- package/lib/sessions/row.js +101 -0
- package/lib/sessions/turns.d.ts +31 -0
- package/lib/sessions/turns.js +63 -0
- package/lib/sessions/zstd.d.ts +15 -0
- package/lib/sessions/zstd.js +152 -0
- package/lib/shared/invocation.d.ts +169 -0
- package/lib/shared/invocation.js +325 -0
- package/lib/shared/render.d.ts +101 -0
- package/lib/shared/render.js +1353 -0
- package/lib/shared/util.d.ts +21 -0
- package/lib/shared/util.js +32 -0
- package/lib/skills/bundled.d.ts +3 -0
- package/lib/skills/bundled.js +42 -0
- package/lib/skills/provider.d.ts +74 -0
- package/lib/skills/provider.js +346 -0
- package/lib/skills/row.d.ts +22 -0
- package/lib/skills/row.js +204 -0
- package/lib/workbench/adapter-coverage.d.ts +65 -0
- package/lib/workbench/adapter-coverage.js +141 -0
- package/lib/workbench/model-tools.d.ts +10 -0
- package/lib/workbench/model-tools.js +122 -0
- package/lib/workbench/overview.d.ts +153 -0
- package/lib/workbench/overview.js +246 -0
- package/lib/workbench/remote.d.ts +161 -0
- package/lib/workbench/remote.js +561 -0
- package/lib/workbench/row.d.ts +15 -0
- package/lib/workbench/row.js +16 -0
- package/lib/workbench/settings.d.ts +19 -0
- package/lib/workbench/settings.js +60 -0
- package/lib/workbench/workbench.d.ts +130 -0
- package/lib/workbench/workbench.js +361 -0
- package/locale/agents/en.json +6 -0
- package/locale/agents/zh.json +6 -0
- package/locale/commands/en.json +6 -0
- package/locale/commands/zh.json +6 -0
- package/locale/context/en.json +6 -0
- package/locale/context/zh.json +6 -0
- package/locale/en.json +6 -0
- package/locale/hooks/en.json +6 -0
- package/locale/hooks/zh.json +6 -0
- package/locale/mcp/en.json +6 -0
- package/locale/mcp/zh.json +6 -0
- package/locale/mods/en.json +6 -0
- package/locale/mods/zh.json +6 -0
- package/locale/opencode/en.json +6 -0
- package/locale/opencode/zh.json +6 -0
- package/locale/porter/en.json +6 -0
- package/locale/porter/zh.json +6 -0
- package/locale/sessions/en.json +6 -0
- package/locale/sessions/zh.json +6 -0
- package/locale/skills/en.json +6 -0
- package/locale/skills/zh.json +6 -0
- package/locale/workbench/en.json +6 -0
- package/locale/workbench/zh.json +6 -0
- package/locale/zh.json +7 -0
- package/package.json +247 -3
- package/runtime/opencode-host.mjs +270 -0
- package/skills/harness-forge/SKILL.md +47 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { type CompatibilityVector, type DiscoveredMarketplace, type DiscoveredPlugin, type DiscoveryWarning, type ForeignPlugin, type Gap, type SourceId } from '@kirkchinese/harness-forge-core';
|
|
3
|
+
import { type AdapterCoverage, type Overview } from './overview.js';
|
|
4
|
+
import { type HarnessSettings } from './settings.js';
|
|
5
|
+
import type { HarnessForge } from '../forge/service.js';
|
|
6
|
+
/**
|
|
7
|
+
* Harness Forge's own version, from its package.json: the nearest one up
|
|
8
|
+
* from this module (`lib/workbench/` when built, `src/workbench/` in tests).
|
|
9
|
+
*/
|
|
10
|
+
export declare function forgeVersion(from?: string): string | undefined;
|
|
11
|
+
/** One component exposed by an installed plugin. */
|
|
12
|
+
export interface CapabilityItem {
|
|
13
|
+
readonly pluginId: string;
|
|
14
|
+
readonly pluginName: string;
|
|
15
|
+
readonly kind: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
}
|
|
20
|
+
/** Per-plugin capability summary. */
|
|
21
|
+
export interface PluginCapabilities {
|
|
22
|
+
readonly pluginId: string;
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly source: string;
|
|
25
|
+
readonly items: readonly CapabilityItem[];
|
|
26
|
+
readonly compat: CompatibilityVector;
|
|
27
|
+
readonly residentTokens: number;
|
|
28
|
+
}
|
|
29
|
+
/** Aggregate capability and context budget view. */
|
|
30
|
+
export interface CapabilityCatalog {
|
|
31
|
+
readonly plugins: readonly PluginCapabilities[];
|
|
32
|
+
readonly totals: Readonly<Record<string, number>>;
|
|
33
|
+
readonly residentTokens: number;
|
|
34
|
+
readonly toolCount?: number;
|
|
35
|
+
readonly toolTokens?: number;
|
|
36
|
+
readonly budgetTokens?: number;
|
|
37
|
+
readonly overBudget: boolean;
|
|
38
|
+
readonly basis: string;
|
|
39
|
+
}
|
|
40
|
+
/** Services the compatibility layer can use when present. */
|
|
41
|
+
export interface HostCapabilities {
|
|
42
|
+
readonly skills: boolean;
|
|
43
|
+
readonly commands: boolean;
|
|
44
|
+
readonly agentPresets: boolean;
|
|
45
|
+
readonly shell: boolean;
|
|
46
|
+
readonly webServer: boolean;
|
|
47
|
+
readonly workingDirectory: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** Read the current host's optional services. */
|
|
50
|
+
export declare function probeHostCapabilities(ctx: Context): HostCapabilities;
|
|
51
|
+
/** Workbench views over the installations. */
|
|
52
|
+
export declare class Workbench {
|
|
53
|
+
private readonly forge;
|
|
54
|
+
private readonly installs;
|
|
55
|
+
constructor(forge: HarnessForge);
|
|
56
|
+
/** Read the persisted workbench settings. */
|
|
57
|
+
settings(): HarnessSettings;
|
|
58
|
+
/** Save workbench settings; only known fields are accepted. */
|
|
59
|
+
saveSettings(input: {
|
|
60
|
+
readonly discoveryRoots?: unknown;
|
|
61
|
+
readonly autoDiscover?: unknown;
|
|
62
|
+
readonly contextBudgetTokens?: unknown;
|
|
63
|
+
}): HarnessSettings;
|
|
64
|
+
/**
|
|
65
|
+
* A plugin the overview lists, by id, read from disk now, with its gaps:
|
|
66
|
+
* an installed plugin's recorded ones, else those its scan shows.
|
|
67
|
+
*/
|
|
68
|
+
findPlugin(id: string): {
|
|
69
|
+
readonly plugin: ForeignPlugin;
|
|
70
|
+
readonly gaps: readonly Gap[];
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Discover plugin roots using the saved settings: the plugins each harness
|
|
74
|
+
* installed and the person's own assets, never what a marketplace only offers.
|
|
75
|
+
*/
|
|
76
|
+
discover(): {
|
|
77
|
+
settings: HarnessSettings;
|
|
78
|
+
plugins: Array<DiscoveredPlugin & {
|
|
79
|
+
installed: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
marketplaces: readonly DiscoveredMarketplace[];
|
|
82
|
+
missingRoots: readonly string[];
|
|
83
|
+
warnings: readonly DiscoveryWarning[];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Whether a discovered plugin is migrated already. A record that follows a harness install counts for that install
|
|
87
|
+
* only, wherever either's folder is (an update moves it to the harness's new folder); one of an install the harness
|
|
88
|
+
* no longer runs, or of one read through another harness, never makes a current install look migrated. A record
|
|
89
|
+
* that follows no harness counts by its folder, and (unless the person kept it as their own copy) by its id.
|
|
90
|
+
*/
|
|
91
|
+
private migrated;
|
|
92
|
+
/** The local marketplaces the harnesses added: under "Get plugins", each plugin installed on its own after the confirmation. */
|
|
93
|
+
localMarketplaces(): Array<{
|
|
94
|
+
readonly input: string;
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly harness: string;
|
|
97
|
+
}>;
|
|
98
|
+
/** Aggregate capabilities and context cost for installed plugins. */
|
|
99
|
+
capabilities(): CapabilityCatalog;
|
|
100
|
+
/** Current optional host services, for diagnostics. */
|
|
101
|
+
hostCapabilities(): HostCapabilities;
|
|
102
|
+
/** The adapter packages installed in this DSH profile (see `adapter-coverage.ts`), read from disk now. */
|
|
103
|
+
adapters(): AdapterCoverage[];
|
|
104
|
+
/**
|
|
105
|
+
* The adapters on disk that DSH lists as installed and enabled: what `harness_verify_port` requires too, so a link
|
|
106
|
+
* left by a failed install covers nothing.
|
|
107
|
+
*/
|
|
108
|
+
enabledAdapters(): Promise<AdapterCoverage[]>;
|
|
109
|
+
/** Scan the roots the overview lists, and attribute the user's configured status line. */
|
|
110
|
+
private overviewSources;
|
|
111
|
+
/** Whether an installed plugin was fetched from the network: its files are in Harness Forge's own download folders. */
|
|
112
|
+
private fetched;
|
|
113
|
+
/** The workbench's plain-language view of every harness: see `overview.ts`. */
|
|
114
|
+
overview(): Promise<Overview>;
|
|
115
|
+
/** Read-only workbench diagnostics: host services, mounts, tool budget and row failures. */
|
|
116
|
+
diagnostics(): Record<string, unknown>;
|
|
117
|
+
/** List all skill roots the skills row serves (none while it is off). */
|
|
118
|
+
listSkillRoots(): readonly string[];
|
|
119
|
+
/**
|
|
120
|
+
* "Migrate all" of one harness: its plugins and the person's own assets that {@link migratable} takes, the
|
|
121
|
+
* rule the overview counts by. A plugin switched off in its harness stays where it is; it can be migrated alone.
|
|
122
|
+
*/
|
|
123
|
+
migrate(source: SourceId): Promise<{
|
|
124
|
+
readonly installed: readonly string[];
|
|
125
|
+
readonly failed: ReadonlyArray<{
|
|
126
|
+
readonly name: string;
|
|
127
|
+
readonly error: string;
|
|
128
|
+
}>;
|
|
129
|
+
}>;
|
|
130
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workbench's read side: settings, discovery, capabilities and context
|
|
3
|
+
* cost, the overview and diagnostics, and migrating a whole harness. It keeps
|
|
4
|
+
* no state; the workbench row and the `/harness` command both read through it.
|
|
5
|
+
* @module @kirkchinese/harness-forge
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
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';
|
|
14
|
+
import { adapterCoverage, enabledAdapters } from './adapter-coverage.js';
|
|
15
|
+
import { readSettings, writeSettings } from './settings.js';
|
|
16
|
+
import { messageOf } from '../shared/util.js';
|
|
17
|
+
import { dshService } from '../dsh/host.js';
|
|
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
|
+
}
|
|
37
|
+
/** A package's version as this process resolves it, if it resolves. */
|
|
38
|
+
function versionOf(specifier) {
|
|
39
|
+
try {
|
|
40
|
+
return createRequire(import.meta.url)(specifier).version;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Read the current host's optional services. */
|
|
47
|
+
export function probeHostCapabilities(ctx) {
|
|
48
|
+
const has = (name) => dshService(ctx, name) !== undefined;
|
|
49
|
+
return {
|
|
50
|
+
skills: has('skills'),
|
|
51
|
+
commands: has('commands'),
|
|
52
|
+
agentPresets: has('agentPresets'),
|
|
53
|
+
shell: has('shell'),
|
|
54
|
+
webServer: has('webServer'),
|
|
55
|
+
workingDirectory: has('workingDirectory'),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Workbench views over the installations. */
|
|
59
|
+
export class Workbench {
|
|
60
|
+
forge;
|
|
61
|
+
installs;
|
|
62
|
+
constructor(forge) {
|
|
63
|
+
this.forge = forge;
|
|
64
|
+
this.installs = forge.ledger;
|
|
65
|
+
}
|
|
66
|
+
/** Read the persisted workbench settings. */
|
|
67
|
+
settings() {
|
|
68
|
+
return readSettings(this.installs.statePath);
|
|
69
|
+
}
|
|
70
|
+
/** Save workbench settings; only known fields are accepted. */
|
|
71
|
+
saveSettings(input) {
|
|
72
|
+
const current = this.settings();
|
|
73
|
+
const roots = Array.isArray(input.discoveryRoots)
|
|
74
|
+
? [...new Set(input.discoveryRoots
|
|
75
|
+
.filter((value) => typeof value === 'string' && value.trim().length > 0)
|
|
76
|
+
.map(value => resolve(value)))]
|
|
77
|
+
: current.discoveryRoots;
|
|
78
|
+
const autoDiscover = typeof input.autoDiscover === 'boolean' ? input.autoDiscover : current.autoDiscover;
|
|
79
|
+
const contextBudgetTokens = typeof input.contextBudgetTokens === 'number'
|
|
80
|
+
&& Number.isFinite(input.contextBudgetTokens)
|
|
81
|
+
&& input.contextBudgetTokens > 0
|
|
82
|
+
? Math.round(input.contextBudgetTokens)
|
|
83
|
+
: undefined;
|
|
84
|
+
const next = {
|
|
85
|
+
schemaVersion: 1,
|
|
86
|
+
discoveryRoots: roots.length > 0 ? roots : current.discoveryRoots,
|
|
87
|
+
autoDiscover,
|
|
88
|
+
...(contextBudgetTokens !== undefined ? { contextBudgetTokens } : {}),
|
|
89
|
+
};
|
|
90
|
+
writeSettings(this.installs.statePath, next);
|
|
91
|
+
return next;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A plugin the overview lists, by id, read from disk now, with its gaps:
|
|
95
|
+
* an installed plugin's recorded ones, else those its scan shows.
|
|
96
|
+
*/
|
|
97
|
+
findPlugin(id) {
|
|
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) };
|
|
105
|
+
}
|
|
106
|
+
return { plugin, gaps };
|
|
107
|
+
}
|
|
108
|
+
throw new Error(`no plugin ${id} is installed or discovered`);
|
|
109
|
+
}
|
|
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
|
+
*/
|
|
114
|
+
discover() {
|
|
115
|
+
const settings = this.settings();
|
|
116
|
+
const result = discoverPlugins(settings.discoveryRoots);
|
|
117
|
+
return {
|
|
118
|
+
settings,
|
|
119
|
+
plugins: result.plugins.map(plugin => ({ ...plugin, installed: this.migrated(plugin) })),
|
|
120
|
+
marketplaces: result.marketplaces,
|
|
121
|
+
missingRoots: result.missingRoots,
|
|
122
|
+
warnings: result.warnings,
|
|
123
|
+
};
|
|
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
|
+
}
|
|
152
|
+
/** Aggregate capabilities and context cost for installed plugins. */
|
|
153
|
+
capabilities() {
|
|
154
|
+
const settings = this.settings();
|
|
155
|
+
const meter = dshService(this.installs.ctx, 'tokenMeter');
|
|
156
|
+
const estimate = (text) => {
|
|
157
|
+
if (meter === undefined)
|
|
158
|
+
return Math.ceil(text.length / 4);
|
|
159
|
+
try {
|
|
160
|
+
return meter.estimateMessage({ role: 'user', content: [{ type: 'text', text }] });
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return Math.ceil(text.length / 4);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const plugins = [];
|
|
167
|
+
const totals = {};
|
|
168
|
+
let residentTokens = 0;
|
|
169
|
+
for (const install of this.installs.live.values()) {
|
|
170
|
+
const plugin = this.installs.scanRoot(install.record.root, install.record.source);
|
|
171
|
+
const compat = assess(plugin, [...install.outcomes.values()]);
|
|
172
|
+
const items = plugin.components.map((component) => {
|
|
173
|
+
const description = 'description' in component ? component.description : undefined;
|
|
174
|
+
return {
|
|
175
|
+
pluginId: plugin.id,
|
|
176
|
+
pluginName: plugin.displayName ?? plugin.name,
|
|
177
|
+
kind: component.kind,
|
|
178
|
+
name: component.name,
|
|
179
|
+
...(description !== undefined ? { description } : {}),
|
|
180
|
+
source: plugin.source,
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
for (const item of items)
|
|
184
|
+
totals[item.kind] = (totals[item.kind] ?? 0) + 1;
|
|
185
|
+
const measured = items.reduce((sum, item) => (item.kind === 'skill' || item.kind === 'command' || item.kind === 'agent'
|
|
186
|
+
? sum + estimate(`${item.name}\n${item.description ?? ''}`)
|
|
187
|
+
: sum), 0);
|
|
188
|
+
residentTokens += measured;
|
|
189
|
+
plugins.push({ pluginId: plugin.id, name: plugin.displayName ?? plugin.name, source: plugin.source, items, compat, residentTokens: measured });
|
|
190
|
+
}
|
|
191
|
+
const budgetTokens = settings.contextBudgetTokens;
|
|
192
|
+
const tools = dshService(this.installs.ctx, 'tools');
|
|
193
|
+
let toolCount = 0;
|
|
194
|
+
let toolTokens = 0;
|
|
195
|
+
try {
|
|
196
|
+
const schemas = tools?.schemas() ?? [];
|
|
197
|
+
toolCount = schemas.length;
|
|
198
|
+
toolTokens = schemas.reduce((sum, schema) => sum + estimate(JSON.stringify(schema)), 0);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// A composition without tool schema projection reports zero tools.
|
|
202
|
+
}
|
|
203
|
+
const totalResident = residentTokens + toolTokens;
|
|
204
|
+
return {
|
|
205
|
+
plugins,
|
|
206
|
+
totals,
|
|
207
|
+
residentTokens: totalResident,
|
|
208
|
+
...(toolCount > 0 ? { toolCount } : {}),
|
|
209
|
+
...(toolTokens > 0 ? { toolTokens } : {}),
|
|
210
|
+
...(budgetTokens !== undefined ? { budgetTokens } : {}),
|
|
211
|
+
overBudget: budgetTokens !== undefined && totalResident > budgetTokens,
|
|
212
|
+
basis: `${meter === undefined ? 'bytes/4' : 'ctx.tokenMeter'} over catalog text + visible tool schemas`,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** Current optional host services, for diagnostics. */
|
|
216
|
+
hostCapabilities() {
|
|
217
|
+
return probeHostCapabilities(this.forge.ctx);
|
|
218
|
+
}
|
|
219
|
+
/** The adapter packages installed in this DSH profile (see `adapter-coverage.ts`), read from disk now. */
|
|
220
|
+
adapters() {
|
|
221
|
+
const profile = dshService(this.installs.ctx, 'profileContext');
|
|
222
|
+
return adapterCoverage(profile?.dir !== undefined && profile.dir.length > 0 ? profile.dir : undefined);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The adapters on disk that DSH lists as installed and enabled: what `harness_verify_port` requires too, so a link
|
|
226
|
+
* left by a failed install covers nothing.
|
|
227
|
+
*/
|
|
228
|
+
enabledAdapters() {
|
|
229
|
+
return enabledAdapters(this.adapters(), dshService(this.forge.ctx, 'pluginManager'));
|
|
230
|
+
}
|
|
231
|
+
/** Scan the roots the overview lists, and attribute the user's configured status line. */
|
|
232
|
+
overviewSources(requiredId) {
|
|
233
|
+
const scanned = [];
|
|
234
|
+
const unreadable = [];
|
|
235
|
+
for (const record of this.installs.list()) {
|
|
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
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
scanned.push({ plugin: this.installs.scan(record.root, record.source), record });
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
if (record.id === requiredId)
|
|
248
|
+
throw error;
|
|
249
|
+
// Its files are gone or unreadable: it stays listed, every part an error, with why.
|
|
250
|
+
unreadable.push(unreadableItemOf(record, messageOf(error)));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const found of this.discover().plugins) {
|
|
254
|
+
if (found.installed)
|
|
255
|
+
continue;
|
|
256
|
+
try {
|
|
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
|
+
});
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// An unreadable root has nothing to show.
|
|
265
|
+
}
|
|
266
|
+
}
|
|
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);
|
|
310
|
+
}
|
|
311
|
+
/** Read-only workbench diagnostics: host services, mounts, tool budget and row failures. */
|
|
312
|
+
diagnostics() {
|
|
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 ?? '' })));
|
|
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 },
|
|
321
|
+
host: this.hostCapabilities(),
|
|
322
|
+
hookShell: { bash: this.forge.shell.bash ?? null, powershell: this.forge.shell.powershell, default: this.forge.shell.defaultKind },
|
|
323
|
+
bun: findBun(this.installs.dataRoot) ?? null,
|
|
324
|
+
versions: {
|
|
325
|
+
forge: forgeVersion() ?? null,
|
|
326
|
+
dsh: versionOf('@deepseek-ai/dsh-session/package.json') ?? null,
|
|
327
|
+
node: process.versions.node,
|
|
328
|
+
},
|
|
329
|
+
platform: process.platform,
|
|
330
|
+
faults,
|
|
331
|
+
tools: { count: catalog.toolCount ?? 0, tokens: catalog.toolTokens ?? 0, residentTokens: catalog.residentTokens },
|
|
332
|
+
skillRoots: this.listSkillRoots(),
|
|
333
|
+
failedMounts,
|
|
334
|
+
plugins: this.installs.list().map(plugin => ({ id: plugin.id, source: plugin.source, root: plugin.root, installedAt: plugin.installedAt })),
|
|
335
|
+
statePath: this.installs.statePath,
|
|
336
|
+
dataRoot: this.installs.dataRoot,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** List all skill roots the skills row serves (none while it is off). */
|
|
340
|
+
listSkillRoots() {
|
|
341
|
+
return this.forge.lookup('skills')?.roots() ?? [];
|
|
342
|
+
}
|
|
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
|
+
*/
|
|
347
|
+
async migrate(source) {
|
|
348
|
+
const installed = [];
|
|
349
|
+
const failed = [];
|
|
350
|
+
for (const found of this.discover().plugins.filter(item => item.source === source && migratable(item))) {
|
|
351
|
+
try {
|
|
352
|
+
const report = await this.forge.install(found.root, found.source);
|
|
353
|
+
installed.push(report.plugin.displayName ?? report.plugin.name);
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
failed.push({ name: found.name, error: messageOf(error) });
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return { installed, failed };
|
|
360
|
+
}
|
|
361
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Harness Forge instructions",
|
|
4
|
+
"description": "Adds Claude Code's instruction files that DSH does not read (~/.claude/CLAUDE.md, .claude/CLAUDE.md, @path imports) and Codex's global AGENTS.md to the system prompt. Yields when the Recollect plugin runs. Needs the Harness Forge row."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Harness Forge",
|
|
4
|
+
"description": "Use Claude Code, Codex and OpenCode plugins, settings and sessions in DSH. Open Harness Forge in the sidebar to see what was found on this computer and migrate it. The other Harness Forge rows each run one kind of part and can be switched off on their own."
|
|
5
|
+
}
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Harness Forge porting",
|
|
4
|
+
"description": "Describes a Claude Code, Codex or OpenCode plugin part DSH cannot run as it is and hands the brief to DSH's creation mode, which writes and installs a local adapter plugin. Turn it off to hide porting. Needs the Harness Forge row."
|
|
5
|
+
}
|
|
6
|
+
}
|