@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,561 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workbench's whole Host surface, as Typert Remote methods under the
|
|
3
|
+
* `harnessCompat` namespace: the browser reaches them through DSH's own
|
|
4
|
+
* Remote carrier, like every DSH service, and Harness Forge registers no HTTP
|
|
5
|
+
* routes of its own. Each method takes at most one `request` object, so the
|
|
6
|
+
* Gateway's source-mode reflection maps one named wire argument and no
|
|
7
|
+
* parameter name can collide with a Host lookup. Method names avoid the
|
|
8
|
+
* browser namespace service's own members (`install`, `remove`, `has`, …). Failures are RemoteErrors
|
|
9
|
+
* whose message is the reason the person reads.
|
|
10
|
+
*
|
|
11
|
+
* Methods are marked with the protocol's runtime marker helper rather than
|
|
12
|
+
* decorator syntax so Vitest can load the Host entry without a decorator
|
|
13
|
+
* transform.
|
|
14
|
+
* @module @kirkchinese/harness-forge
|
|
15
|
+
*/
|
|
16
|
+
import { homedir } from 'node:os';
|
|
17
|
+
import { assess, dialects } from '@kirkchinese/harness-forge-core';
|
|
18
|
+
import { Remote, RemoteError, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
19
|
+
import { Workbench } from './workbench.js';
|
|
20
|
+
import { waitingParts } from '../forge/projects.js';
|
|
21
|
+
import { forgeVerifyDeps, livePorts, verifyPort } from '../porting/verify-port.js';
|
|
22
|
+
import { stateOf } from '../porting/port-sessions.js';
|
|
23
|
+
import { installChatImport, sessionImportStatus } from '../sessions/chat-import.js';
|
|
24
|
+
function sourceOf(value) {
|
|
25
|
+
return value === 'codex' || value === 'opencode' ? value : 'claude-code';
|
|
26
|
+
}
|
|
27
|
+
/** A Discover section's harness, any dialect Harness Forge reads (Agent Skills too); an unknown one is refused. */
|
|
28
|
+
function dialectOf(value) {
|
|
29
|
+
const dialect = dialects().find(candidate => candidate.id === value);
|
|
30
|
+
if (dialect === undefined)
|
|
31
|
+
throw new Error(`unknown harness ${JSON.stringify(value)}`);
|
|
32
|
+
return dialect.id;
|
|
33
|
+
}
|
|
34
|
+
function text(request, key) {
|
|
35
|
+
const value = request?.[key];
|
|
36
|
+
return typeof value === 'string' ? value : '';
|
|
37
|
+
}
|
|
38
|
+
function required(request, key, operation) {
|
|
39
|
+
const value = text(request, key);
|
|
40
|
+
if (value.length === 0)
|
|
41
|
+
throw new RemoteError('harness-forge/failed', `${key} is required`, { operation });
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
/** Plugin facts the workbench shows for a scan. */
|
|
45
|
+
function summary(plugin) {
|
|
46
|
+
const counts = new Map();
|
|
47
|
+
for (const component of plugin.components)
|
|
48
|
+
counts.set(component.kind, (counts.get(component.kind) ?? 0) + 1);
|
|
49
|
+
return {
|
|
50
|
+
id: plugin.id,
|
|
51
|
+
name: plugin.displayName ?? plugin.name,
|
|
52
|
+
source: plugin.source,
|
|
53
|
+
version: plugin.version,
|
|
54
|
+
license: plugin.license,
|
|
55
|
+
root: plugin.root,
|
|
56
|
+
manifestKind: plugin.ref.manifestKind,
|
|
57
|
+
components: Object.fromEntries(counts),
|
|
58
|
+
warnings: plugin.warnings.map(warning => warning.code),
|
|
59
|
+
compat: assess(plugin),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** What an install reports to the workbench. */
|
|
63
|
+
function reportOf(report) {
|
|
64
|
+
return {
|
|
65
|
+
plugin: summary(report.plugin),
|
|
66
|
+
compat: report.compat,
|
|
67
|
+
receipt: report.receipt,
|
|
68
|
+
outcomes: report.outcomes,
|
|
69
|
+
alreadyInstalled: report.alreadyInstalled,
|
|
70
|
+
skillRoots: report.skillRoots,
|
|
71
|
+
commands: report.commands,
|
|
72
|
+
mcp: report.mcp,
|
|
73
|
+
hooks: report.hooks,
|
|
74
|
+
agents: report.agents,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* An answer as plain JSON, the only kind DSH's Remote carrier passes: fields
|
|
79
|
+
* that are `undefined` (or functions) are dropped, an `undefined` list item
|
|
80
|
+
* becomes `null`, `-0` becomes `0`, and anything with `toJSON` is converted as
|
|
81
|
+
* JSON would. A number JSON cannot carry, a bigint or a cycle is refused with
|
|
82
|
+
* where it sits, instead of reaching the browser as something else.
|
|
83
|
+
*/
|
|
84
|
+
export function plainJson(value, at = 'answer', ancestors = new Set()) {
|
|
85
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
86
|
+
return value;
|
|
87
|
+
if (typeof value === 'number') {
|
|
88
|
+
if (!Number.isFinite(value))
|
|
89
|
+
throw new Error(`${at} is ${String(value)}, which JSON cannot carry`);
|
|
90
|
+
return value === 0 ? 0 : value;
|
|
91
|
+
}
|
|
92
|
+
if (typeof value === 'bigint')
|
|
93
|
+
throw new Error(`${at} is a bigint, which JSON cannot carry`);
|
|
94
|
+
if (typeof value !== 'object')
|
|
95
|
+
return undefined;
|
|
96
|
+
if (ancestors.has(value))
|
|
97
|
+
throw new Error(`${at} refers to itself, which JSON cannot carry`);
|
|
98
|
+
const toJSON = value.toJSON;
|
|
99
|
+
if (typeof toJSON === 'function')
|
|
100
|
+
return plainJson(toJSON.call(value), at, ancestors);
|
|
101
|
+
ancestors.add(value);
|
|
102
|
+
try {
|
|
103
|
+
if (Array.isArray(value))
|
|
104
|
+
return value.map((item, index) => plainJson(item, `${at}[${String(index)}]`, ancestors) ?? null);
|
|
105
|
+
const plain = {};
|
|
106
|
+
for (const [key, item] of Object.entries(value)) {
|
|
107
|
+
const converted = plainJson(item, `${at}.${key}`, ancestors);
|
|
108
|
+
if (converted !== undefined)
|
|
109
|
+
plain[key] = converted;
|
|
110
|
+
}
|
|
111
|
+
return plain;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
ancestors.delete(value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** The installation service as Remote methods. */
|
|
118
|
+
export class HarnessRemoteService extends TypertRemoteService {
|
|
119
|
+
forge;
|
|
120
|
+
workbench;
|
|
121
|
+
adapterSurfaces = new Map();
|
|
122
|
+
adapterListeners = new Map();
|
|
123
|
+
constructor(ctx, forge) {
|
|
124
|
+
super(ctx, 'harnessCompat');
|
|
125
|
+
this.forge = forge;
|
|
126
|
+
this.workbench = new Workbench(forge);
|
|
127
|
+
}
|
|
128
|
+
/** A row's API, or a failure naming the row that is off. */
|
|
129
|
+
row(name, operation) {
|
|
130
|
+
const api = this.forge.lookup(name);
|
|
131
|
+
if (api === undefined)
|
|
132
|
+
throw new RemoteError('harness-forge/failed', `the Harness Forge ${name} row is off; turn it on in Plugin Manager`, { operation });
|
|
133
|
+
return api;
|
|
134
|
+
}
|
|
135
|
+
/** Run one operation and answer it as plain JSON; anything it throws reaches the browser with its message. */
|
|
136
|
+
async guard(operation, run) {
|
|
137
|
+
try {
|
|
138
|
+
return plainJson(await run(), operation);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (typeof error === 'object' && error !== null && error.isDSHRemoteError === true)
|
|
142
|
+
throw error;
|
|
143
|
+
const code = error instanceof Error ? error.code : undefined;
|
|
144
|
+
if (code === 'session-too-large') {
|
|
145
|
+
const { limit, bytes } = error;
|
|
146
|
+
throw new RemoteError('harness-forge/session-too-large', error.message, { operation, limit: limit ?? 0, ...(bytes !== undefined ? { size: bytes } : {}) }, { cause: error });
|
|
147
|
+
}
|
|
148
|
+
if (code === 'session-maybe-imported') {
|
|
149
|
+
throw new RemoteError('harness-forge/session-maybe-imported', error.message, { operation, existingId: String(error.existingId) }, { cause: error });
|
|
150
|
+
}
|
|
151
|
+
throw new RemoteError('harness-forge/failed', error instanceof Error ? error.message : String(error), { operation }, { cause: error });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// --- reading --------------------------------------------------------------
|
|
155
|
+
/** The instruction files added to the default workspace's prompt (`{ active, yieldingTo?, files }`); inactive while the context row is off. */
|
|
156
|
+
contextStatus() {
|
|
157
|
+
return this.guard('contextStatus', () => this.forge.lookup('context')?.status() ?? { active: false, files: [] });
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The overview, plus the home folder (the page shows paths under it as `~/…`), the workspaces of open sessions with
|
|
161
|
+
* their trust and the project parts that wait for it, and how many records are still being applied. It starts following the harnesses' changes without waiting for it:
|
|
162
|
+
* `applying` says it is under way, and the next overview shows the result.
|
|
163
|
+
*/
|
|
164
|
+
overview() {
|
|
165
|
+
return this.guard('overview', async () => {
|
|
166
|
+
void this.forge.follow();
|
|
167
|
+
const applying = this.forge.applying();
|
|
168
|
+
return { ...await this.workbench.overview(), home: homedir(), workspaces: await this.forge.projects.workspaces(), ...(applying !== undefined ? { applying } : {}) };
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// --- workspace trust ----------------------------------------------------------
|
|
172
|
+
/** A workspace's trust (`{ workspace, trusted, sources, waiting }`): its project parts that run code wait until it is trusted. */
|
|
173
|
+
workspaceTrust(request) {
|
|
174
|
+
return this.guard('workspaceTrust', () => this.trustOf(required(request, 'cwd', 'workspaceTrust')));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Trust (or stop trusting) a workspace in Harness Forge; returns once open sessions in it have mounted or withdrawn what changed
|
|
178
|
+
* (`{ decision, stillLive: [{ componentId, reason }] }`: the parts whose withdrawal failed are still live, and calling it again retries).
|
|
179
|
+
*/
|
|
180
|
+
trustWorkspace(request) {
|
|
181
|
+
return this.guard('trustWorkspace', async () => {
|
|
182
|
+
const cwd = required(request, 'cwd', 'trustWorkspace');
|
|
183
|
+
if (typeof request['trusted'] !== 'boolean')
|
|
184
|
+
throw new RemoteError('harness-forge/failed', 'trusted must be true or false', { operation: 'trustWorkspace' });
|
|
185
|
+
const { stillLive } = await this.forge.projects.setTrust(cwd, request['trusted']);
|
|
186
|
+
return { decision: this.trustOf(cwd), stillLive };
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/** The workspaces Harness Forge holds a trust decision on (`{ workspaces: [{ workspace, trusted, sources, dismissed, trustedAt?, dismissedAt? }] }`): trusted here, or dismissed with "Not now". */
|
|
190
|
+
trustDecisions() {
|
|
191
|
+
return this.guard('trustDecisions', () => ({ workspaces: this.forge.projects.trust.list() }));
|
|
192
|
+
}
|
|
193
|
+
/** Hide (or show again) a workspace's trust banner; trusts nothing. */
|
|
194
|
+
dismissTrust(request) {
|
|
195
|
+
return this.guard('dismissTrust', () => {
|
|
196
|
+
const cwd = required(request, 'cwd', 'dismissTrust');
|
|
197
|
+
if (typeof request['dismissed'] !== 'boolean')
|
|
198
|
+
throw new RemoteError('harness-forge/failed', 'dismissed must be true or false', { operation: 'dismissTrust' });
|
|
199
|
+
this.forge.projects.trust.dismiss(cwd, request['dismissed']);
|
|
200
|
+
return this.trustOf(cwd);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
trustOf(cwd) {
|
|
204
|
+
const state = this.forge.projects.trust.state(cwd);
|
|
205
|
+
return { ...state, waiting: waitingParts(cwd, state) };
|
|
206
|
+
}
|
|
207
|
+
discover() {
|
|
208
|
+
return this.guard('discover', () => {
|
|
209
|
+
void this.forge.follow();
|
|
210
|
+
return this.workbench.discover();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
diagnostics() {
|
|
214
|
+
return this.guard('diagnostics', () => this.workbench.diagnostics());
|
|
215
|
+
}
|
|
216
|
+
settings() {
|
|
217
|
+
return this.guard('settings', () => this.workbench.settings());
|
|
218
|
+
}
|
|
219
|
+
saveSettings(request) {
|
|
220
|
+
return this.guard('saveSettings', () => this.workbench.saveSettings(request));
|
|
221
|
+
}
|
|
222
|
+
// --- migrating --------------------------------------------------------------
|
|
223
|
+
installPlugin(request) {
|
|
224
|
+
return this.guard('installPlugin', async () => {
|
|
225
|
+
return reportOf(await this.forge.install(required(request, 'path', 'installPlugin'), text(request, 'source') || 'claude-code'));
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
migrate(request) {
|
|
229
|
+
return this.guard('migrate', () => this.workbench.migrate(dialectOf(request['source'])));
|
|
230
|
+
}
|
|
231
|
+
setPartEnabled(request) {
|
|
232
|
+
return this.guard('setPartEnabled', async () => {
|
|
233
|
+
const pluginId = required(request, 'pluginId', 'setPartEnabled');
|
|
234
|
+
const componentId = required(request, 'componentId', 'setPartEnabled');
|
|
235
|
+
if (typeof request['enabled'] !== 'boolean')
|
|
236
|
+
throw new RemoteError('harness-forge/failed', 'enabled must be true or false', { operation: 'setPartEnabled' });
|
|
237
|
+
return { changed: await this.forge.setPartEnabled(pluginId, componentId, request['enabled']) };
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
removePlugin(request) {
|
|
241
|
+
return this.guard('removePlugin', async () => {
|
|
242
|
+
const id = required(request, 'id', 'removePlugin');
|
|
243
|
+
if (!await this.forge.uninstall(id))
|
|
244
|
+
throw new RemoteError('harness-forge/failed', `no installed plugin ${id}`, { operation: 'removePlugin' });
|
|
245
|
+
return { removed: true };
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/** Keep a plugin its harness no longer runs as the person's own copy. */
|
|
249
|
+
keepPlugin(request) {
|
|
250
|
+
return this.guard('keepPlugin', async () => {
|
|
251
|
+
await this.forge.keep(required(request, 'id', 'keepPlugin'));
|
|
252
|
+
return { kept: true };
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
// --- plugins from the network ------------------------------------------------
|
|
256
|
+
/**
|
|
257
|
+
* The default marketplaces, the ones the person added, the local
|
|
258
|
+
* marketplaces the harnesses on this computer added, what was installed
|
|
259
|
+
* from the network, and whether git is installed.
|
|
260
|
+
*/
|
|
261
|
+
remoteSources() {
|
|
262
|
+
return this.guard('remoteSources', async () => ({ ...await this.forge.remote.sources(), local: this.workbench.localMarketplaces() }));
|
|
263
|
+
}
|
|
264
|
+
/** Open a pasted marketplace or plugin (`owner/repo`, a git URL, a marketplace.json URL, an npm package, a local folder): its entries, fetched now. */
|
|
265
|
+
remoteOpen(request) {
|
|
266
|
+
return this.guard('remoteOpen', () => this.forge.remote.open(required(request, 'input', 'remoteOpen')));
|
|
267
|
+
}
|
|
268
|
+
/** Stop listing a marketplace the person added. */
|
|
269
|
+
remoteForget(request) {
|
|
270
|
+
return this.guard('remoteForget', () => ({ forgotten: this.forge.remote.forget(required(request, 'input', 'remoteForget')) }));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Fetch one plugin (a marketplace's `entry`, or the pasted `input` itself) and say what it contains, to confirm:
|
|
274
|
+
* `{ token, name, source, page?, revision, parts, codeParts, … }`. Nothing is installed yet.
|
|
275
|
+
*/
|
|
276
|
+
remotePrepare(request) {
|
|
277
|
+
return this.guard('remotePrepare', () => this.forge.remote.prepare(required(request, 'input', 'remotePrepare'), text(request, 'entry') || undefined));
|
|
278
|
+
}
|
|
279
|
+
/** Install (or, for an update, apply) exactly what `remotePrepare` or `remotePrepareUpdate` showed. */
|
|
280
|
+
remoteInstall(request) {
|
|
281
|
+
return this.guard('remoteInstall', async () => {
|
|
282
|
+
const result = await this.forge.remote.install(required(request, 'token', 'remoteInstall'));
|
|
283
|
+
if (result.report === undefined)
|
|
284
|
+
return { pluginId: result.pluginId, revision: result.revision, updated: result.updated };
|
|
285
|
+
return { ...reportOf(result.report), revision: result.revision, updated: result.updated };
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/** Drop a confirmation the person declined, with the files it fetched. */
|
|
289
|
+
remoteCancel(request) {
|
|
290
|
+
return this.guard('remoteCancel', () => ({ cancelled: this.forge.remote.cancel(required(request, 'token', 'remoteCancel')) }));
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Compare what was installed from the network with its source now
|
|
294
|
+
* (`{ updates: [{ pluginId, current, latest?, update, token?, error? }] }`); `token` names the revision found.
|
|
295
|
+
*/
|
|
296
|
+
remoteCheckUpdates(request) {
|
|
297
|
+
return this.guard('remoteCheckUpdates', async () => ({ updates: await this.forge.remote.checkUpdates(text(request, 'pluginId') || undefined) }));
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Fetch the revision a check found (`{ pluginId, token }`) and say what it contains and what changed, to confirm
|
|
301
|
+
* like an install; `remoteInstall` with the returned token applies it.
|
|
302
|
+
*/
|
|
303
|
+
remotePrepareUpdate(request) {
|
|
304
|
+
return this.guard('remotePrepareUpdate', () => this.forge.remote.prepareUpdate(required(request, 'pluginId', 'remotePrepareUpdate'), required(request, 'token', 'remotePrepareUpdate')));
|
|
305
|
+
}
|
|
306
|
+
// --- sign-in, sessions ------------------------------------------------------
|
|
307
|
+
signIns() {
|
|
308
|
+
return this.guard('signIns', () => ({ waiting: this.row('mcp', 'signIns').pendingSignIns() }));
|
|
309
|
+
}
|
|
310
|
+
signIn(request) {
|
|
311
|
+
return this.guard('signIn', () => {
|
|
312
|
+
const server = required(request, 'server', 'signIn');
|
|
313
|
+
return { server, signInUrl: this.row('mcp', 'signIn').startSignIn(server) };
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
sessions(request) {
|
|
317
|
+
return this.guard('sessions', () => {
|
|
318
|
+
const cursor = request?.['cursor'];
|
|
319
|
+
const limit = request?.['limit'];
|
|
320
|
+
return this.row('sessions', 'sessions').sessions(undefined, sourceOf(request?.['source']), {
|
|
321
|
+
...(typeof cursor === 'number' && Number.isInteger(cursor) && cursor >= 0 ? { cursor } : {}),
|
|
322
|
+
...(typeof limit === 'number' && Number.isInteger(limit) && limit > 0 ? { limit: Math.min(limit, 200) } : {}),
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
importSession(request) {
|
|
327
|
+
return this.guard('importSession', () => this.row('sessions', 'importSession').importSession(required(request, 'path', 'importSession'), text(request, 'targetId') || undefined, sourceOf(request['source']), text(request, 'sourceId') || undefined));
|
|
328
|
+
}
|
|
329
|
+
/** Open a session an import stored: registered with DSH and out of its archive (`{ id, live, unarchived, archived }`). */
|
|
330
|
+
openImported(request) {
|
|
331
|
+
return this.guard('openImported', () => this.row('sessions', 'openImported').open(required(request, 'id', 'openImported')));
|
|
332
|
+
}
|
|
333
|
+
/** Who imports sessions (`{ provider: 'harness-forge' | 'dsh-chat-import', canInstall, command }`). */
|
|
334
|
+
sessionImport() {
|
|
335
|
+
return this.guard('sessionImport', () => sessionImportStatus(this.forge.ctx));
|
|
336
|
+
}
|
|
337
|
+
/** Install and enable dsh-chat-import through DSH's plugin manager; the browser asks the person first. */
|
|
338
|
+
installChatImport() {
|
|
339
|
+
return this.guard('installChatImport', () => installChatImport(this.forge.ctx));
|
|
340
|
+
}
|
|
341
|
+
// --- mod surfaces -------------------------------------------------------------
|
|
342
|
+
/**
|
|
343
|
+
* A session's mod drawings: the current one, then every new one, until the
|
|
344
|
+
* browser stops reading. Ends at once when the session's mods draw nothing.
|
|
345
|
+
*/
|
|
346
|
+
async *modSurfaces(request, signal) {
|
|
347
|
+
const session = text(request, 'session');
|
|
348
|
+
const queue = [];
|
|
349
|
+
let wake;
|
|
350
|
+
const stop = this.forge.lookup('mods')?.watch(session, (snapshot) => {
|
|
351
|
+
queue.push(snapshot);
|
|
352
|
+
wake?.();
|
|
353
|
+
});
|
|
354
|
+
if (stop === undefined)
|
|
355
|
+
return;
|
|
356
|
+
const aborted = new Promise((resolve) => {
|
|
357
|
+
if (signal?.aborted === true)
|
|
358
|
+
resolve();
|
|
359
|
+
signal?.addEventListener('abort', () => { resolve(); }, { once: true });
|
|
360
|
+
});
|
|
361
|
+
try {
|
|
362
|
+
while (signal?.aborted !== true) {
|
|
363
|
+
while (queue.length > 0)
|
|
364
|
+
yield plainJson(queue.shift(), 'modSurfaces');
|
|
365
|
+
await Promise.race([new Promise((resolve) => { wake = resolve; }), aborted]);
|
|
366
|
+
wake = undefined;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
finally {
|
|
370
|
+
stop();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
modAct(request) {
|
|
374
|
+
return this.guard('modAct', () => this.row('mods', 'modAct').act(text(request, 'session'), Number(request['generation']), text(request, 'action'), request['value']));
|
|
375
|
+
}
|
|
376
|
+
modClose(request) {
|
|
377
|
+
return this.guard('modClose', () => this.row('mods', 'modClose').closePane(text(request, 'session'), text(request, 'pane')));
|
|
378
|
+
}
|
|
379
|
+
modMove(request) {
|
|
380
|
+
return this.guard('modMove', () => {
|
|
381
|
+
const kind = request['kind'] === 'scroll' ? 'scroll' : 'focus';
|
|
382
|
+
return this.row('mods', 'modMove').move(text(request, 'session'), kind, request);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
// --- adapter surfaces ---------------------------------------------------------
|
|
386
|
+
/**
|
|
387
|
+
* For an adapter's Node half (not a Remote method): publish a surface its
|
|
388
|
+
* browser half reads through `adapterSurface`, so an adapter needs no HTTP
|
|
389
|
+
* route of its own. `read` gives what the surface shows for one session;
|
|
390
|
+
* `changed(session)` tells the browser to read again.
|
|
391
|
+
*/
|
|
392
|
+
registerAdapterSurface(id, source) {
|
|
393
|
+
this.adapterSurfaces.set(id, source);
|
|
394
|
+
const listeners = this.adapterListeners.get(id) ?? new Set();
|
|
395
|
+
this.adapterListeners.set(id, listeners);
|
|
396
|
+
return {
|
|
397
|
+
changed: (sessionId) => { for (const listener of [...listeners])
|
|
398
|
+
listener(sessionId); },
|
|
399
|
+
dispose: () => {
|
|
400
|
+
if (this.adapterSurfaces.get(id) === source)
|
|
401
|
+
this.adapterSurfaces.delete(id);
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/** What an adapter's surface shows for a session now, read once (a browser half that sets its own pace). */
|
|
406
|
+
async adapterRead(request) {
|
|
407
|
+
const id = required(request, 'adapter', 'adapterRead');
|
|
408
|
+
const source = this.adapterSurfaces.get(id);
|
|
409
|
+
if (source === undefined)
|
|
410
|
+
throw new RemoteError('harness-forge/failed', `no adapter surface "${id}" is registered in this DSH`, { operation: 'adapterRead' });
|
|
411
|
+
return this.guard('adapterRead', () => source.read(text(request, 'session'), request));
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* What an adapter's surface shows for a session: now, then again each time
|
|
415
|
+
* the adapter says it changed, until the browser stops reading.
|
|
416
|
+
*/
|
|
417
|
+
async *adapterSurface(request, signal) {
|
|
418
|
+
const id = required(request, 'adapter', 'adapterSurface');
|
|
419
|
+
const session = text(request, 'session');
|
|
420
|
+
if (!this.adapterSurfaces.has(id))
|
|
421
|
+
throw new RemoteError('harness-forge/failed', `no adapter surface "${id}" is registered in this DSH`, { operation: 'adapterSurface' });
|
|
422
|
+
let pending = true;
|
|
423
|
+
let wake;
|
|
424
|
+
const listener = (changed) => {
|
|
425
|
+
if (changed !== session)
|
|
426
|
+
return;
|
|
427
|
+
pending = true;
|
|
428
|
+
wake?.();
|
|
429
|
+
};
|
|
430
|
+
const listeners = this.adapterListeners.get(id) ?? new Set();
|
|
431
|
+
this.adapterListeners.set(id, listeners);
|
|
432
|
+
listeners.add(listener);
|
|
433
|
+
const aborted = new Promise((resolve) => {
|
|
434
|
+
if (signal?.aborted === true)
|
|
435
|
+
resolve();
|
|
436
|
+
signal?.addEventListener('abort', () => { resolve(); }, { once: true });
|
|
437
|
+
});
|
|
438
|
+
try {
|
|
439
|
+
while (signal?.aborted !== true) {
|
|
440
|
+
if (pending) {
|
|
441
|
+
pending = false;
|
|
442
|
+
const source = this.adapterSurfaces.get(id);
|
|
443
|
+
if (source === undefined)
|
|
444
|
+
return;
|
|
445
|
+
yield plainJson(await source.read(session, request), 'adapterSurface');
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
await Promise.race([new Promise((resolve) => { wake = resolve; }), aborted]);
|
|
449
|
+
wake = undefined;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
listeners.delete(listener);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// --- porting ----------------------------------------------------------------
|
|
457
|
+
/**
|
|
458
|
+
* The task a port session starts with (the working protocol, then the part's brief), as Markdown, to preview or
|
|
459
|
+
* copy; `language` is the user's interface language, which the agent is told to talk in.
|
|
460
|
+
*/
|
|
461
|
+
portBrief(request) {
|
|
462
|
+
return this.guard('portBrief', () => {
|
|
463
|
+
const porter = this.row('porter', 'portBrief');
|
|
464
|
+
const { plugin, gaps } = this.workbench.findPlugin(required(request, 'pluginId', 'portBrief'));
|
|
465
|
+
return { markdown: porter.task(plugin, gaps, required(request, 'componentId', 'portBrief'), text(request, 'language') || undefined) };
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The parts being ported or ported (`{ ports: [{ pluginId, componentId, state, sessionId?, verifiedAt?, adapter? }] }`,
|
|
470
|
+
* `state` `in-progress` or `verified`). A port whose session was deleted is dropped, so the part can be ported again.
|
|
471
|
+
*/
|
|
472
|
+
portSessions() {
|
|
473
|
+
return this.guard('portSessions', async () => ({ ports: (await livePorts(this.forge)).map(record => ({ ...record, state: stateOf(record) })) }));
|
|
474
|
+
}
|
|
475
|
+
/** What `harness_verify_port` answers for a part (`{ covered, checks, adapter? }`), recorded the same way. */
|
|
476
|
+
verifyPort(request) {
|
|
477
|
+
return this.guard('verifyPort', () => verifyPort(forgeVerifyDeps(this.forge, this.workbench), required(request, 'pluginId', 'verifyPort'), required(request, 'componentId', 'verifyPort')));
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Port one part of a plugin: start a session in DSH's creation mode working
|
|
481
|
+
* on its task in the adapters directory by default (or the given `workspaceId`
|
|
482
|
+
* or `cwd`), and record it as the part's port session.
|
|
483
|
+
*/
|
|
484
|
+
portGap(request) {
|
|
485
|
+
return this.guard('portGap', async () => {
|
|
486
|
+
const porter = this.row('porter', 'portGap');
|
|
487
|
+
const { plugin, gaps } = this.workbench.findPlugin(required(request, 'pluginId', 'portGap'));
|
|
488
|
+
const workspaceId = text(request, 'workspaceId');
|
|
489
|
+
const cwd = text(request, 'cwd');
|
|
490
|
+
const location = workspaceId.length > 0 ? { workspaceId } : cwd.length > 0 ? { cwd } : {};
|
|
491
|
+
const { sessionId } = await porter.port(plugin, gaps, required(request, 'componentId', 'portGap'), location, text(request, 'language') || undefined);
|
|
492
|
+
return { sessionId };
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/** The Remote methods and whether each streams; the client contribution mirrors this list. */
|
|
497
|
+
export const REMOTE_METHODS = [
|
|
498
|
+
// [method, mode, takes a request]
|
|
499
|
+
['overview', 'unary', false],
|
|
500
|
+
['workspaceTrust', 'unary', true],
|
|
501
|
+
['trustWorkspace', 'unary', true],
|
|
502
|
+
['trustDecisions', 'unary', false],
|
|
503
|
+
['dismissTrust', 'unary', true],
|
|
504
|
+
['discover', 'unary', false],
|
|
505
|
+
['contextStatus', 'unary', false],
|
|
506
|
+
['diagnostics', 'unary', false],
|
|
507
|
+
['settings', 'unary', false],
|
|
508
|
+
['saveSettings', 'unary', true],
|
|
509
|
+
['installPlugin', 'unary', true],
|
|
510
|
+
['migrate', 'unary', true],
|
|
511
|
+
['setPartEnabled', 'unary', true],
|
|
512
|
+
['removePlugin', 'unary', true],
|
|
513
|
+
['keepPlugin', 'unary', true],
|
|
514
|
+
['remoteSources', 'unary', false],
|
|
515
|
+
['remoteOpen', 'unary', true],
|
|
516
|
+
['remoteForget', 'unary', true],
|
|
517
|
+
['remotePrepare', 'unary', true],
|
|
518
|
+
['remoteInstall', 'unary', true],
|
|
519
|
+
['remoteCancel', 'unary', true],
|
|
520
|
+
['remoteCheckUpdates', 'unary', true],
|
|
521
|
+
['remotePrepareUpdate', 'unary', true],
|
|
522
|
+
['signIns', 'unary', false],
|
|
523
|
+
['signIn', 'unary', true],
|
|
524
|
+
['sessions', 'unary', true],
|
|
525
|
+
['importSession', 'unary', true],
|
|
526
|
+
['openImported', 'unary', true],
|
|
527
|
+
['sessionImport', 'unary', false],
|
|
528
|
+
['installChatImport', 'unary', false],
|
|
529
|
+
['modSurfaces', 'stream', true],
|
|
530
|
+
['modAct', 'unary', true],
|
|
531
|
+
['modClose', 'unary', true],
|
|
532
|
+
['modMove', 'unary', true],
|
|
533
|
+
['adapterSurface', 'stream', true],
|
|
534
|
+
['adapterRead', 'unary', true],
|
|
535
|
+
['portBrief', 'unary', true],
|
|
536
|
+
['portGap', 'unary', true],
|
|
537
|
+
['portSessions', 'unary', false],
|
|
538
|
+
['verifyPort', 'unary', true],
|
|
539
|
+
];
|
|
540
|
+
/**
|
|
541
|
+
* Attach the same marker the decorator would attach. The decorator's context
|
|
542
|
+
* only calls `addInitializer`; running it against a synthetic instance is the
|
|
543
|
+
* public runtime equivalent.
|
|
544
|
+
*/
|
|
545
|
+
function markRemote(method, mode) {
|
|
546
|
+
const prototype = HarnessRemoteService.prototype;
|
|
547
|
+
const synthetic = Object.create(prototype);
|
|
548
|
+
const context = {
|
|
549
|
+
kind: 'method',
|
|
550
|
+
name: method,
|
|
551
|
+
static: false,
|
|
552
|
+
private: false,
|
|
553
|
+
addInitializer(initializer) {
|
|
554
|
+
initializer.call(synthetic);
|
|
555
|
+
},
|
|
556
|
+
};
|
|
557
|
+
const decorator = mode === 'stream' ? Remote({ name: method, mode: 'stream' }) : Remote(method);
|
|
558
|
+
decorator(prototype[method], context);
|
|
559
|
+
}
|
|
560
|
+
for (const [method, mode] of REMOTE_METHODS)
|
|
561
|
+
markRemote(method, mode);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workbench row: the workbench's Host surface, as Remote methods under
|
|
3
|
+
* the `harnessCompat` namespace, which the client panel calls. A method that
|
|
4
|
+
* needs a row that is off fails with the row's name.
|
|
5
|
+
* @module @kirkchinese/harness-forge/workbench
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import type { Disposer } from '../forge/contract.js';
|
|
9
|
+
import { type HarnessForge } from '../forge/service.js';
|
|
10
|
+
export declare const name = "harness-forge-workbench";
|
|
11
|
+
export declare const inject: string[];
|
|
12
|
+
/** The workbench row. */
|
|
13
|
+
export declare function apply(ctx: Context): void;
|
|
14
|
+
/** Start the workbench row on the shared service. Returns its teardown. */
|
|
15
|
+
export declare function startWorkbench(ctx: Context, forge: HarnessForge): Disposer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FORGE_SERVICE } from '../forge/service.js';
|
|
2
|
+
import { HarnessRemoteService } from './remote.js';
|
|
3
|
+
import { rowEffect } from '../forge/row.js';
|
|
4
|
+
export const name = 'harness-forge-workbench';
|
|
5
|
+
export const inject = [FORGE_SERVICE];
|
|
6
|
+
/** The workbench row. */
|
|
7
|
+
export function apply(ctx) {
|
|
8
|
+
rowEffect(ctx, 'workbench', forge => startWorkbench(ctx, forge));
|
|
9
|
+
}
|
|
10
|
+
/** Start the workbench row on the shared service. Returns its teardown. */
|
|
11
|
+
export function startWorkbench(ctx, forge) {
|
|
12
|
+
// The Remote service registers itself on the row's context and goes with it.
|
|
13
|
+
if (typeof ctx.provide === 'function')
|
|
14
|
+
new HarnessRemoteService(ctx, forge);
|
|
15
|
+
return () => { };
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** User-visible workbench settings. */
|
|
2
|
+
export interface HarnessSettings {
|
|
3
|
+
readonly schemaVersion: 1;
|
|
4
|
+
readonly discoveryRoots: readonly string[];
|
|
5
|
+
readonly autoDiscover: boolean;
|
|
6
|
+
readonly contextBudgetTokens?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Default roots: the folders where the harnesses keep their plugins and
|
|
10
|
+
* settings. Not the folder DSH was started from: that is arbitrary (often the
|
|
11
|
+
* home folder), and a workspace's own `.claude/` is read per session instead.
|
|
12
|
+
*/
|
|
13
|
+
export declare function defaultSettings(): HarnessSettings;
|
|
14
|
+
/** Settings file lives beside `state.json`/`receipts/`. */
|
|
15
|
+
export declare function settingsPathFor(statePath: string): string;
|
|
16
|
+
/** Read settings, falling back to defaults when the file is absent/invalid. */
|
|
17
|
+
export declare function readSettings(statePath: string): HarnessSettings;
|
|
18
|
+
/** Persist settings atomically. */
|
|
19
|
+
export declare function writeSettings(statePath: string, settings: HarnessSettings): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workbench settings persisted beside the installation ledger. Settings are a
|
|
3
|
+
* small, explicit JSON file rather than YAML so the UI and service agree on the
|
|
4
|
+
* same source of truth.
|
|
5
|
+
* @module @kirkchinese/harness-forge
|
|
6
|
+
*/
|
|
7
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { dirname, join, resolve } from 'node:path';
|
|
9
|
+
import { defaultDiscoveryRoots } from '@kirkchinese/harness-forge-core';
|
|
10
|
+
/**
|
|
11
|
+
* Default roots: the folders where the harnesses keep their plugins and
|
|
12
|
+
* settings. Not the folder DSH was started from: that is arbitrary (often the
|
|
13
|
+
* home folder), and a workspace's own `.claude/` is read per session instead.
|
|
14
|
+
*/
|
|
15
|
+
export function defaultSettings() {
|
|
16
|
+
return {
|
|
17
|
+
schemaVersion: 1,
|
|
18
|
+
discoveryRoots: defaultDiscoveryRoots(),
|
|
19
|
+
autoDiscover: true,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Settings file lives beside `state.json`/`receipts/`. */
|
|
23
|
+
export function settingsPathFor(statePath) {
|
|
24
|
+
return join(dirname(statePath), 'settings.json');
|
|
25
|
+
}
|
|
26
|
+
/** Read settings, falling back to defaults when the file is absent/invalid. */
|
|
27
|
+
export function readSettings(statePath) {
|
|
28
|
+
const defaults = defaultSettings();
|
|
29
|
+
let raw;
|
|
30
|
+
try {
|
|
31
|
+
raw = JSON.parse(readFileSync(settingsPathFor(statePath), 'utf8'));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return defaults;
|
|
35
|
+
}
|
|
36
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
37
|
+
return defaults;
|
|
38
|
+
const record = raw;
|
|
39
|
+
const roots = Array.isArray(record['discoveryRoots'])
|
|
40
|
+
? [...new Set(record['discoveryRoots'].filter((value) => typeof value === 'string' && value.trim().length > 0).map(value => resolve(value)))]
|
|
41
|
+
: defaults.discoveryRoots;
|
|
42
|
+
const autoDiscover = typeof record['autoDiscover'] === 'boolean' ? record['autoDiscover'] : defaults.autoDiscover;
|
|
43
|
+
const contextBudgetTokens = typeof record['contextBudgetTokens'] === 'number' && Number.isFinite(record['contextBudgetTokens']) && record['contextBudgetTokens'] > 0
|
|
44
|
+
? Math.round(record['contextBudgetTokens'])
|
|
45
|
+
: undefined;
|
|
46
|
+
return {
|
|
47
|
+
schemaVersion: 1,
|
|
48
|
+
discoveryRoots: roots.length > 0 ? roots : defaults.discoveryRoots,
|
|
49
|
+
autoDiscover,
|
|
50
|
+
...(contextBudgetTokens !== undefined ? { contextBudgetTokens } : {}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Persist settings atomically. */
|
|
54
|
+
export function writeSettings(statePath, settings) {
|
|
55
|
+
const path = settingsPathFor(statePath);
|
|
56
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
57
|
+
const temporary = `${path}.tmp`;
|
|
58
|
+
writeFileSync(temporary, `${JSON.stringify(settings, null, 2)}\n`, 'utf8');
|
|
59
|
+
renameSync(temporary, path);
|
|
60
|
+
}
|