@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,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code mods in DSH sessions: one mods engine per root session, every
|
|
3
|
+
* imported mod loaded into it fresh (module state is the session's, as in
|
|
4
|
+
* Claude Code), and the engine's events raised at DSH's call sites:
|
|
5
|
+
*
|
|
6
|
+
* | Event | DSH call site |
|
|
7
|
+
* |---|---|
|
|
8
|
+
* | session.start / session.end | `agent/created` / `agent/disposed` of a root agent |
|
|
9
|
+
* | prompt.submit, turn.start | `agent/pre-step` with the user's messages / a turn's first step |
|
|
10
|
+
* | turn.complete | `session/event` `turn/end` |
|
|
11
|
+
* | tool.call | `tools/pre-execute` → `tools/execute` → `tools/post-execute`: the hooks wrap PreToolUse, the permission decision and the tool |
|
|
12
|
+
* | tool.check | the hooks broker's decision, after PreToolUse hooks and permission rules |
|
|
13
|
+
* | command.run | a command a mod registered (`$.command.register`) |
|
|
14
|
+
* @module @kirkchinese/harness-forge/mods
|
|
15
|
+
*/
|
|
16
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
17
|
+
import type { SurfaceSnapshot } from './surfaces.js';
|
|
18
|
+
import type { ClaudeVerdict, ModSource, ModsServiceHost, ToolExec } from './service/types.js';
|
|
19
|
+
export type { ClaudeVerdict, ModEventRecord, ModSource, ModsServiceHost } from './service/types.js';
|
|
20
|
+
export { claudeInstructionFiles } from './service/turns.js';
|
|
21
|
+
/** Claude Code mods across the process's DSH sessions. */
|
|
22
|
+
export declare class ModsService {
|
|
23
|
+
private readonly ctx;
|
|
24
|
+
private readonly registry;
|
|
25
|
+
private readonly commands;
|
|
26
|
+
private readonly turns;
|
|
27
|
+
private readonly tools;
|
|
28
|
+
private readonly drawings;
|
|
29
|
+
constructor(ctx: Context, host: ModsServiceHost);
|
|
30
|
+
/** Add a mod: loaded into every live session now and every session after. Returns the removal. */
|
|
31
|
+
add(source: ModSource): Promise<() => Promise<void>>;
|
|
32
|
+
/** The loaded mods of a session, for evidence and the workbench. */
|
|
33
|
+
loaded(sessionId: string): readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* The process is going away: every live session's mods hear
|
|
36
|
+
* `session.end` (reason `other`), as Claude Code's do at exit.
|
|
37
|
+
*/
|
|
38
|
+
shutdown(): Promise<void>;
|
|
39
|
+
/** Listen on the host. Returns the disposer. */
|
|
40
|
+
install(): () => void;
|
|
41
|
+
/**
|
|
42
|
+
* Watch the band and panes of a session, across the agents it is given (a
|
|
43
|
+
* resumed session gets a new agent when the person acts). Undefined when no
|
|
44
|
+
* mod is loaded at all.
|
|
45
|
+
*/
|
|
46
|
+
watch(sessionId: string, listener: (snapshot: SurfaceSnapshot) => void): (() => void) | undefined;
|
|
47
|
+
/** A session's drawings, drawn afresh; undefined when the session has no mods. */
|
|
48
|
+
drawn(sessionId: string): Promise<SurfaceSnapshot | undefined>;
|
|
49
|
+
/** The person acted on a control of a session's drawing. */
|
|
50
|
+
act(sessionId: string, generation: number, actionId: string, value?: unknown): Promise<SurfaceSnapshot>;
|
|
51
|
+
/**
|
|
52
|
+
* The person closed a pane: `ui.close` with origin `person`; a hook may
|
|
53
|
+
* keep it open with `{ deny }`.
|
|
54
|
+
* @returns the drawing after, and the refusal when a hook kept the pane.
|
|
55
|
+
*/
|
|
56
|
+
closePane(sessionId: string, id: string): Promise<{
|
|
57
|
+
snapshot: SurfaceSnapshot;
|
|
58
|
+
refused?: string;
|
|
59
|
+
}>;
|
|
60
|
+
/** The person moved focus or scrolled in a session's drawing. */
|
|
61
|
+
move(sessionId: string, kind: 'focus' | 'scroll', target: Readonly<Record<string, unknown>>): Promise<{
|
|
62
|
+
snapshot: SurfaceSnapshot;
|
|
63
|
+
refused?: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** Whether a call's session has mods hooking `tool.check`. */
|
|
66
|
+
checks(exec: ToolExec): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* `tool.check` for one call the hooks broker decided: the mods' answer over
|
|
69
|
+
* Claude Code's own verdict (rules, PreToolUse hooks, the mode).
|
|
70
|
+
*/
|
|
71
|
+
check(exec: ToolExec, verdict: ClaudeVerdict): Promise<ClaudeVerdict>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { onDsh } from '../dsh/host.js';
|
|
2
|
+
import { ModCommands } from './service/commands.js';
|
|
3
|
+
import { ModDrawings } from './service/drawings.js';
|
|
4
|
+
import { SessionRegistry } from './service/sessions.js';
|
|
5
|
+
import { ModTools } from './service/tools.js';
|
|
6
|
+
import { ModTurns } from './service/turns.js';
|
|
7
|
+
export { claudeInstructionFiles } from './service/turns.js';
|
|
8
|
+
/** Claude Code mods across the process's DSH sessions. */
|
|
9
|
+
export class ModsService {
|
|
10
|
+
ctx;
|
|
11
|
+
registry;
|
|
12
|
+
commands;
|
|
13
|
+
turns;
|
|
14
|
+
tools;
|
|
15
|
+
drawings;
|
|
16
|
+
constructor(ctx, host) {
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
this.registry = new SessionRegistry(ctx, host, {
|
|
19
|
+
registerCommand: (session, plugin, spec) => this.commands.registerCommand(session, plugin, spec),
|
|
20
|
+
toolCore: (session, e, context) => this.tools.toolCore(session, e, context),
|
|
21
|
+
checkCore: (session, e) => this.tools.checkCore(session, e),
|
|
22
|
+
});
|
|
23
|
+
this.commands = new ModCommands(this.registry);
|
|
24
|
+
this.turns = new ModTurns(this.registry);
|
|
25
|
+
this.tools = new ModTools(this.registry);
|
|
26
|
+
this.drawings = new ModDrawings(this.registry);
|
|
27
|
+
}
|
|
28
|
+
/** Add a mod: loaded into every live session now and every session after. Returns the removal. */
|
|
29
|
+
add(source) {
|
|
30
|
+
return this.registry.add(source);
|
|
31
|
+
}
|
|
32
|
+
/** The loaded mods of a session, for evidence and the workbench. */
|
|
33
|
+
loaded(sessionId) {
|
|
34
|
+
return this.registry.loaded(sessionId);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The process is going away: every live session's mods hear
|
|
38
|
+
* `session.end` (reason `other`), as Claude Code's do at exit.
|
|
39
|
+
*/
|
|
40
|
+
shutdown() {
|
|
41
|
+
return this.registry.shutdown();
|
|
42
|
+
}
|
|
43
|
+
/** Listen on the host. Returns the disposer. */
|
|
44
|
+
install() {
|
|
45
|
+
const on = (name, listener, options) => onDsh(this.ctx, name, listener, { ...options, owner: 'mods' });
|
|
46
|
+
const disposers = [
|
|
47
|
+
on('agent/created', ((payload) => this.registry.created(payload.agent, payload.signal))),
|
|
48
|
+
on('agent/disposed', ((payload) => { this.registry.disposed(payload.agent); })),
|
|
49
|
+
on('agent/pre-step', ((payload, next) => this.turns.preStep(payload, next)), { prepend: true }),
|
|
50
|
+
on('session/event', ((session, event) => { this.turns.sessionEvent(session, event); })),
|
|
51
|
+
on('tools/pre-execute', ((exec, next) => this.tools.preExecute(exec, next)), { prepend: true }),
|
|
52
|
+
on('tools/execute', ((exec, next) => this.tools.execute(exec, next)), { prepend: true }),
|
|
53
|
+
on('tools/post-execute', ((exec, result, next) => this.tools.postExecute(exec, result, next)), { prepend: true }),
|
|
54
|
+
on('tools/result', ((exec, result) => { this.tools.toolResult(exec, result); })),
|
|
55
|
+
this.commands.wrapCommands(),
|
|
56
|
+
];
|
|
57
|
+
return () => {
|
|
58
|
+
for (const dispose of disposers)
|
|
59
|
+
dispose();
|
|
60
|
+
for (const session of this.registry.sessions.values())
|
|
61
|
+
this.registry.close(session);
|
|
62
|
+
this.registry.sessions.clear();
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Watch the band and panes of a session, across the agents it is given (a
|
|
67
|
+
* resumed session gets a new agent when the person acts). Undefined when no
|
|
68
|
+
* mod is loaded at all.
|
|
69
|
+
*/
|
|
70
|
+
watch(sessionId, listener) {
|
|
71
|
+
return this.drawings.watch(sessionId, listener);
|
|
72
|
+
}
|
|
73
|
+
/** A session's drawings, drawn afresh; undefined when the session has no mods. */
|
|
74
|
+
drawn(sessionId) {
|
|
75
|
+
return this.drawings.drawn(sessionId);
|
|
76
|
+
}
|
|
77
|
+
/** The person acted on a control of a session's drawing. */
|
|
78
|
+
act(sessionId, generation, actionId, value) {
|
|
79
|
+
return this.drawings.act(sessionId, generation, actionId, value);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The person closed a pane: `ui.close` with origin `person`; a hook may
|
|
83
|
+
* keep it open with `{ deny }`.
|
|
84
|
+
* @returns the drawing after, and the refusal when a hook kept the pane.
|
|
85
|
+
*/
|
|
86
|
+
closePane(sessionId, id) {
|
|
87
|
+
return this.drawings.closePane(sessionId, id);
|
|
88
|
+
}
|
|
89
|
+
/** The person moved focus or scrolled in a session's drawing. */
|
|
90
|
+
move(sessionId, kind, target) {
|
|
91
|
+
return this.drawings.move(sessionId, kind, target);
|
|
92
|
+
}
|
|
93
|
+
/** Whether a call's session has mods hooking `tool.check`. */
|
|
94
|
+
checks(exec) {
|
|
95
|
+
return this.tools.checks(exec);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* `tool.check` for one call the hooks broker decided: the mods' answer over
|
|
99
|
+
* Claude Code's own verdict (rules, PreToolUse hooks, the mode).
|
|
100
|
+
*/
|
|
101
|
+
check(exec, verdict) {
|
|
102
|
+
return this.tools.check(exec, verdict);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** A node as the browser draws it. */
|
|
2
|
+
export type SerializedNode = string | SerializedElement;
|
|
3
|
+
/** An element as the browser draws it: plain props, its controls' action ids. */
|
|
4
|
+
export interface SerializedElement {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly props: Readonly<Record<string, unknown>>;
|
|
7
|
+
readonly children: readonly SerializedNode[];
|
|
8
|
+
/** `press`, `submit`, `input`, `select`, `link` → action id. */
|
|
9
|
+
readonly actions?: Readonly<Record<string, string>>;
|
|
10
|
+
}
|
|
11
|
+
/** One open pane. */
|
|
12
|
+
export interface PaneSnapshot {
|
|
13
|
+
readonly plugin: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly tree: SerializedNode | null;
|
|
17
|
+
/** Why the pane could not be drawn. */
|
|
18
|
+
readonly error?: string;
|
|
19
|
+
}
|
|
20
|
+
/** What a session's browser draws, at one generation. */
|
|
21
|
+
export interface SurfaceSnapshot {
|
|
22
|
+
readonly generation: number;
|
|
23
|
+
readonly band: SerializedNode | null;
|
|
24
|
+
readonly bandError?: string;
|
|
25
|
+
readonly panes: readonly PaneSnapshot[];
|
|
26
|
+
}
|
|
27
|
+
/** How a session raises its events. */
|
|
28
|
+
export interface SurfaceHost {
|
|
29
|
+
raise(event: string, input: unknown): Promise<unknown>;
|
|
30
|
+
report(line: string): void;
|
|
31
|
+
isWorking(): boolean;
|
|
32
|
+
/** Run outside any mod hook's context (see `invalidate`). */
|
|
33
|
+
detached?(fn: () => void): void;
|
|
34
|
+
}
|
|
35
|
+
/** The drawings of one session. */
|
|
36
|
+
export declare class SessionSurfaces {
|
|
37
|
+
private readonly host;
|
|
38
|
+
private generation;
|
|
39
|
+
private snapshot;
|
|
40
|
+
private readonly panes;
|
|
41
|
+
private actions;
|
|
42
|
+
private readonly watchers;
|
|
43
|
+
private pending;
|
|
44
|
+
private drawing;
|
|
45
|
+
private isDirty;
|
|
46
|
+
private isClosed;
|
|
47
|
+
/** `generation`: where numbering continues when a session's agent is replaced, so later drawings stay newer. */
|
|
48
|
+
constructor(host: SurfaceHost, generation?: number);
|
|
49
|
+
/** The latest drawing. */
|
|
50
|
+
current(): SurfaceSnapshot;
|
|
51
|
+
/** Watch every drawing from now on; returns the unsubscribe. */
|
|
52
|
+
watch(listener: (snapshot: SurfaceSnapshot) => void): () => void;
|
|
53
|
+
/** Something a drawing may depend on changed: draw again soon (folds bursts). */
|
|
54
|
+
invalidate(): void;
|
|
55
|
+
/** A mod opened a pane (`$.ui.open`). */
|
|
56
|
+
open(plugin: string, args: Readonly<Record<string, unknown>>): {
|
|
57
|
+
isPlaced: boolean;
|
|
58
|
+
reason?: string;
|
|
59
|
+
};
|
|
60
|
+
/** A pane closes, by its mod or the person; the hooks of `ui.close` have let it. */
|
|
61
|
+
close(id: string): void;
|
|
62
|
+
/** The open panes, as `$.ui.panes()` lists them. */
|
|
63
|
+
list(): Array<{
|
|
64
|
+
id: string;
|
|
65
|
+
plugin: string;
|
|
66
|
+
title: string;
|
|
67
|
+
placement: 'dock';
|
|
68
|
+
isFocused: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
/** Whose pane an id is. */
|
|
71
|
+
owner(id: string): string | undefined;
|
|
72
|
+
dispose(): void;
|
|
73
|
+
/** Draw the band and every pane. */
|
|
74
|
+
refresh(): Promise<SurfaceSnapshot>;
|
|
75
|
+
private draw;
|
|
76
|
+
private render;
|
|
77
|
+
/**
|
|
78
|
+
* The person acted on a control of the drawing at `generation`: its event
|
|
79
|
+
* (`ui.press`, `ui.input`, `ui.select`) runs, the callback last.
|
|
80
|
+
*/
|
|
81
|
+
act(generation: number, actionId: string, value?: unknown): Promise<SurfaceSnapshot>;
|
|
82
|
+
/**
|
|
83
|
+
* The person moved the keyboard focus to a control, or scrolled a pane or
|
|
84
|
+
* the band: `ui.focus` / `ui.scroll`, origin `person`. A hook may
|
|
85
|
+
* refuse it or handle it; the drawing follows either way.
|
|
86
|
+
*/
|
|
87
|
+
move(kind: 'focus' | 'scroll', target: Readonly<Record<string, unknown>>): Promise<{
|
|
88
|
+
snapshot: SurfaceSnapshot;
|
|
89
|
+
refused?: string;
|
|
90
|
+
}>;
|
|
91
|
+
/** Core of a control's event: its callback, in its mod's environment. */
|
|
92
|
+
runCallback(event: string, e: Readonly<Record<string, unknown>>): Promise<unknown>;
|
|
93
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mods' drawings in a DSH session, on the desktop surface: the band above
|
|
3
|
+
* the prompt (`AbovePrompt`) and the panes mods open (`$.ui.open`). Each is a
|
|
4
|
+
* `ui.render` dispatch; the tree it settles on is checked against the desktop
|
|
5
|
+
* element table and sent to the browser as plain data, every control's
|
|
6
|
+
* callback kept here under an action id. A press, a submitted input or a
|
|
7
|
+
* picked option raises `ui.press` / `ui.input` / `ui.select`, whose core runs
|
|
8
|
+
* the callback in its mod's environment.
|
|
9
|
+
* @module @kirkchinese/harness-forge/mods
|
|
10
|
+
*/
|
|
11
|
+
import { elementTable } from './runtime.js';
|
|
12
|
+
import { isRecord, messageOf } from './values.js';
|
|
13
|
+
const BAND_ID = 'band';
|
|
14
|
+
const SURFACE = 'desktop';
|
|
15
|
+
const COLUMNS = 120;
|
|
16
|
+
const ROWS = 12;
|
|
17
|
+
const PANE_COLUMNS = 100;
|
|
18
|
+
const PANE_ROWS = 40;
|
|
19
|
+
const HANDLER_PROPS = { onPress: 'press', onSubmit: 'submit', onInput: 'input', onSelect: 'select', onLinkPress: 'link' };
|
|
20
|
+
/** The drawings of one session. */
|
|
21
|
+
export class SessionSurfaces {
|
|
22
|
+
host;
|
|
23
|
+
generation = 0;
|
|
24
|
+
snapshot = { generation: 0, band: null, panes: [] };
|
|
25
|
+
panes = new Map();
|
|
26
|
+
actions = new Map();
|
|
27
|
+
watchers = new Set();
|
|
28
|
+
pending;
|
|
29
|
+
drawing;
|
|
30
|
+
isDirty = false;
|
|
31
|
+
isClosed = false;
|
|
32
|
+
/** `generation`: where numbering continues when a session's agent is replaced, so later drawings stay newer. */
|
|
33
|
+
constructor(host, generation = 0) {
|
|
34
|
+
this.host = host;
|
|
35
|
+
this.generation = generation;
|
|
36
|
+
this.snapshot = { generation, band: null, panes: [] };
|
|
37
|
+
}
|
|
38
|
+
/** The latest drawing. */
|
|
39
|
+
current() {
|
|
40
|
+
return this.snapshot;
|
|
41
|
+
}
|
|
42
|
+
/** Watch every drawing from now on; returns the unsubscribe. */
|
|
43
|
+
watch(listener) {
|
|
44
|
+
this.watchers.add(listener);
|
|
45
|
+
listener(this.snapshot);
|
|
46
|
+
return () => { this.watchers.delete(listener); };
|
|
47
|
+
}
|
|
48
|
+
/** Something a drawing may depend on changed: draw again soon (folds bursts). */
|
|
49
|
+
invalidate() {
|
|
50
|
+
if (this.isClosed)
|
|
51
|
+
return;
|
|
52
|
+
if (this.pending !== undefined)
|
|
53
|
+
return;
|
|
54
|
+
// A mod's own `$.ui.open` or `$.ui.invalidate` asks for this redraw; a timer created in its hook would carry
|
|
55
|
+
// that hook's context into the redraw, and the engine would then skip the mod's hooks as a re-entry, drawing
|
|
56
|
+
// nothing. The redraw is the engine's, not the mod's call, so it is scheduled outside any hook's context.
|
|
57
|
+
const schedule = () => {
|
|
58
|
+
this.pending = setTimeout(() => {
|
|
59
|
+
this.pending = undefined;
|
|
60
|
+
void this.refresh();
|
|
61
|
+
}, 40);
|
|
62
|
+
this.pending.unref?.();
|
|
63
|
+
};
|
|
64
|
+
if (this.host.detached !== undefined)
|
|
65
|
+
this.host.detached(schedule);
|
|
66
|
+
else
|
|
67
|
+
schedule();
|
|
68
|
+
}
|
|
69
|
+
/** A mod opened a pane (`$.ui.open`). */
|
|
70
|
+
open(plugin, args) {
|
|
71
|
+
const id = String(args['id'] ?? '');
|
|
72
|
+
if (!/^[A-Za-z0-9_-]{1,64}$/u.test(id))
|
|
73
|
+
throw new Error('a pane id is 1-64 letters, digits, "_" or "-"');
|
|
74
|
+
const prior = this.panes.get(id);
|
|
75
|
+
if (prior !== undefined && prior.plugin !== plugin)
|
|
76
|
+
throw new Error(`pane ${id} is ${prior.plugin}'s`);
|
|
77
|
+
this.panes.set(id, { plugin, title: typeof args['title'] === 'string' ? args['title'] : prior?.title ?? id, isFocused: args['focus'] === true });
|
|
78
|
+
this.invalidate();
|
|
79
|
+
return { isPlaced: true };
|
|
80
|
+
}
|
|
81
|
+
/** A pane closes, by its mod or the person; the hooks of `ui.close` have let it. */
|
|
82
|
+
close(id) {
|
|
83
|
+
if (this.panes.delete(id))
|
|
84
|
+
this.invalidate();
|
|
85
|
+
}
|
|
86
|
+
/** The open panes, as `$.ui.panes()` lists them. */
|
|
87
|
+
list() {
|
|
88
|
+
return [...this.panes].map(([id, pane]) => ({ id, plugin: pane.plugin, title: pane.title, placement: 'dock', isFocused: pane.isFocused }));
|
|
89
|
+
}
|
|
90
|
+
/** Whose pane an id is. */
|
|
91
|
+
owner(id) {
|
|
92
|
+
return this.panes.get(id)?.plugin;
|
|
93
|
+
}
|
|
94
|
+
dispose() {
|
|
95
|
+
this.isClosed = true;
|
|
96
|
+
if (this.pending !== undefined)
|
|
97
|
+
clearTimeout(this.pending);
|
|
98
|
+
this.watchers.clear();
|
|
99
|
+
}
|
|
100
|
+
/** Draw the band and every pane. */
|
|
101
|
+
async refresh() {
|
|
102
|
+
if (this.drawing !== undefined) {
|
|
103
|
+
this.isDirty = true;
|
|
104
|
+
await this.drawing;
|
|
105
|
+
return this.snapshot;
|
|
106
|
+
}
|
|
107
|
+
this.drawing = this.draw();
|
|
108
|
+
try {
|
|
109
|
+
await this.drawing;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
this.drawing = undefined;
|
|
113
|
+
}
|
|
114
|
+
if (this.isDirty) {
|
|
115
|
+
this.isDirty = false;
|
|
116
|
+
return this.refresh();
|
|
117
|
+
}
|
|
118
|
+
return this.snapshot;
|
|
119
|
+
}
|
|
120
|
+
async draw() {
|
|
121
|
+
const actions = new Map();
|
|
122
|
+
const band = await this.render('AbovePrompt', BAND_ID, undefined, {
|
|
123
|
+
hasSurvey: false,
|
|
124
|
+
isWorking: this.host.isWorking(),
|
|
125
|
+
maxRows: ROWS,
|
|
126
|
+
bodyColumns: COLUMNS,
|
|
127
|
+
scroll: { offset: 0, bodyRows: ROWS },
|
|
128
|
+
view: {},
|
|
129
|
+
}, { columns: COLUMNS, rows: ROWS }, actions);
|
|
130
|
+
const panes = [];
|
|
131
|
+
for (const [id, pane] of this.panes) {
|
|
132
|
+
const drawn = await this.render('Pane', id, pane.plugin, {
|
|
133
|
+
title: pane.title,
|
|
134
|
+
isFocused: pane.isFocused,
|
|
135
|
+
bodyColumns: PANE_COLUMNS,
|
|
136
|
+
placement: 'dock',
|
|
137
|
+
scroll: { offset: 0, bodyRows: PANE_ROWS },
|
|
138
|
+
view: {},
|
|
139
|
+
}, { columns: PANE_COLUMNS, rows: PANE_ROWS, isFullscreen: false }, actions);
|
|
140
|
+
panes.push({ plugin: pane.plugin, id, title: pane.title, tree: drawn.tree, ...(drawn.error !== undefined ? { error: drawn.error } : {}) });
|
|
141
|
+
}
|
|
142
|
+
this.actions = actions;
|
|
143
|
+
this.snapshot = { generation: ++this.generation, band: band.tree, ...(band.error !== undefined ? { bandError: band.error } : {}), panes };
|
|
144
|
+
for (const watcher of [...this.watchers]) {
|
|
145
|
+
try {
|
|
146
|
+
watcher(this.snapshot);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
this.host.report(`a surface watcher failed: ${messageOf(error)}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async render(component, requestId, plugin, props, viewport, actions) {
|
|
154
|
+
let tree;
|
|
155
|
+
try {
|
|
156
|
+
tree = await this.host.raise('ui.render', { surface: SURFACE, component, requestId, viewport, props, ...(plugin !== undefined ? { plugin } : {}) });
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return { tree: null, error: messageOf(error) };
|
|
160
|
+
}
|
|
161
|
+
const problem = validate(tree);
|
|
162
|
+
if (problem !== undefined)
|
|
163
|
+
return { tree: null, error: `the desktop surface cannot draw it: ${problem}` };
|
|
164
|
+
const owner = plugin ?? '';
|
|
165
|
+
return { tree: serialize(tree, component, requestId, owner, actions) };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The person acted on a control of the drawing at `generation`: its event
|
|
169
|
+
* (`ui.press`, `ui.input`, `ui.select`) runs, the callback last.
|
|
170
|
+
*/
|
|
171
|
+
async act(generation, actionId, value) {
|
|
172
|
+
const action = this.actions.get(actionId);
|
|
173
|
+
if (action === undefined || generation !== this.snapshot.generation) {
|
|
174
|
+
throw new Error('that control is no longer drawn; the band or pane has been drawn again');
|
|
175
|
+
}
|
|
176
|
+
const base = { plugin: action.plugin, element: action.element, component: action.component, requestId: action.requestId, surface: SURFACE };
|
|
177
|
+
if (action.kind === 'press' || action.kind === 'link') {
|
|
178
|
+
await this.host.raise('ui.press', { ...base, ...(action.kind === 'link' ? { link: value } : {}) });
|
|
179
|
+
}
|
|
180
|
+
else if (action.kind === 'select') {
|
|
181
|
+
await this.host.raise('ui.select', { ...base, value: String(value ?? '') });
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
await this.host.raise('ui.input', { ...base, value: String(value ?? ''), kind: action.kind === 'submit' ? 'submit' : 'change' });
|
|
185
|
+
}
|
|
186
|
+
return this.refresh();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The person moved the keyboard focus to a control, or scrolled a pane or
|
|
190
|
+
* the band: `ui.focus` / `ui.scroll`, origin `person`. A hook may
|
|
191
|
+
* refuse it or handle it; the drawing follows either way.
|
|
192
|
+
*/
|
|
193
|
+
async move(kind, target) {
|
|
194
|
+
const pane = typeof target['pane'] === 'string' ? target['pane'] : undefined;
|
|
195
|
+
const component = pane === undefined ? 'AbovePrompt' : 'Pane';
|
|
196
|
+
const requestId = pane ?? BAND_ID;
|
|
197
|
+
const owner = pane === undefined ? undefined : this.panes.get(pane)?.plugin;
|
|
198
|
+
const input = kind === 'focus'
|
|
199
|
+
? {
|
|
200
|
+
component,
|
|
201
|
+
requestId,
|
|
202
|
+
...(typeof target['element'] === 'string' ? { element: target['element'] } : {}),
|
|
203
|
+
...(owner !== undefined ? { plugin: owner } : {}),
|
|
204
|
+
origin: { kind: 'person' },
|
|
205
|
+
}
|
|
206
|
+
: {
|
|
207
|
+
component,
|
|
208
|
+
requestId,
|
|
209
|
+
offset: Number(target['offset']) || 0,
|
|
210
|
+
by: Number(target['by']) || 0,
|
|
211
|
+
bodyRows: Number(target['bodyRows']) || PANE_ROWS,
|
|
212
|
+
contentRows: Number(target['contentRows']) || PANE_ROWS,
|
|
213
|
+
origin: { kind: 'person' },
|
|
214
|
+
...(owner !== undefined ? { plugin: owner } : {}),
|
|
215
|
+
};
|
|
216
|
+
const result = await this.host.raise(kind === 'focus' ? 'ui.focus' : 'ui.scroll', input).catch((error) => ({ deny: messageOf(error) }));
|
|
217
|
+
const snapshot = await this.refresh();
|
|
218
|
+
return { snapshot, ...(typeof result['deny'] === 'string' ? { refused: result['deny'] } : {}) };
|
|
219
|
+
}
|
|
220
|
+
/** Core of a control's event: its callback, in its mod's environment. */
|
|
221
|
+
async runCallback(event, e) {
|
|
222
|
+
const kind = event === 'ui.select' ? ['select'] : event === 'ui.input' ? [e['kind'] === 'change' ? 'input' : 'submit', 'input'] : e['link'] !== undefined ? ['link', 'press'] : ['press'];
|
|
223
|
+
const action = [...this.actions.values()].find(item => item.element === e['element'] && item.requestId === e['requestId'] && kind.includes(item.kind));
|
|
224
|
+
if (action === undefined)
|
|
225
|
+
throw new Error(`no control keyed ${String(e['element'])} is drawn`);
|
|
226
|
+
const argument = event === 'ui.press' ? (e['link'] !== undefined ? [e['link'], e] : []) : [e['value'], e];
|
|
227
|
+
await action.fn(...argument);
|
|
228
|
+
return { element: action.element };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** Why the desktop surface cannot draw a tree, or undefined. */
|
|
232
|
+
function validate(tree) {
|
|
233
|
+
const table = elementTable(SURFACE);
|
|
234
|
+
let count = 0;
|
|
235
|
+
const visit = (node, depth) => {
|
|
236
|
+
if (node === null || node === undefined || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean')
|
|
237
|
+
return undefined;
|
|
238
|
+
if (Array.isArray(node)) {
|
|
239
|
+
for (const child of node) {
|
|
240
|
+
const problem = visit(child, depth);
|
|
241
|
+
if (problem !== undefined)
|
|
242
|
+
return problem;
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
if (!isRecord(node) || typeof node['type'] !== 'string')
|
|
247
|
+
return 'a node is neither text nor an element';
|
|
248
|
+
if (++count > 20_000)
|
|
249
|
+
return 'more than 20000 elements';
|
|
250
|
+
if (depth > 32)
|
|
251
|
+
return 'nested deeper than 32 levels';
|
|
252
|
+
if (node['type'] !== 'engine' && !(node['type'] in table))
|
|
253
|
+
return `${node['type']} is not a desktop element`;
|
|
254
|
+
const children = Array.isArray(node['children']) ? node['children'] : [];
|
|
255
|
+
return visit(children, depth + 1);
|
|
256
|
+
};
|
|
257
|
+
return visit(tree, 0);
|
|
258
|
+
}
|
|
259
|
+
let actionIds = 0;
|
|
260
|
+
function serialize(node, component, requestId, plugin, actions) {
|
|
261
|
+
if (node === null || node === undefined || typeof node === 'boolean')
|
|
262
|
+
return null;
|
|
263
|
+
if (typeof node === 'string' || typeof node === 'number')
|
|
264
|
+
return String(node);
|
|
265
|
+
if (Array.isArray(node)) {
|
|
266
|
+
const children = node.map(child => serialize(child, component, requestId, plugin, actions)).filter((child) => child !== null);
|
|
267
|
+
return { type: 'Box', props: { flexDirection: 'column' }, children };
|
|
268
|
+
}
|
|
269
|
+
if (!isRecord(node) || typeof node['type'] !== 'string' || node['type'] === 'engine')
|
|
270
|
+
return null;
|
|
271
|
+
const props = {};
|
|
272
|
+
const own = {};
|
|
273
|
+
// Whose control: the runtime's stamp, else the pane's owner.
|
|
274
|
+
const stamp = isRecord(node['press']) && typeof node['press']['plugin'] === 'string' ? node['press']['plugin'] : undefined;
|
|
275
|
+
const owner = stamp ?? plugin;
|
|
276
|
+
const source = isRecord(node['props']) ? node['props'] : {};
|
|
277
|
+
const key = typeof source['key'] === 'string' ? source['key'] : undefined;
|
|
278
|
+
for (const [name, value] of Object.entries(source)) {
|
|
279
|
+
const kind = HANDLER_PROPS[name];
|
|
280
|
+
if (kind !== undefined && typeof value === 'function') {
|
|
281
|
+
const id = `a${String(++actionIds)}`;
|
|
282
|
+
actions.set(id, { kind, fn: value, plugin: owner, element: key ?? String(source['label'] ?? node['type']), component, requestId });
|
|
283
|
+
own[kind] = id;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (typeof value === 'function')
|
|
287
|
+
continue;
|
|
288
|
+
const kept = plain(value);
|
|
289
|
+
if (kept !== undefined)
|
|
290
|
+
props[name] = kept;
|
|
291
|
+
}
|
|
292
|
+
const children = (Array.isArray(node['children']) ? node['children'] : [])
|
|
293
|
+
.map(child => serialize(child, component, requestId, owner, actions))
|
|
294
|
+
.filter((child) => child !== null);
|
|
295
|
+
return { type: node['type'], props, children, ...(Object.keys(own).length > 0 ? { actions: own } : {}) };
|
|
296
|
+
}
|
|
297
|
+
/** JSON data only: what is not (a function, undefined, a non-finite number) is left out. */
|
|
298
|
+
function plain(value) {
|
|
299
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
300
|
+
return value;
|
|
301
|
+
if (typeof value === 'number')
|
|
302
|
+
return Number.isFinite(value) ? (Object.is(value, -0) ? 0 : value) : undefined;
|
|
303
|
+
if (Array.isArray(value))
|
|
304
|
+
return value.map(plain).filter(item => item !== undefined);
|
|
305
|
+
if (isRecord(value)) {
|
|
306
|
+
return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, plain(item)]).filter(([, item]) => item !== undefined));
|
|
307
|
+
}
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-data helpers for the mods engine: events and results cross between a
|
|
3
|
+
* mod's environment and the host as deeply frozen plain data.
|
|
4
|
+
* @module @kirkchinese/harness-forge/mods
|
|
5
|
+
*/
|
|
6
|
+
/** Whether a value is a RegExp, from any realm. */
|
|
7
|
+
export declare function isRegExp(value: unknown): value is RegExp;
|
|
8
|
+
/** Whether a value is a plain object (not an array, RegExp or null), from any realm. */
|
|
9
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
10
|
+
/** Whether a value is a promise-like, from any realm. */
|
|
11
|
+
export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Deeply freeze a value in place and return it. Functions (a Button's
|
|
14
|
+
* `onPress`) stay callable; they are frozen as objects only.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deepFreeze<T>(value: T, depth?: number): T;
|
|
17
|
+
/**
|
|
18
|
+
* A frozen copy of an event as it crosses into the chain: plain objects and
|
|
19
|
+
* arrays are copied; functions, RegExps and other objects are kept by
|
|
20
|
+
* reference (a render tree's callbacks must stay the plugin's own).
|
|
21
|
+
*/
|
|
22
|
+
export declare function frozenCopy<T>(value: T, depth?: number): T;
|
|
23
|
+
/** JSON round trip, as `$.store.set` keeps values. */
|
|
24
|
+
export declare function jsonCopy(value: unknown): unknown;
|
|
25
|
+
/** Structural equality over plain data (cross-realm), as `toEqual` reads it. */
|
|
26
|
+
export declare function plainEqual(a: unknown, b: unknown): boolean;
|
|
27
|
+
/** An error's text as Claude Code's notices print it: `Error: boom`. */
|
|
28
|
+
export declare function errorLine(error: unknown): string;
|
|
29
|
+
/** An error's message alone. */
|
|
30
|
+
export declare function messageOf(error: unknown): string;
|