@kirkchinese/harness-forge 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/docs/DETAIL.zh.md +47 -0
- package/lib/agents/presets.d.ts +7 -0
- package/lib/agents/presets.js +11 -1
- package/lib/agents/profiles.js +3 -2
- package/lib/agents/row.js +3 -1
- package/lib/client/paths.d.ts +12 -0
- package/lib/client/paths.js +68 -0
- package/lib/client/typert.d.ts +12 -1
- package/lib/client/typert.js +54 -6
- package/lib/client.js +1593 -270
- package/lib/commands/row.js +1 -1
- package/lib/context/instructions.js +5 -5
- package/lib/dsh/host.d.ts +3 -0
- package/lib/dsh/host.js +3 -0
- package/lib/forge/contract.d.ts +42 -2
- package/lib/forge/contract.js +3 -1
- package/lib/forge/follow.d.ts +30 -0
- package/lib/forge/follow.js +73 -0
- package/lib/forge/ledger.d.ts +70 -7
- package/lib/forge/ledger.js +314 -42
- package/lib/forge/projects.d.ts +5 -2
- package/lib/forge/projects.js +23 -16
- 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/service.d.ts +19 -9
- package/lib/forge/service.js +47 -31
- package/lib/forge/settings.d.ts +5 -3
- package/lib/forge/settings.js +11 -4
- package/lib/forge/state.d.ts +60 -0
- package/lib/forge/state.js +174 -58
- package/lib/hooks/broker/engine.js +2 -8
- package/lib/hooks/broker/session-events.d.ts +5 -0
- package/lib/hooks/broker/session-events.js +12 -3
- package/lib/hooks/broker/types.d.ts +7 -5
- package/lib/hooks/condition.d.ts +78 -2
- package/lib/hooks/condition.js +494 -73
- package/lib/hooks/config.d.ts +1 -1
- package/lib/hooks/config.js +4 -0
- package/lib/hooks/glob.d.ts +41 -0
- package/lib/hooks/glob.js +114 -0
- package/lib/hooks/permissions.d.ts +8 -3
- package/lib/hooks/permissions.js +119 -26
- package/lib/hooks/powershell-aliases.d.ts +19 -0
- package/lib/hooks/powershell-aliases.js +58 -0
- package/lib/hooks/process.d.ts +17 -0
- package/lib/hooks/process.js +156 -1
- package/lib/hooks/row.js +2 -0
- package/lib/hooks/runner.d.ts +17 -4
- package/lib/hooks/runner.js +42 -13
- package/lib/hooks/shell-commands.d.ts +10 -1
- package/lib/hooks/shell-commands.js +74 -10
- package/lib/hooks/shell.d.ts +3 -2
- package/lib/hooks/shell.js +5 -2
- package/lib/hooks/vocabulary.js +3 -1
- package/lib/mcp/catalog.d.ts +5 -2
- package/lib/mcp/catalog.js +18 -10
- package/lib/mcp/mount.d.ts +40 -2
- package/lib/mcp/mount.js +131 -31
- package/lib/mcp/policy.d.ts +42 -0
- package/lib/mcp/policy.js +43 -0
- package/lib/mcp/remote.js +5 -15
- package/lib/mcp/row.js +111 -17
- package/lib/mods/loader.js +4 -0
- package/lib/mods/service/turns.d.ts +8 -7
- package/lib/mods/service/turns.js +10 -35
- package/lib/opencode/bun.js +14 -2
- package/lib/opencode/row.d.ts +14 -1
- package/lib/opencode/row.js +38 -20
- package/lib/opencode/runtime/server.js +2 -1
- package/lib/porting/adapter-paths.d.ts +13 -0
- package/lib/porting/adapter-paths.js +120 -0
- package/lib/porting/port-gap.d.ts +10 -4
- package/lib/porting/port-gap.js +43 -7
- package/lib/porting/prompt.js +9 -7
- package/lib/porting/row.js +7 -5
- package/lib/porting/verify-port.d.ts +3 -10
- package/lib/porting/verify-port.js +12 -34
- package/lib/sessions/chat-import.d.ts +48 -0
- package/lib/sessions/chat-import.js +44 -0
- package/lib/sessions/claude.d.ts +16 -10
- package/lib/sessions/claude.js +76 -55
- 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 +34 -22
- package/lib/sessions/codex.js +150 -183
- package/lib/sessions/opencode.d.ts +15 -9
- package/lib/sessions/opencode.js +77 -58
- package/lib/sessions/persist.d.ts +162 -0
- package/lib/sessions/persist.js +377 -0
- package/lib/sessions/row.d.ts +2 -1
- package/lib/sessions/row.js +75 -9
- 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/render.d.ts +30 -1
- package/lib/shared/render.js +813 -48
- package/lib/skills/provider.d.ts +2 -0
- package/lib/skills/provider.js +8 -2
- package/lib/skills/row.js +1 -1
- package/lib/workbench/adapter-coverage.d.ts +20 -2
- package/lib/workbench/adapter-coverage.js +46 -7
- package/lib/workbench/overview.d.ts +77 -27
- package/lib/workbench/overview.js +99 -12
- package/lib/workbench/remote.d.ts +64 -21
- package/lib/workbench/remote.js +181 -42
- package/lib/workbench/settings.d.ts +5 -1
- package/lib/workbench/settings.js +6 -2
- package/lib/workbench/workbench.d.ts +34 -4
- package/lib/workbench/workbench.js +147 -46
- package/locale/zh.json +2 -1
- package/package.json +3 -2
- package/lib/forge/marketplace-install.d.ts +0 -3
- package/lib/forge/marketplace-install.js +0 -64
package/README.md
CHANGED
|
@@ -24,6 +24,10 @@ Also: **Import sessions**, **Settings**, **Diagnostics**. The model can use the
|
|
|
24
24
|
|
|
25
25
|
This package installs one DSH plugin row per capability: Harness Forge (required by the others), skills, commands, agents, hooks, MCP servers, Claude Code mods, OpenCode plugins, instructions, sessions, porting and workbench. Each can be switched off in DSH's **Plugins** page without affecting the rest.
|
|
26
26
|
|
|
27
|
+
## Works well with
|
|
28
|
+
|
|
29
|
+
[dsh-chat-import](https://github.com/Nwflower/dsh-chat-import) imports conversations from Claude Code, Codex, OpenCode and 40+ other agents as DSH sessions you can continue. While it is installed, Harness Forge's own session import steps aside for it; **Install** under **More → Import sessions** (or on the first-run banner) installs it through DSH's plugin manager.
|
|
30
|
+
|
|
27
31
|
## Safety
|
|
28
32
|
|
|
29
33
|
Migrated hooks, MCP servers and plugin code run with your permissions, as in their original harness. Migrate only plugins you trust.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Harness Forge
|
|
2
|
+
|
|
3
|
+
在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)里使用你的 Claude Code、Codex 和 OpenCode 插件与设置:技能、斜杠命令、子代理、hook、MCP 服务(stdio、HTTP、SSE、OAuth)、Claude Code mods 和 OpenCode 代码插件,你的 `~/.claude` 和 `~/.codex` 设置,DSH 自己不读的指令文件,以及可以接着聊的历史会话。转换在运行时完成,原来的安装保持原样。
|
|
4
|
+
|
|
5
|
+
在 DSH 里:打开 **插件 › 添加插件**,输入 `@kirkchinese/harness-forge`。也可以在终端里装到 `dsh web` 使用的主 profile:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
dsh plugin --profile web add @kirkchinese/harness-forge
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
需要 DSH 0.2.2-rc.3 或更新版本、Node.js 22.19+ 或 24+;在 Windows 上,hook 在 Git Bash 里运行。
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
在 DSH 侧边栏打开 **Harness Forge**:
|
|
16
|
+
|
|
17
|
+
- **发现与迁移** 列出这台电脑上找到的插件和你自己的设置,逐项标出可用、部分可用或无法使用并写明原因,然后迁移它们(**全部迁移**)。这里也可以浏览插件市场。
|
|
18
|
+
- **已迁移** 可以关闭单个部分或撤销迁移。
|
|
19
|
+
- **缺口** 列出无法完整运行的部分及原因。**用 AI 补上** 会在 DSH 的创作模式里开一个会话,构建一个本地适配器插件(`dsh-adapter-<插件>-<部分>`);是否发布由你决定,发布时用你自己的 npm scope。
|
|
20
|
+
|
|
21
|
+
另外还有:**导入会话**、**设置**、**诊断**。模型可以使用 `harness_*` 工具,你也可以输入 `/harness status | list | scan | plan | import | undo | remove | roots | login`。
|
|
22
|
+
|
|
23
|
+
## 行
|
|
24
|
+
|
|
25
|
+
这个包为每种能力安装一个 DSH 插件行:Harness Forge(其他行都依赖它)、技能、命令、智能体、hook、MCP 服务、Claude Code mods、OpenCode 插件、指令、会话、移植和工作台(workbench)。每一行都可以在 DSH 的 **插件** 页单独关闭,不影响其他行。
|
|
26
|
+
|
|
27
|
+
## 搭配使用
|
|
28
|
+
|
|
29
|
+
[dsh-chat-import](https://github.com/Nwflower/dsh-chat-import) 把 Claude Code、Codex、OpenCode 和其他 40 多种智能体的对话导入为可以接着聊的 DSH 会话。安装它之后,Harness Forge 自己的会话导入会让位给它;在 **更多 → 导入会话** 里(或首次打开时的横幅上)点 **安装**,即可通过 DSH 的插件管理器安装它。
|
|
30
|
+
|
|
31
|
+
## 安全
|
|
32
|
+
|
|
33
|
+
迁移过来的 hook、MCP 服务和插件代码以你的权限运行,和在原工具里一样。只迁移你信任的插件。
|
|
34
|
+
|
|
35
|
+
## 文档
|
|
36
|
+
|
|
37
|
+
- [快速开始](https://github.com/kirkchinese/harness-forge/blob/main/docs/user/quickstart.zh.md)
|
|
38
|
+
- [兼容性](https://github.com/kirkchinese/harness-forge/blob/main/docs/user/compatibility.zh.md)
|
|
39
|
+
- [移植(用 AI 补上)](https://github.com/kirkchinese/harness-forge/blob/main/docs/user/porting.zh.md)
|
|
40
|
+
- [架构](https://github.com/kirkchinese/harness-forge/blob/main/docs/architecture/overview.md)(英文)
|
|
41
|
+
- [更新日志](https://github.com/kirkchinese/harness-forge/blob/main/CHANGELOG.md)(英文)
|
|
42
|
+
|
|
43
|
+
完整的中文说明:[README](https://github.com/kirkchinese/harness-forge/blob/main/README.zh.md)。
|
|
44
|
+
|
|
45
|
+
## 许可证
|
|
46
|
+
|
|
47
|
+
MIT
|
package/lib/agents/presets.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export declare class AgentTool {
|
|
|
64
64
|
private readonly presets;
|
|
65
65
|
private readonly scoped;
|
|
66
66
|
private holding;
|
|
67
|
+
private closed;
|
|
67
68
|
private fiber;
|
|
68
69
|
/**
|
|
69
70
|
* @param inherited - the global tool whose agents a session-scoped tool also offers.
|
|
@@ -85,6 +86,12 @@ export declare class AgentTool {
|
|
|
85
86
|
hold(): void;
|
|
86
87
|
/** End a {@link hold}: the tool starts once with every agent added meanwhile. */
|
|
87
88
|
resume(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Take no more changes: the context it runs in is going away (its fiber
|
|
91
|
+
* goes with it). The agents' withdrawals run after that, and starting or
|
|
92
|
+
* updating a tool in an inactive context throws.
|
|
93
|
+
*/
|
|
94
|
+
close(): void;
|
|
88
95
|
dispose(): Promise<void>;
|
|
89
96
|
private refresh;
|
|
90
97
|
}
|
package/lib/agents/presets.js
CHANGED
|
@@ -195,6 +195,7 @@ export class AgentTool {
|
|
|
195
195
|
presets = new Map();
|
|
196
196
|
scoped = new Set();
|
|
197
197
|
holding = false;
|
|
198
|
+
closed = false;
|
|
198
199
|
fiber;
|
|
199
200
|
/**
|
|
200
201
|
* @param inherited - the global tool whose agents a session-scoped tool also offers.
|
|
@@ -252,14 +253,23 @@ export class AgentTool {
|
|
|
252
253
|
this.holding = false;
|
|
253
254
|
this.refresh();
|
|
254
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Take no more changes: the context it runs in is going away (its fiber
|
|
258
|
+
* goes with it). The agents' withdrawals run after that, and starting or
|
|
259
|
+
* updating a tool in an inactive context throws.
|
|
260
|
+
*/
|
|
261
|
+
close() {
|
|
262
|
+
this.closed = true;
|
|
263
|
+
}
|
|
255
264
|
async dispose() {
|
|
265
|
+
this.close();
|
|
256
266
|
this.inherited?.scoped.delete(this);
|
|
257
267
|
const fiber = this.fiber;
|
|
258
268
|
this.fiber = undefined;
|
|
259
269
|
await fiber?.dispose();
|
|
260
270
|
}
|
|
261
271
|
refresh() {
|
|
262
|
-
if (this.holding)
|
|
272
|
+
if (this.holding || this.closed)
|
|
263
273
|
return;
|
|
264
274
|
for (const tool of this.scoped)
|
|
265
275
|
tool.refresh();
|
package/lib/agents/profiles.js
CHANGED
|
@@ -28,7 +28,7 @@ import { homedir } from 'node:os';
|
|
|
28
28
|
import { join } from 'node:path';
|
|
29
29
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
30
30
|
import { renderSkillContent } from '@deepseek-ai/dsh-skill';
|
|
31
|
-
import { kebabCase, toolList } from '@kirkchinese/harness-forge-core';
|
|
31
|
+
import { kebabCase, leadsToShare, toolList } from '@kirkchinese/harness-forge-core';
|
|
32
32
|
import { appendNotice } from '../hooks/notice.js';
|
|
33
33
|
import { resolveRoute } from '../shared/invocation.js';
|
|
34
34
|
import { selectRoute } from '../dsh/model-route.js';
|
|
@@ -79,7 +79,8 @@ export function memoryInstructions(dir) {
|
|
|
79
79
|
const path = join(dir, 'MEMORY.md');
|
|
80
80
|
let excerpt = '';
|
|
81
81
|
let cut = false;
|
|
82
|
-
|
|
82
|
+
// A project's memory file on a link to a network share it is not on is left unread (see `leadsToShare`).
|
|
83
|
+
if (!leadsToShare(path) && existsSync(path)) {
|
|
83
84
|
const text = readFileSync(path, 'utf8');
|
|
84
85
|
const lines = text.split(/\r?\n/u);
|
|
85
86
|
excerpt = lines.slice(0, MEMORY_LINES).join('\n');
|
package/lib/agents/row.js
CHANGED
|
@@ -138,9 +138,11 @@ export function startAgents(ctx, forge) {
|
|
|
138
138
|
}));
|
|
139
139
|
// A preset registry that starts after this row retries the agents that needed it.
|
|
140
140
|
parts.add('preset registry', () => {
|
|
141
|
-
const fiber = ctx.inject(['agentPresets'], () => { forge.ledger.reapply(); });
|
|
141
|
+
const fiber = ctx.inject(['agentPresets'], () => { forge.ledger.reapply('agent'); });
|
|
142
142
|
return () => fiber.dispose();
|
|
143
143
|
});
|
|
144
144
|
parts.add('api', () => forge.provide('agents', api));
|
|
145
|
+
// Torn down first: the row's context is already inactive, so the agents withdrawn after this leave the tool alone.
|
|
146
|
+
parts.add('closing', () => () => { agents.close(); });
|
|
145
147
|
return () => parts.dispose();
|
|
146
148
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What stands for the home folder. */
|
|
2
|
+
export declare const HOME_MARK = "~";
|
|
3
|
+
/** Show `path` with the home folder as `~`; a path elsewhere, or no home known, is returned as it is. */
|
|
4
|
+
export declare function displayPath(path: string, home: string | undefined): string;
|
|
5
|
+
/** Show the home folder as `~` wherever a message (an error, a log line) names it, as whole folders only. */
|
|
6
|
+
export declare function displayText(text: string, home: string | undefined): string;
|
|
7
|
+
/** The home folder the Host reported, for the screens below the page. */
|
|
8
|
+
export declare const HomeContext: import("react").Context<string | undefined>;
|
|
9
|
+
/** `displayPath` over the Host's home folder. */
|
|
10
|
+
export declare function usePath(): (path: string) => string;
|
|
11
|
+
/** `displayText` over the Host's home folder. */
|
|
12
|
+
export declare function useText(): (text: string) => string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths as the page shows them: what is under the person's home folder reads
|
|
3
|
+
* `~/…` (`~\…` on Windows). The Host knows the home folder and sends it with
|
|
4
|
+
* the overview; the page only displays through here, and every action (install,
|
|
5
|
+
* import, open, remove, settings sent back) keeps the full path.
|
|
6
|
+
* @module @kirkchinese/harness-forge/client
|
|
7
|
+
*/
|
|
8
|
+
import { createContext, useContext } from 'react';
|
|
9
|
+
/** What stands for the home folder. */
|
|
10
|
+
export const HOME_MARK = '~';
|
|
11
|
+
/** A home folder written the Windows way: a drive (`C:`) or a network share (`\\server`). */
|
|
12
|
+
const WINDOWS_HOME = /^(?:[A-Za-z]:|[\\/]{2})/u;
|
|
13
|
+
/** A home that is only a drive: too wide to fold everything under it. */
|
|
14
|
+
const DRIVE_ROOT = /^[A-Za-z]:$/u;
|
|
15
|
+
const WINDOWS_SEPARATOR = '\\';
|
|
16
|
+
const POSIX_SEPARATOR = '/';
|
|
17
|
+
/** What may follow the home folder in a message: anything but a character that would continue a folder name. */
|
|
18
|
+
const NAME_CHARACTER = '[\\p{L}\\p{N}_.-]';
|
|
19
|
+
/** What may precede it: anything but a character that would make it the tail of a longer path. */
|
|
20
|
+
const PATH_CHARACTER = '[\\p{L}\\p{N}_.~/\\\\-]';
|
|
21
|
+
/** The home folder as it matches paths: no trailing separator; nothing for an empty home or a root. */
|
|
22
|
+
function homeOf(home) {
|
|
23
|
+
if (home === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
const windows = WINDOWS_HOME.test(home);
|
|
26
|
+
const text = home.replace(windows ? /[\\/]+$/u : /\/+$/u, '');
|
|
27
|
+
if (text.length === 0 || (windows && DRIVE_ROOT.test(text)))
|
|
28
|
+
return undefined;
|
|
29
|
+
return { text, windows };
|
|
30
|
+
}
|
|
31
|
+
/** Show `path` with the home folder as `~`; a path elsewhere, or no home known, is returned as it is. */
|
|
32
|
+
export function displayPath(path, home) {
|
|
33
|
+
const folder = homeOf(home);
|
|
34
|
+
if (folder === undefined || path.length < folder.text.length)
|
|
35
|
+
return path;
|
|
36
|
+
const prefix = path.slice(0, folder.text.length);
|
|
37
|
+
if (folder.windows ? prefix.toLowerCase() !== folder.text.toLowerCase() : prefix !== folder.text)
|
|
38
|
+
return path;
|
|
39
|
+
if (path.length === folder.text.length)
|
|
40
|
+
return HOME_MARK;
|
|
41
|
+
const next = path.charAt(folder.text.length);
|
|
42
|
+
if (next !== POSIX_SEPARATOR && !(folder.windows && next === WINDOWS_SEPARATOR))
|
|
43
|
+
return path;
|
|
44
|
+
return `${HOME_MARK}${folder.windows ? WINDOWS_SEPARATOR : POSIX_SEPARATOR}${path.slice(folder.text.length + 1)}`;
|
|
45
|
+
}
|
|
46
|
+
function escaped(text) {
|
|
47
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
48
|
+
}
|
|
49
|
+
/** Show the home folder as `~` wherever a message (an error, a log line) names it, as whole folders only. */
|
|
50
|
+
export function displayText(text, home) {
|
|
51
|
+
const folder = homeOf(home);
|
|
52
|
+
if (folder === undefined)
|
|
53
|
+
return text;
|
|
54
|
+
const pattern = new RegExp(`(?<!${PATH_CHARACTER})${escaped(folder.text)}(?!${NAME_CHARACTER})`, folder.windows ? 'giu' : 'gu');
|
|
55
|
+
return text.replace(pattern, HOME_MARK);
|
|
56
|
+
}
|
|
57
|
+
/** The home folder the Host reported, for the screens below the page. */
|
|
58
|
+
export const HomeContext = createContext(undefined);
|
|
59
|
+
/** `displayPath` over the Host's home folder. */
|
|
60
|
+
export function usePath() {
|
|
61
|
+
const home = useContext(HomeContext);
|
|
62
|
+
return path => displayPath(path, home);
|
|
63
|
+
}
|
|
64
|
+
/** `displayText` over the Host's home folder. */
|
|
65
|
+
export function useText() {
|
|
66
|
+
const home = useContext(HomeContext);
|
|
67
|
+
return text => displayText(text, home);
|
|
68
|
+
}
|
package/lib/client/typert.d.ts
CHANGED
|
@@ -6,7 +6,18 @@ export declare function setMountedRemote(value: unknown): void;
|
|
|
6
6
|
export declare function setMountedRemoteError(error: unknown): void;
|
|
7
7
|
/** Why the namespace could not mount, when known. */
|
|
8
8
|
export declare function mountedRemoteError(): string | undefined;
|
|
9
|
-
/**
|
|
9
|
+
/** A failed call: the Host's reason, and the Remote error code and its details when there are. */
|
|
10
|
+
export declare class CallError extends Error {
|
|
11
|
+
readonly code?: string | undefined;
|
|
12
|
+
readonly details?: Readonly<Record<string, unknown>> | undefined;
|
|
13
|
+
constructor(message: string, code?: string | undefined, details?: Readonly<Record<string, unknown>> | undefined);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether a failed call means the `harness-forge-workbench` row is switched off: the page is
|
|
17
|
+
* there (the client is declared once per package) but nothing on the Host answers `harnessCompat`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isWorkbenchOff(error: unknown): boolean;
|
|
20
|
+
/** Call one workbench method; a failure throws a CallError carrying the Host's reason. */
|
|
10
21
|
export declare function call<T>(method: string, request?: Record<string, unknown>): Promise<T>;
|
|
11
22
|
/** Open one workbench stream; dispose the handle to stop it. */
|
|
12
23
|
export declare function stream<T>(method: string, request: Record<string, unknown>): Promise<AsyncIterable<T> & {
|
package/lib/client/typert.js
CHANGED
|
@@ -24,12 +24,22 @@ const METHODS = [
|
|
|
24
24
|
['migrate', 'unary', true],
|
|
25
25
|
['setPartEnabled', 'unary', true],
|
|
26
26
|
['removePlugin', 'unary', true],
|
|
27
|
-
['
|
|
28
|
-
['
|
|
27
|
+
['keepPlugin', 'unary', true],
|
|
28
|
+
['remoteSources', 'unary', false],
|
|
29
|
+
['remoteOpen', 'unary', true],
|
|
30
|
+
['remoteForget', 'unary', true],
|
|
31
|
+
['remotePrepare', 'unary', true],
|
|
32
|
+
['remoteInstall', 'unary', true],
|
|
33
|
+
['remoteCancel', 'unary', true],
|
|
34
|
+
['remoteCheckUpdates', 'unary', true],
|
|
35
|
+
['remotePrepareUpdate', 'unary', true],
|
|
29
36
|
['signIns', 'unary', false],
|
|
30
37
|
['signIn', 'unary', true],
|
|
31
38
|
['sessions', 'unary', true],
|
|
32
39
|
['importSession', 'unary', true],
|
|
40
|
+
['openImported', 'unary', true],
|
|
41
|
+
['sessionImport', 'unary', false],
|
|
42
|
+
['installChatImport', 'unary', false],
|
|
33
43
|
['modSurfaces', 'stream', true],
|
|
34
44
|
['modAct', 'unary', true],
|
|
35
45
|
['modClose', 'unary', true],
|
|
@@ -87,16 +97,54 @@ async function namespace() {
|
|
|
87
97
|
throw new Error(`Harness Forge is not reachable: ${mountError ?? 'the Remote namespace did not mount'}`);
|
|
88
98
|
return ready;
|
|
89
99
|
}
|
|
90
|
-
/**
|
|
100
|
+
/** A failed call: the Host's reason, and the Remote error code and its details when there are. */
|
|
101
|
+
export class CallError extends Error {
|
|
102
|
+
code;
|
|
103
|
+
details;
|
|
104
|
+
constructor(message, code, details) {
|
|
105
|
+
super(message);
|
|
106
|
+
this.code = code;
|
|
107
|
+
this.details = details;
|
|
108
|
+
this.name = 'CallError';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Gateway codes for an endpoint that no running Host service answers: the workbench row is off. */
|
|
112
|
+
const NOT_SERVED = new Set(['gateway/invocation-unavailable', 'gateway/service-unavailable', 'gateway/method-unavailable', 'gateway/definition-unavailable']);
|
|
113
|
+
/**
|
|
114
|
+
* Whether a failed call means the `harness-forge-workbench` row is switched off: the page is
|
|
115
|
+
* there (the client is declared once per package) but nothing on the Host answers `harnessCompat`.
|
|
116
|
+
*/
|
|
117
|
+
export function isWorkbenchOff(error) {
|
|
118
|
+
if (!(error instanceof Error))
|
|
119
|
+
return false;
|
|
120
|
+
const code = error.code;
|
|
121
|
+
if (typeof code === 'string' && NOT_SERVED.has(code))
|
|
122
|
+
return true;
|
|
123
|
+
// DSH 0.2.2 answers an endpoint no Host service exports with HTTP 404, which the client reports as a transport failure.
|
|
124
|
+
return /harness-forge-workbench/u.test(error.message)
|
|
125
|
+
|| /\/api\/harnessCompat\/\w+: HTTP 404\b/u.test(error.message)
|
|
126
|
+
|| /harnessCompat\/\w+.*(?:no active Remote method|active Service .* is unavailable|has no callable method|definition was withdrawn)/u.test(error.message);
|
|
127
|
+
}
|
|
128
|
+
function recordOf(value) {
|
|
129
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
130
|
+
}
|
|
131
|
+
/** Call one workbench method; a failure throws a CallError carrying the Host's reason. */
|
|
91
132
|
export async function call(method, request) {
|
|
92
133
|
const target = (await namespace())[method];
|
|
93
134
|
if (typeof target !== 'function')
|
|
94
|
-
throw new
|
|
95
|
-
|
|
135
|
+
throw new CallError(`Harness Forge has no method ${method}`);
|
|
136
|
+
let result;
|
|
137
|
+
try {
|
|
138
|
+
result = await (request === undefined ? target() : target(request));
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const { code, details } = (error ?? {});
|
|
142
|
+
throw new CallError(error instanceof Error ? error.message : String(error), typeof code === 'string' ? code : undefined, recordOf(details));
|
|
143
|
+
}
|
|
96
144
|
if (typeof result === 'object' && result !== null && 'ok' in result) {
|
|
97
145
|
const outcome = result;
|
|
98
146
|
if (!outcome.ok)
|
|
99
|
-
throw new
|
|
147
|
+
throw new CallError(outcome.error?.message ?? outcome.error?.code ?? `${method} failed`, outcome.error?.code, recordOf(outcome.error?.details));
|
|
100
148
|
return outcome.value;
|
|
101
149
|
}
|
|
102
150
|
return result;
|