@kirkchinese/harness-forge 0.0.0-stage → 0.4.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 +42 -2
- package/assets/icon.svg +12 -0
- package/cordis.patch.yml +28 -0
- package/lib/agents/presets.d.ts +91 -0
- package/lib/agents/presets.js +282 -0
- package/lib/agents/profiles.d.ts +58 -0
- package/lib/agents/profiles.js +278 -0
- package/lib/agents/row.d.ts +17 -0
- package/lib/agents/row.js +146 -0
- package/lib/client/styles.d.ts +8 -0
- package/lib/client/styles.js +89 -0
- package/lib/client/typert.d.ts +14 -0
- package/lib/client/typert.js +110 -0
- package/lib/client.js +22500 -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 +107 -0
- package/lib/dsh/host.js +214 -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 +231 -0
- package/lib/forge/contract.js +43 -0
- package/lib/forge/ledger.d.ts +143 -0
- package/lib/forge/ledger.js +733 -0
- package/lib/forge/live-mounts.d.ts +45 -0
- package/lib/forge/live-mounts.js +78 -0
- package/lib/forge/marketplace-install.d.ts +3 -0
- package/lib/forge/marketplace-install.js +64 -0
- package/lib/forge/npm.d.ts +31 -0
- package/lib/forge/npm.js +60 -0
- package/lib/forge/projects.d.ts +94 -0
- package/lib/forge/projects.js +336 -0
- package/lib/forge/receipts.d.ts +5 -0
- package/lib/forge/receipts.js +31 -0
- package/lib/forge/row.d.ts +32 -0
- package/lib/forge/row.js +59 -0
- package/lib/forge/service.d.ts +105 -0
- package/lib/forge/service.js +274 -0
- package/lib/forge/settings.d.ts +41 -0
- package/lib/forge/settings.js +115 -0
- package/lib/forge/state.d.ts +69 -0
- package/lib/forge/state.js +150 -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 +728 -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 +22 -0
- package/lib/hooks/broker/session-events.js +196 -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 +262 -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 +11 -0
- package/lib/hooks/condition.js +181 -0
- package/lib/hooks/config.d.ts +85 -0
- package/lib/hooks/config.js +150 -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 +14 -0
- package/lib/hooks/permissions.js +109 -0
- package/lib/hooks/process.d.ts +47 -0
- package/lib/hooks/process.js +134 -0
- package/lib/hooks/row.d.ts +17 -0
- package/lib/hooks/row.js +94 -0
- package/lib/hooks/runner.d.ts +85 -0
- package/lib/hooks/runner.js +293 -0
- package/lib/hooks/shell-commands.d.ts +19 -0
- package/lib/hooks/shell-commands.js +177 -0
- package/lib/hooks/shell.d.ts +43 -0
- package/lib/hooks/shell.js +126 -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 +364 -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 +36 -0
- package/lib/mcp/catalog.js +61 -0
- package/lib/mcp/mount.d.ts +75 -0
- package/lib/mcp/mount.js +217 -0
- package/lib/mcp/remote.d.ts +45 -0
- package/lib/mcp/remote.js +143 -0
- package/lib/mcp/row.d.ts +9 -0
- package/lib/mcp/row.js +131 -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 +227 -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 +32 -0
- package/lib/mods/service/turns.js +161 -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 +156 -0
- package/lib/opencode/convert.d.ts +53 -0
- package/lib/opencode/convert.js +255 -0
- package/lib/opencode/row.d.ts +9 -0
- package/lib/opencode/row.js +86 -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 +353 -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/port-gap.d.ts +30 -0
- package/lib/porting/port-gap.js +122 -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 +49 -0
- package/lib/porting/row.d.ts +16 -0
- package/lib/porting/row.js +25 -0
- package/lib/porting/verify-port.d.ts +53 -0
- package/lib/porting/verify-port.js +104 -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/claude.d.ts +29 -0
- package/lib/sessions/claude.js +83 -0
- package/lib/sessions/codex.d.ts +30 -0
- package/lib/sessions/codex.js +303 -0
- package/lib/sessions/opencode.d.ts +32 -0
- package/lib/sessions/opencode.js +320 -0
- package/lib/sessions/row.d.ts +14 -0
- package/lib/sessions/row.js +35 -0
- package/lib/shared/invocation.d.ts +169 -0
- package/lib/shared/invocation.js +325 -0
- package/lib/shared/render.d.ts +72 -0
- package/lib/shared/render.js +588 -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 +72 -0
- package/lib/skills/provider.js +340 -0
- package/lib/skills/row.d.ts +22 -0
- package/lib/skills/row.js +204 -0
- package/lib/workbench/adapter-coverage.d.ts +47 -0
- package/lib/workbench/adapter-coverage.js +102 -0
- package/lib/workbench/model-tools.d.ts +10 -0
- package/lib/workbench/model-tools.js +122 -0
- package/lib/workbench/overview.d.ts +103 -0
- package/lib/workbench/overview.js +159 -0
- package/lib/workbench/remote.d.ts +118 -0
- package/lib/workbench/remote.js +422 -0
- package/lib/workbench/row.d.ts +15 -0
- package/lib/workbench/row.js +16 -0
- package/lib/workbench/settings.d.ts +15 -0
- package/lib/workbench/settings.js +56 -0
- package/lib/workbench/workbench.d.ts +100 -0
- package/lib/workbench/workbench.js +260 -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 +6 -0
- package/package.json +246 -3
- package/runtime/opencode-host.mjs +270 -0
- package/skills/harness-forge/SKILL.md +47 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Porting a gap: Harness Forge writes the brief (see the core's
|
|
3
|
+
* `portBrief`), puts the working protocol before it (`prompt.ts`) and hands
|
|
4
|
+
* it to DSH's own creation mode, a new session on the
|
|
5
|
+
* `cordis` preset that has the dsh-doc skill, runtime inspection and the
|
|
6
|
+
* plugin manager. The authoring, testing and installing are that agent's.
|
|
7
|
+
* @module @kirkchinese/harness-forge/porting
|
|
8
|
+
*/
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
11
|
+
import { dirname, join, resolve } from 'node:path';
|
|
12
|
+
import { absolutePath, detectLicense, portBrief } from '@kirkchinese/harness-forge-core';
|
|
13
|
+
import { dshService } from '../dsh/host.js';
|
|
14
|
+
import { portPrompt } from './prompt.js';
|
|
15
|
+
/** The preset of DSH's creation mode ("Let the agent create a plugin" in the Plugin Manager). */
|
|
16
|
+
export const CREATOR_PRESET = 'cordis';
|
|
17
|
+
/** Most files a brief lists for one part. */
|
|
18
|
+
const FILE_LIMIT = 200;
|
|
19
|
+
const SKIPPED_DIRS = new Set(['node_modules', '.git']);
|
|
20
|
+
/** The session title for a brief: its heading, without the Markdown marker DSH would otherwise show in the sidebar. */
|
|
21
|
+
export function briefTitle(brief) {
|
|
22
|
+
return (brief.split('\n', 1)[0] ?? '').replace(/^#+\s*/u, '').trim();
|
|
23
|
+
}
|
|
24
|
+
function filesUnder(path, out) {
|
|
25
|
+
if (out.length >= FILE_LIMIT || !existsSync(path))
|
|
26
|
+
return;
|
|
27
|
+
const stat = statSync(path);
|
|
28
|
+
if (stat.isFile()) {
|
|
29
|
+
if (!out.includes(path))
|
|
30
|
+
out.push(path);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!stat.isDirectory())
|
|
34
|
+
return;
|
|
35
|
+
for (const entry of readdirSync(path, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
36
|
+
if (out.length >= FILE_LIMIT)
|
|
37
|
+
return;
|
|
38
|
+
if (entry.isDirectory() && SKIPPED_DIRS.has(entry.name))
|
|
39
|
+
continue;
|
|
40
|
+
filesUnder(join(path, entry.name), out);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The files of one part on disk: its own files, and the whole directory of a
|
|
45
|
+
* skill or a code entry, whose neighbours it runs. A part declared in the
|
|
46
|
+
* plugin's manifest itself lists the manifest.
|
|
47
|
+
*/
|
|
48
|
+
export function partFiles(plugin, component) {
|
|
49
|
+
const out = [];
|
|
50
|
+
const paths = [component.path];
|
|
51
|
+
switch (component.kind) {
|
|
52
|
+
case 'skill':
|
|
53
|
+
paths.push(component.resourceBase, component.bodyPath);
|
|
54
|
+
break;
|
|
55
|
+
case 'command':
|
|
56
|
+
case 'agent':
|
|
57
|
+
paths.push(component.bodyPath);
|
|
58
|
+
break;
|
|
59
|
+
case 'hooks':
|
|
60
|
+
paths.push(component.configPath, ...component.modules);
|
|
61
|
+
break;
|
|
62
|
+
case 'code':
|
|
63
|
+
if (component.entryPath !== undefined)
|
|
64
|
+
paths.push(component.entryPath, dirname(absolutePath(plugin.root, component.entryPath)));
|
|
65
|
+
break;
|
|
66
|
+
case 'ui':
|
|
67
|
+
paths.push(component.specPath);
|
|
68
|
+
break;
|
|
69
|
+
case 'settings':
|
|
70
|
+
paths.push(...component.files);
|
|
71
|
+
break;
|
|
72
|
+
default: break;
|
|
73
|
+
}
|
|
74
|
+
for (const path of paths) {
|
|
75
|
+
if (path === undefined || path.length === 0)
|
|
76
|
+
continue;
|
|
77
|
+
const absolute = absolutePath(plugin.root, path);
|
|
78
|
+
// The plugin's root is not one part's files.
|
|
79
|
+
if (resolve(absolute) !== resolve(plugin.root))
|
|
80
|
+
filesUnder(absolute, out);
|
|
81
|
+
}
|
|
82
|
+
if (!out.includes(plugin.ref.manifestPath) && existsSync(plugin.ref.manifestPath))
|
|
83
|
+
out.push(plugin.ref.manifestPath);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/** The brief for one part of a plugin, or a failure naming what is missing. */
|
|
87
|
+
export function briefFor(plugin, gaps, componentId) {
|
|
88
|
+
const component = plugin.components.find(item => item.id === componentId);
|
|
89
|
+
if (component === undefined)
|
|
90
|
+
throw new Error(`${plugin.name} has no part ${componentId}`);
|
|
91
|
+
const license = plugin.license ?? detectLicense(plugin.root);
|
|
92
|
+
return portBrief({ plugin, component, gaps, files: partFiles(plugin, component), ...(license !== undefined ? { license } : {}) });
|
|
93
|
+
}
|
|
94
|
+
/** The first message of a part's port session: the protocol, then the brief (see `prompt.ts`). */
|
|
95
|
+
export function taskFor(plugin, gaps, componentId, language) {
|
|
96
|
+
const brief = briefFor(plugin, gaps, componentId);
|
|
97
|
+
const component = plugin.components.find(item => item.id === componentId);
|
|
98
|
+
return portPrompt({ plugin, component, brief, ...(language !== undefined && language.length > 0 ? { language } : {}) });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Start a creation-mode session and send it the task, as the Plugin
|
|
102
|
+
* Manager's creation entry and a typed message would.
|
|
103
|
+
* @param title - the session's name; the task's first line when absent.
|
|
104
|
+
* @returns the new session's id.
|
|
105
|
+
*/
|
|
106
|
+
export async function startCreatorSession(ctx, task, location = {}, title = briefTitle(task)) {
|
|
107
|
+
const controller = dshService(ctx, 'sessionController');
|
|
108
|
+
if (controller === undefined)
|
|
109
|
+
throw new Error('this DSH profile composes no session controller, so no creation session can be started; copy the brief into a session in creation mode instead');
|
|
110
|
+
const presets = dshService(ctx, 'agentPresets');
|
|
111
|
+
const creator = presets?.list === undefined ? undefined : (await presets.list()).find(preset => preset.id === CREATOR_PRESET);
|
|
112
|
+
if (presets?.list !== undefined && (creator === undefined || creator.broken !== undefined)) {
|
|
113
|
+
throw new Error(`creation mode (agent preset "${CREATOR_PRESET}") is ${creator === undefined ? 'not in this DSH profile' : 'unavailable in this DSH profile'}; copy the brief into a session instead`);
|
|
114
|
+
}
|
|
115
|
+
const where = location.workspaceId !== undefined ? { workspaceId: location.workspaceId } : location.cwd !== undefined ? { cwd: location.cwd } : {};
|
|
116
|
+
const { sessionId } = await controller.create({ ...where, agentPreset: CREATOR_PRESET });
|
|
117
|
+
// Named before the task is sent, so the sidebar shows the brief's heading rather than the protocol's first line. A title the host refuses only leaves DSH's own.
|
|
118
|
+
if (title.length > 0)
|
|
119
|
+
await controller.rename?.({ sessionId, title }).catch(() => undefined);
|
|
120
|
+
await controller.prompt({ requestId: randomUUID(), sessionId, mode: 'queue', content: [{ type: 'text', text: task }] }, AbortSignal.timeout(60_000));
|
|
121
|
+
return { sessionId };
|
|
122
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** One part being ported, or ported and verified. */
|
|
2
|
+
export interface PortRecord {
|
|
3
|
+
readonly pluginId: string;
|
|
4
|
+
readonly componentId: string;
|
|
5
|
+
/** The creation-mode session working on it; absent when it was verified without one. */
|
|
6
|
+
readonly sessionId?: string;
|
|
7
|
+
readonly startedAt?: string;
|
|
8
|
+
/** When `harness_verify_port` last confirmed an adapter covers the part. */
|
|
9
|
+
readonly verifiedAt?: string;
|
|
10
|
+
/** The package that covered it then. */
|
|
11
|
+
readonly adapter?: string;
|
|
12
|
+
}
|
|
13
|
+
/** What the Gaps screen shows for one part. */
|
|
14
|
+
export type PortState = 'in-progress' | 'verified';
|
|
15
|
+
/** The state a record stands for. */
|
|
16
|
+
export declare function stateOf(record: PortRecord): PortState;
|
|
17
|
+
/** The per-profile store of port sessions. */
|
|
18
|
+
export declare class PortSessions {
|
|
19
|
+
readonly path: string;
|
|
20
|
+
/** @param statePath - the ledger file; `ports.json` lives beside it. */
|
|
21
|
+
constructor(statePath: string);
|
|
22
|
+
/** Every record; an absent or unreadable file holds none. */
|
|
23
|
+
list(): PortRecord[];
|
|
24
|
+
get(pluginId: string, componentId: string): PortRecord | undefined;
|
|
25
|
+
private write;
|
|
26
|
+
private put;
|
|
27
|
+
/** A session started porting the part: it is in progress again, whatever was verified before. */
|
|
28
|
+
started(pluginId: string, componentId: string, sessionId: string, at?: Date): PortRecord;
|
|
29
|
+
/** `harness_verify_port` confirmed `adapter` covers the part; the session that ported it stays linked. */
|
|
30
|
+
verified(pluginId: string, componentId: string, adapter: string, at?: Date): PortRecord;
|
|
31
|
+
/** A verification failed: a confirmation recorded before no longer holds, the session (if any) is in progress. */
|
|
32
|
+
unverified(pluginId: string, componentId: string): void;
|
|
33
|
+
forget(pluginId: string, componentId: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Drop the sessions that no longer exist: an in-progress record goes (the
|
|
36
|
+
* part can be ported again), a verified one keeps its confirmation without
|
|
37
|
+
* the session link.
|
|
38
|
+
* @param exists - whether a session id is still a session of this DSH.
|
|
39
|
+
*/
|
|
40
|
+
prune(exists: (sessionId: string) => boolean): PortRecord[];
|
|
41
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which creation-mode session ports which part, and whether
|
|
3
|
+
* `harness_verify_port` has confirmed it: kept in `ports.json` beside the
|
|
4
|
+
* ledger (per DSH profile), so the Gaps screen shows the progress after a
|
|
5
|
+
* reload. A record whose session no longer exists is dropped when the screen
|
|
6
|
+
* reads it, so the part can be ported again.
|
|
7
|
+
* @module @kirkchinese/harness-forge/porting
|
|
8
|
+
*/
|
|
9
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
/** The state a record stands for. */
|
|
12
|
+
export function stateOf(record) {
|
|
13
|
+
return record.verifiedAt !== undefined ? 'verified' : 'in-progress';
|
|
14
|
+
}
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
const record = value;
|
|
17
|
+
return typeof record === 'object' && record !== null && typeof record.pluginId === 'string' && typeof record.componentId === 'string';
|
|
18
|
+
}
|
|
19
|
+
const same = (record, pluginId, componentId) => record.pluginId === pluginId && record.componentId === componentId;
|
|
20
|
+
/** The per-profile store of port sessions. */
|
|
21
|
+
export class PortSessions {
|
|
22
|
+
path;
|
|
23
|
+
/** @param statePath - the ledger file; `ports.json` lives beside it. */
|
|
24
|
+
constructor(statePath) {
|
|
25
|
+
this.path = join(dirname(statePath), 'ports.json');
|
|
26
|
+
}
|
|
27
|
+
/** Every record; an absent or unreadable file holds none. */
|
|
28
|
+
list() {
|
|
29
|
+
try {
|
|
30
|
+
const raw = JSON.parse(readFileSync(this.path, 'utf8'));
|
|
31
|
+
return Array.isArray(raw?.ports) ? raw.ports.filter(isRecord) : [];
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
get(pluginId, componentId) {
|
|
38
|
+
return this.list().find(record => same(record, pluginId, componentId));
|
|
39
|
+
}
|
|
40
|
+
write(ports) {
|
|
41
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
42
|
+
const temporary = `${this.path}.tmp`;
|
|
43
|
+
writeFileSync(temporary, `${JSON.stringify({ schemaVersion: 1, ports }, null, 2)}\n`, 'utf8');
|
|
44
|
+
renameSync(temporary, this.path);
|
|
45
|
+
}
|
|
46
|
+
put(record) {
|
|
47
|
+
this.write([...this.list().filter(item => !same(item, record.pluginId, record.componentId)), record]);
|
|
48
|
+
return record;
|
|
49
|
+
}
|
|
50
|
+
/** A session started porting the part: it is in progress again, whatever was verified before. */
|
|
51
|
+
started(pluginId, componentId, sessionId, at = new Date()) {
|
|
52
|
+
return this.put({ pluginId, componentId, sessionId, startedAt: at.toISOString() });
|
|
53
|
+
}
|
|
54
|
+
/** `harness_verify_port` confirmed `adapter` covers the part; the session that ported it stays linked. */
|
|
55
|
+
verified(pluginId, componentId, adapter, at = new Date()) {
|
|
56
|
+
const current = this.get(pluginId, componentId);
|
|
57
|
+
return this.put({ ...current, pluginId, componentId, verifiedAt: at.toISOString(), adapter });
|
|
58
|
+
}
|
|
59
|
+
/** A verification failed: a confirmation recorded before no longer holds, the session (if any) is in progress. */
|
|
60
|
+
unverified(pluginId, componentId) {
|
|
61
|
+
const current = this.get(pluginId, componentId);
|
|
62
|
+
if (current?.verifiedAt === undefined)
|
|
63
|
+
return;
|
|
64
|
+
const { verifiedAt: _verifiedAt, adapter: _adapter, ...rest } = current;
|
|
65
|
+
if (rest.sessionId === undefined)
|
|
66
|
+
this.forget(pluginId, componentId);
|
|
67
|
+
else
|
|
68
|
+
this.put(rest);
|
|
69
|
+
}
|
|
70
|
+
forget(pluginId, componentId) {
|
|
71
|
+
const ports = this.list();
|
|
72
|
+
const kept = ports.filter(item => !same(item, pluginId, componentId));
|
|
73
|
+
if (kept.length !== ports.length)
|
|
74
|
+
this.write(kept);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Drop the sessions that no longer exist: an in-progress record goes (the
|
|
78
|
+
* part can be ported again), a verified one keeps its confirmation without
|
|
79
|
+
* the session link.
|
|
80
|
+
* @param exists - whether a session id is still a session of this DSH.
|
|
81
|
+
*/
|
|
82
|
+
prune(exists) {
|
|
83
|
+
const ports = this.list();
|
|
84
|
+
let changed = false;
|
|
85
|
+
const kept = ports.flatMap((record) => {
|
|
86
|
+
if (record.sessionId === undefined || exists(record.sessionId))
|
|
87
|
+
return [record];
|
|
88
|
+
changed = true;
|
|
89
|
+
if (record.verifiedAt === undefined)
|
|
90
|
+
return [];
|
|
91
|
+
const { sessionId: _sessionId, startedAt: _startedAt, ...rest } = record;
|
|
92
|
+
return [rest];
|
|
93
|
+
});
|
|
94
|
+
if (changed)
|
|
95
|
+
this.write(kept);
|
|
96
|
+
return kept;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first message of a creation-mode port session: the working protocol
|
|
3
|
+
* (ask once, build, verify, report), then the part's brief. The protocol is
|
|
4
|
+
* the same for every part and lives only here; what is specific to the part
|
|
5
|
+
* (its files, gaps, the questions it leaves open, its acceptance criteria) is
|
|
6
|
+
* the brief's. Written for the model, in English; it tells the agent to talk
|
|
7
|
+
* to the user in their own language.
|
|
8
|
+
* @module @kirkchinese/harness-forge/porting
|
|
9
|
+
*/
|
|
10
|
+
import { type ForeignComponent, type ForeignPlugin } from '@kirkchinese/harness-forge-core';
|
|
11
|
+
/** The model tool that confirms an adapter covers the part (see `verify-port.ts`). */
|
|
12
|
+
export declare const VERIFY_TOOL = "harness_verify_port";
|
|
13
|
+
/** What the prompt is written for. */
|
|
14
|
+
export interface PortPromptInput {
|
|
15
|
+
readonly plugin: Pick<ForeignPlugin, 'id' | 'name'>;
|
|
16
|
+
readonly component: Pick<ForeignComponent, 'id' | 'name'>;
|
|
17
|
+
/** The part's brief (`portBrief`), appended after the protocol. */
|
|
18
|
+
readonly brief: string;
|
|
19
|
+
/** The user's interface language (`en`, `zh`, …), when the browser said. */
|
|
20
|
+
readonly language?: string;
|
|
21
|
+
}
|
|
22
|
+
/** The protocol and the brief, as the session's first message. */
|
|
23
|
+
export declare function portPrompt(input: PortPromptInput): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first message of a creation-mode port session: the working protocol
|
|
3
|
+
* (ask once, build, verify, report), then the part's brief. The protocol is
|
|
4
|
+
* the same for every part and lives only here; what is specific to the part
|
|
5
|
+
* (its files, gaps, the questions it leaves open, its acceptance criteria) is
|
|
6
|
+
* the brief's. Written for the model, in English; it tells the agent to talk
|
|
7
|
+
* to the user in their own language.
|
|
8
|
+
* @module @kirkchinese/harness-forge/porting
|
|
9
|
+
*/
|
|
10
|
+
import { adapterPackageName, defaultAdapterDir } from '@kirkchinese/harness-forge-core';
|
|
11
|
+
/** The model tool that confirms an adapter covers the part (see `verify-port.ts`). */
|
|
12
|
+
export const VERIFY_TOOL = 'harness_verify_port';
|
|
13
|
+
/** Language names for the user's interface language, as the prompt names it. */
|
|
14
|
+
const LANGUAGES = { en: 'English', zh: 'Chinese (简体中文)' };
|
|
15
|
+
/** The language line: the interface language when known, else whatever the user writes in. */
|
|
16
|
+
function languageLine(language) {
|
|
17
|
+
const named = language === undefined ? undefined : LANGUAGES[language.split('-')[0].toLowerCase()] ?? language;
|
|
18
|
+
return named === undefined
|
|
19
|
+
? 'Talk to the user in the language they write in.'
|
|
20
|
+
: `Talk to the user in ${named}, the language of their DSH interface, unless they write in another language.`;
|
|
21
|
+
}
|
|
22
|
+
/** The protocol and the brief, as the session's first message. */
|
|
23
|
+
export function portPrompt(input) {
|
|
24
|
+
const { plugin, component } = input;
|
|
25
|
+
const packageName = adapterPackageName(plugin, component);
|
|
26
|
+
const verifyArgs = JSON.stringify({ pluginId: plugin.id, componentId: component.id });
|
|
27
|
+
const protocol = [
|
|
28
|
+
`You are in DSH's creation mode. Harness Forge asks you to port the part "${component.name}" of ${plugin.name} to DSH as a local adapter plugin \`${packageName}\`. The brief below has the facts; this is how to work. ${languageLine(input.language)}`,
|
|
29
|
+
'',
|
|
30
|
+
'## Protocol',
|
|
31
|
+
'',
|
|
32
|
+
'1. **Ask once, first.** Read the brief and the original\'s files, then send the user ONE concise message with numbered questions, each with a default so they can just reply "ok". Ask:',
|
|
33
|
+
` - where to put the adapter's source; default \`${defaultAdapterDir(packageName)}\`, because it is outside every workspace and the original plugin, so neither a workspace cleanup nor an update of the original touches it, and the local install keeps pointing at it;`,
|
|
34
|
+
' - each question under "Questions for the user" in the brief that reading the files did not settle.',
|
|
35
|
+
' Never ask what you can look up (DSH APIs, slot names, file contents): look it up. Write no file before the answer.',
|
|
36
|
+
'2. **Build without further questions.** Load the `dsh-doc` skill and follow it. Scaffold the package in the agreed directory, implement it reusing the original\'s code and data where possible, install it into the current profile with `plugin_manager` `install_bundle` (absolute directory) and make sure it is enabled. Ask again only when blocked on a choice only the user can make.',
|
|
37
|
+
' Fallback: should `install_bundle` come back `"application": "failed"` with "pnpm printed nothing … and was terminated", call it once more with the same directory (a pnpm that did not exit; the second call completes). Do not run pnpm or `dsh plugin` from the shell on the running profile instead.',
|
|
38
|
+
'3. **Verify before you report.** All of these must pass:',
|
|
39
|
+
' a. The adapter loaded without errors: `plugin_manager` `list_bundles` shows it enabled with no `error`, and `cordis_inspect_*` shows what it registered.',
|
|
40
|
+
' b. Each behaviour the acceptance criteria name happens: exercise it and observe the result (the tool\'s answer, the command\'s output, the hook acting, the surface\'s value).',
|
|
41
|
+
` c. \`${VERIFY_TOOL}\` with \`${verifyArgs}\` answers \`"covered": true\`.`,
|
|
42
|
+
' When a check fails, fix the cause and run all three again.',
|
|
43
|
+
'4. **Report.** Only after 3 passed: say what now works, with the evidence (what each check showed, including the `' + VERIFY_TOOL + '` answer), where the source is, and what still differs from the original. If you cannot close the gap, say exactly what blocks it, what you tried, and what the user can do.',
|
|
44
|
+
'',
|
|
45
|
+
'---',
|
|
46
|
+
'',
|
|
47
|
+
];
|
|
48
|
+
return `${protocol.join('\n')}\n${input.brief}`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The porter row: porting a plugin part Harness Forge cannot run. It writes
|
|
3
|
+
* the part's brief and hands it to DSH's own creation mode, which authors,
|
|
4
|
+
* tests and installs the adapter. With the row off, the workbench offers no
|
|
5
|
+
* porting.
|
|
6
|
+
* @module @kirkchinese/harness-forge/porter
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { Disposer } from '../forge/contract.js';
|
|
10
|
+
import { type HarnessForge } from '../forge/service.js';
|
|
11
|
+
export declare const name = "harness-forge-porter";
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
/** The porter row. */
|
|
14
|
+
export declare function apply(ctx: Context): void;
|
|
15
|
+
/** Start the porter row on the shared service. Returns its teardown. */
|
|
16
|
+
export declare function startPorter(ctx: Context, forge: HarnessForge): Disposer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FORGE_SERVICE } from '../forge/service.js';
|
|
2
|
+
import { briefFor, briefTitle, startCreatorSession, taskFor } from './port-gap.js';
|
|
3
|
+
import { PortSessions } from './port-sessions.js';
|
|
4
|
+
import { rowEffect } from '../forge/row.js';
|
|
5
|
+
export const name = 'harness-forge-porter';
|
|
6
|
+
export const inject = [FORGE_SERVICE];
|
|
7
|
+
/** The porter row. */
|
|
8
|
+
export function apply(ctx) {
|
|
9
|
+
rowEffect(ctx, 'porter', forge => startPorter(ctx, forge));
|
|
10
|
+
}
|
|
11
|
+
/** Start the porter row on the shared service. Returns its teardown. */
|
|
12
|
+
export function startPorter(ctx, forge) {
|
|
13
|
+
const sessions = new PortSessions(forge.statePath);
|
|
14
|
+
const api = {
|
|
15
|
+
brief: (plugin, gaps, componentId) => briefFor(plugin, gaps, componentId),
|
|
16
|
+
task: (plugin, gaps, componentId, language) => taskFor(plugin, gaps, componentId, language),
|
|
17
|
+
port: async (plugin, gaps, componentId, location, language) => {
|
|
18
|
+
const task = taskFor(plugin, gaps, componentId, language);
|
|
19
|
+
const started = await startCreatorSession(ctx, task, location, briefTitle(briefFor(plugin, gaps, componentId)));
|
|
20
|
+
sessions.started(plugin.id, componentId, started.sessionId);
|
|
21
|
+
return started;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return forge.provide('porter', api);
|
|
25
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `harness_verify_port`: whether an installed adapter now covers a plugin
|
|
3
|
+
* part. It reads the adapter packages again, asks DSH's plugin manager whether
|
|
4
|
+
* that package is enabled and its plugins started without a fault, and records
|
|
5
|
+
* the answer for the Gaps screen ("Done — verified", or back to in progress).
|
|
6
|
+
* The creation-mode agent calls it before it reports a port done.
|
|
7
|
+
* @module @kirkchinese/harness-forge/porting
|
|
8
|
+
*/
|
|
9
|
+
import { type ForeignPlugin } from '@kirkchinese/harness-forge-core';
|
|
10
|
+
import { type AdapterCoverage } from '../workbench/overview.js';
|
|
11
|
+
import { type PluginManagerLike } from '../workbench/adapter-coverage.js';
|
|
12
|
+
import { PortSessions, type PortRecord } from './port-sessions.js';
|
|
13
|
+
import type { HarnessForge } from '../forge/service.js';
|
|
14
|
+
import type { Workbench } from '../workbench/workbench.js';
|
|
15
|
+
export type { PluginManagerLike };
|
|
16
|
+
/** What verification reads. */
|
|
17
|
+
export interface VerifyDeps {
|
|
18
|
+
findPlugin(id: string): {
|
|
19
|
+
readonly plugin: ForeignPlugin;
|
|
20
|
+
};
|
|
21
|
+
adapters(): readonly AdapterCoverage[];
|
|
22
|
+
/** Absent when the profile composes no plugin manager. */
|
|
23
|
+
readonly pluginManager: PluginManagerLike | undefined;
|
|
24
|
+
readonly sessions: PortSessions;
|
|
25
|
+
}
|
|
26
|
+
export interface PortCheck {
|
|
27
|
+
readonly check: 'declared' | 'enabled' | 'loaded';
|
|
28
|
+
readonly ok: boolean;
|
|
29
|
+
readonly detail: string;
|
|
30
|
+
}
|
|
31
|
+
/** The tool's answer. */
|
|
32
|
+
export interface PortVerification {
|
|
33
|
+
/** All checks passed: the Gaps screen now shows the part as done. */
|
|
34
|
+
readonly covered: boolean;
|
|
35
|
+
readonly pluginId: string;
|
|
36
|
+
readonly componentId: string;
|
|
37
|
+
readonly plugin: string;
|
|
38
|
+
readonly part: string;
|
|
39
|
+
readonly adapter?: string;
|
|
40
|
+
readonly checks: readonly PortCheck[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify that an adapter covers one part, and record the answer.
|
|
44
|
+
* @param callerSession - the session that asked, linked to the part when no port session was recorded for it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function verifyPort(deps: VerifyDeps, pluginId: string, componentId: string, callerSession?: string): Promise<PortVerification>;
|
|
47
|
+
/** Verification against this Harness Forge and the DSH it runs in. */
|
|
48
|
+
export declare function forgeVerifyDeps(forge: HarnessForge, workbench: Workbench): VerifyDeps;
|
|
49
|
+
/**
|
|
50
|
+
* The recorded port sessions, without those whose session was deleted (when
|
|
51
|
+
* the profile composes a session controller that can list them).
|
|
52
|
+
*/
|
|
53
|
+
export declare function livePorts(forge: HarnessForge): Promise<PortRecord[]>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `harness_verify_port`: whether an installed adapter now covers a plugin
|
|
3
|
+
* part. It reads the adapter packages again, asks DSH's plugin manager whether
|
|
4
|
+
* that package is enabled and its plugins started without a fault, and records
|
|
5
|
+
* the answer for the Gaps screen ("Done — verified", or back to in progress).
|
|
6
|
+
* The creation-mode agent calls it before it reports a port done.
|
|
7
|
+
* @module @kirkchinese/harness-forge/porting
|
|
8
|
+
*/
|
|
9
|
+
import { adapterPackageName } from '@kirkchinese/harness-forge-core';
|
|
10
|
+
import { coveringAdapter } from '../workbench/overview.js';
|
|
11
|
+
import { bundleState } from '../workbench/adapter-coverage.js';
|
|
12
|
+
import { PortSessions } from './port-sessions.js';
|
|
13
|
+
import { dshService } from '../dsh/host.js';
|
|
14
|
+
const check = (name, ok, detail) => ({ check: name, ok, detail });
|
|
15
|
+
/** Whether the package's plugins started: every row it declares has a live entry, active, without a startup failure. */
|
|
16
|
+
async function loaded(manager, rows) {
|
|
17
|
+
if (rows.length === 0)
|
|
18
|
+
return check('loaded', true, 'its bundle declares no plugin rows, so nothing has to start');
|
|
19
|
+
const entries = new Map((await manager.listPlugins()).map(entry => [entry.entryId, entry]));
|
|
20
|
+
const problems = [];
|
|
21
|
+
for (const row of rows) {
|
|
22
|
+
const entry = row.entryId === undefined ? undefined : entries.get(row.entryId);
|
|
23
|
+
if (entry === undefined)
|
|
24
|
+
problems.push(`row "${row.rowId}" has no running entry`);
|
|
25
|
+
else if (entry.diagnostic !== undefined)
|
|
26
|
+
problems.push(`row "${row.rowId}" failed to start: ${entry.diagnostic}`);
|
|
27
|
+
else if (!entry.enabled)
|
|
28
|
+
problems.push(`row "${row.rowId}" is disabled`);
|
|
29
|
+
else if (entry.fiberPhase !== 'active')
|
|
30
|
+
problems.push(`row "${row.rowId}" is ${entry.fiberPhase ?? 'not running'}`);
|
|
31
|
+
}
|
|
32
|
+
return problems.length === 0
|
|
33
|
+
? check('loaded', true, `all ${String(rows.length)} plugin row(s) of its bundle are active, without startup failures`)
|
|
34
|
+
: check('loaded', false, problems.join('; '));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Verify that an adapter covers one part, and record the answer.
|
|
38
|
+
* @param callerSession - the session that asked, linked to the part when no port session was recorded for it.
|
|
39
|
+
*/
|
|
40
|
+
export async function verifyPort(deps, pluginId, componentId, callerSession) {
|
|
41
|
+
const { plugin } = deps.findPlugin(pluginId);
|
|
42
|
+
const component = plugin.components.find(item => item.id === componentId);
|
|
43
|
+
if (component === undefined)
|
|
44
|
+
throw new Error(`${plugin.name} has no part ${componentId}; its parts are ${plugin.components.map(item => item.id).join(', ')}`);
|
|
45
|
+
const base = { pluginId, componentId, plugin: plugin.name, part: component.name };
|
|
46
|
+
const adapters = deps.adapters();
|
|
47
|
+
const name = coveringAdapter(plugin, component, adapters);
|
|
48
|
+
const checks = [];
|
|
49
|
+
if (name === undefined) {
|
|
50
|
+
checks.push(check('declared', false, `no package installed in this DSH profile declares this part: its package.json needs "harnessForge": { "ports": [${JSON.stringify({ plugin: plugin.name, component: component.name })}] } (or the package is named ${adapterPackageName(plugin, component)}), and it must be installed with plugin_manager install_bundle`));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const dir = adapters.find(adapter => adapter.name === name)?.dir;
|
|
54
|
+
checks.push(check('declared', true, `${name}${dir !== undefined ? ` (${dir})` : ''} declares it`));
|
|
55
|
+
if (deps.pluginManager === undefined) {
|
|
56
|
+
checks.push(check('enabled', false, 'this DSH profile composes no plugin manager, so whether the adapter is enabled cannot be checked'));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// The criterion the workbench overview counts an adapter by (`bundleState`).
|
|
60
|
+
const status = bundleState(name, await deps.pluginManager.listBundles());
|
|
61
|
+
if (status.state === 'unlisted')
|
|
62
|
+
checks.push(check('enabled', false, `${name} is on disk but DSH does not list it as an installed bundle: install it with plugin_manager install_bundle (a link left by a failed install does not count), and check that its package.json declares a bundle (dsh-doc references/host-plugin.md)`));
|
|
63
|
+
else if (status.state === 'off')
|
|
64
|
+
checks.push(check('enabled', false, `${name} is installed but switched off: enable it with plugin_manager set_bundle`));
|
|
65
|
+
else if (status.state === 'broken')
|
|
66
|
+
checks.push(check('enabled', false, `${name} is enabled but its bundle cannot load: ${status.error.code}${status.error.diagnostic !== undefined ? ` — ${status.error.diagnostic}` : ''}`));
|
|
67
|
+
else {
|
|
68
|
+
checks.push(check('enabled', true, `${name} is enabled`));
|
|
69
|
+
checks.push(await loaded(deps.pluginManager, status.bundle.rows));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const covered = checks.every(item => item.ok);
|
|
74
|
+
if (covered && name !== undefined) {
|
|
75
|
+
if (deps.sessions.get(pluginId, componentId) === undefined && callerSession !== undefined)
|
|
76
|
+
deps.sessions.started(pluginId, componentId, callerSession);
|
|
77
|
+
deps.sessions.verified(pluginId, componentId, name);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
deps.sessions.unverified(pluginId, componentId);
|
|
81
|
+
}
|
|
82
|
+
return { covered, ...base, ...(name !== undefined ? { adapter: name } : {}), checks };
|
|
83
|
+
}
|
|
84
|
+
/** Verification against this Harness Forge and the DSH it runs in. */
|
|
85
|
+
export function forgeVerifyDeps(forge, workbench) {
|
|
86
|
+
return {
|
|
87
|
+
findPlugin: id => workbench.findPlugin(id),
|
|
88
|
+
adapters: () => workbench.adapters(),
|
|
89
|
+
pluginManager: dshService(forge.ctx, 'pluginManager'),
|
|
90
|
+
sessions: new PortSessions(forge.statePath),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The recorded port sessions, without those whose session was deleted (when
|
|
95
|
+
* the profile composes a session controller that can list them).
|
|
96
|
+
*/
|
|
97
|
+
export async function livePorts(forge) {
|
|
98
|
+
const sessions = new PortSessions(forge.statePath);
|
|
99
|
+
const controller = dshService(forge.ctx, 'sessionController');
|
|
100
|
+
if (controller?.list === undefined)
|
|
101
|
+
return sessions.list();
|
|
102
|
+
const existing = new Set((await controller.list({}, AbortSignal.timeout(30_000))).items.map(item => item.sessionId));
|
|
103
|
+
return sessions.prune(id => existing.has(id));
|
|
104
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset row standing in for DSH's `tool-fs-search` when an agent's tool list
|
|
3
|
+
* keeps only one of `glob` and `grep`: DSH's row registers both and has no
|
|
4
|
+
* switch, and `tools.restrict` cannot hide a tool a preset row registers. This
|
|
5
|
+
* row registers the listed one with DSH's own implementation and caps.
|
|
6
|
+
* @module @kirkchinese/harness-forge/preset-fs-search
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
/** The listed tools, and DSH's `tool-fs-search` config of the row this one replaces. */
|
|
10
|
+
export interface Config {
|
|
11
|
+
tools: Array<'glob' | 'grep'>;
|
|
12
|
+
sampleOverCapGlobResults?: boolean;
|
|
13
|
+
globMaxResults?: number;
|
|
14
|
+
grepMaxMatches?: number;
|
|
15
|
+
grepMaxLineBytes?: number;
|
|
16
|
+
searchMetaMaxBytes?: number;
|
|
17
|
+
rawOutputMaxBytes?: number;
|
|
18
|
+
graceMs?: number;
|
|
19
|
+
stderrMaxBytes?: number;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare const name = "harness-forge-fs-search";
|
|
23
|
+
/** What DSH's search tools need. */
|
|
24
|
+
export declare const inject: string[];
|
|
25
|
+
export declare function apply(ctx: Context, config: Config): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const name = 'harness-forge-fs-search';
|
|
2
|
+
/** What DSH's search tools need. */
|
|
3
|
+
export const inject = ['tools', 'systemPrompt', 'subprocess', 'workingDirectory'];
|
|
4
|
+
export async function apply(ctx, config) {
|
|
5
|
+
const search = await import('@deepseek-ai/dsh-tool-fs-search');
|
|
6
|
+
const shared = {
|
|
7
|
+
maxMetaBytes: config.searchMetaMaxBytes ?? search.SEARCH_META_MAX_BYTES,
|
|
8
|
+
rawOutputMaxBytes: config.rawOutputMaxBytes ?? search.RAW_OUTPUT_MAX_BYTES,
|
|
9
|
+
graceMs: config.graceMs ?? search.SEARCH_GRACE_MS,
|
|
10
|
+
stderrMaxBytes: config.stderrMaxBytes ?? search.SEARCH_STDERR_MAX_BYTES,
|
|
11
|
+
timeoutMs: config.timeoutMs ?? search.SEARCH_TIMEOUT_MS,
|
|
12
|
+
};
|
|
13
|
+
if (config.tools.includes('glob'))
|
|
14
|
+
search.applyGlobTool(ctx, { ...shared, sampleOverCapGlobResults: config.sampleOverCapGlobResults ?? false, maxResults: config.globMaxResults ?? search.GLOB_MAX_RESULTS });
|
|
15
|
+
if (config.tools.includes('grep'))
|
|
16
|
+
search.applyGrepTool(ctx, { ...shared, maxMatches: config.grepMaxMatches ?? search.GREP_MAX_MATCHES, maxLineBytes: config.grepMaxLineBytes ?? search.GREP_MAX_LINE_BYTES });
|
|
17
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-filter row mounted inside a generated agent preset. The preset's own
|
|
3
|
+
* rows are already narrowed to the agent's `tools` (see `narrowRows`); this
|
|
4
|
+
* row covers what rows cannot express: a tool a kept row registers but the
|
|
5
|
+
* agent does not list, and the host's global tools (other plugins, MCP).
|
|
6
|
+
* Visible global tools outside the list are hidden with `tools.restrict`; what
|
|
7
|
+
* `restrict` cannot reach (a tool a kept row registers beside a listed one, a
|
|
8
|
+
* tool another plugin registers on the agent itself, such as the capability
|
|
9
|
+
* catalog's `skill`) is taken out of the agent's assembled tool list; and every
|
|
10
|
+
* call outside the list is refused by a scoped `tools.guard`.
|
|
11
|
+
*
|
|
12
|
+
* MCP entries follow Claude Code: `mcp__server` names every tool of a server,
|
|
13
|
+
* `mcp__server__*` too, `mcp__server__tool` one tool. A capability-catalog
|
|
14
|
+
* call is judged as the MCP tool its id names.
|
|
15
|
+
* @module @kirkchinese/harness-forge/preset-tool-filter
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
18
|
+
import z from '@deepseek-ai/schemastery';
|
|
19
|
+
/** Tool names to allow and/or deny. */
|
|
20
|
+
export interface Config {
|
|
21
|
+
allow?: string[];
|
|
22
|
+
deny?: string[];
|
|
23
|
+
}
|
|
24
|
+
/** Schemastery validation for the filter row. */
|
|
25
|
+
export declare const Config: z<Config>;
|
|
26
|
+
/** Cordis plugin name. */
|
|
27
|
+
export declare const name = "harness-forge-tool-filter";
|
|
28
|
+
/** The filter needs the scoped tool registry. */
|
|
29
|
+
export declare const inject: string[];
|
|
30
|
+
/** Whether an MCP entry of an agent's tool list names this MCP tool. */
|
|
31
|
+
export declare function mcpEntryMatches(entry: string, tool: string): boolean;
|
|
32
|
+
/** Why a call is outside an agent's tool list, or undefined when it is inside. */
|
|
33
|
+
export declare function exclusion(config: Config, tool: string, args: unknown): string | undefined;
|
|
34
|
+
/** Apply the restriction for the lifetime of the preset row. */
|
|
35
|
+
export declare function apply(ctx: Context, config: Config): void;
|