@kirkchinese/harness-forge 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/assets/icon.svg +12 -0
- package/cordis.patch.yml +28 -0
- package/docs/DETAIL.zh.md +47 -0
- package/lib/agents/presets.d.ts +98 -0
- package/lib/agents/presets.js +292 -0
- package/lib/agents/profiles.d.ts +58 -0
- package/lib/agents/profiles.js +279 -0
- package/lib/agents/row.d.ts +17 -0
- package/lib/agents/row.js +148 -0
- package/lib/client/paths.d.ts +12 -0
- package/lib/client/paths.js +68 -0
- package/lib/client/styles.d.ts +8 -0
- package/lib/client/styles.js +89 -0
- package/lib/client/typert.d.ts +25 -0
- package/lib/client/typert.js +158 -0
- package/lib/client.js +23823 -0
- package/lib/commands/definition.d.ts +40 -0
- package/lib/commands/definition.js +113 -0
- package/lib/commands/output-styles.d.ts +42 -0
- package/lib/commands/output-styles.js +152 -0
- package/lib/commands/row.d.ts +9 -0
- package/lib/commands/row.js +157 -0
- package/lib/context/instructions.d.ts +32 -0
- package/lib/context/instructions.js +88 -0
- package/lib/context/row.d.ts +16 -0
- package/lib/context/row.js +17 -0
- package/lib/dsh/commands.d.ts +30 -0
- package/lib/dsh/commands.js +61 -0
- package/lib/dsh/host.d.ts +110 -0
- package/lib/dsh/host.js +217 -0
- package/lib/dsh/model-route.d.ts +21 -0
- package/lib/dsh/model-route.js +37 -0
- package/lib/dsh/session-records.d.ts +78 -0
- package/lib/dsh/session-records.js +36 -0
- package/lib/dsh/subagents.d.ts +46 -0
- package/lib/dsh/subagents.js +14 -0
- package/lib/forge/contract.d.ts +271 -0
- package/lib/forge/contract.js +45 -0
- package/lib/forge/follow.d.ts +30 -0
- package/lib/forge/follow.js +73 -0
- package/lib/forge/ledger.d.ts +206 -0
- package/lib/forge/ledger.js +1005 -0
- package/lib/forge/live-mounts.d.ts +45 -0
- package/lib/forge/live-mounts.js +78 -0
- package/lib/forge/npm.d.ts +31 -0
- package/lib/forge/npm.js +60 -0
- package/lib/forge/projects.d.ts +97 -0
- package/lib/forge/projects.js +343 -0
- package/lib/forge/receipts.d.ts +5 -0
- package/lib/forge/receipts.js +31 -0
- package/lib/forge/remote/archive.d.ts +65 -0
- package/lib/forge/remote/archive.js +565 -0
- package/lib/forge/remote/code-parts.d.ts +18 -0
- package/lib/forge/remote/code-parts.js +76 -0
- package/lib/forge/remote/fetch.d.ts +265 -0
- package/lib/forge/remote/fetch.js +1133 -0
- package/lib/forge/remote/service.d.ts +256 -0
- package/lib/forge/remote/service.js +868 -0
- package/lib/forge/row.d.ts +32 -0
- package/lib/forge/row.js +59 -0
- package/lib/forge/service.d.ts +115 -0
- package/lib/forge/service.js +290 -0
- package/lib/forge/settings.d.ts +43 -0
- package/lib/forge/settings.js +122 -0
- package/lib/forge/state.d.ts +129 -0
- package/lib/forge/state.js +266 -0
- package/lib/forge/trust.d.ts +48 -0
- package/lib/forge/trust.js +107 -0
- package/lib/forge/turns.d.ts +13 -0
- package/lib/forge/turns.js +56 -0
- package/lib/hooks/broker/engine.d.ts +112 -0
- package/lib/hooks/broker/engine.js +722 -0
- package/lib/hooks/broker/helpers.d.ts +10 -0
- package/lib/hooks/broker/helpers.js +22 -0
- package/lib/hooks/broker/lifecycle.d.ts +65 -0
- package/lib/hooks/broker/lifecycle.js +342 -0
- package/lib/hooks/broker/session-events.d.ts +27 -0
- package/lib/hooks/broker/session-events.js +205 -0
- package/lib/hooks/broker/tools.d.ts +52 -0
- package/lib/hooks/broker/tools.js +424 -0
- package/lib/hooks/broker/types.d.ts +264 -0
- package/lib/hooks/broker/types.js +1 -0
- package/lib/hooks/broker.d.ts +80 -0
- package/lib/hooks/broker.js +95 -0
- package/lib/hooks/codex-user.d.ts +5 -0
- package/lib/hooks/codex-user.js +109 -0
- package/lib/hooks/condition.d.ts +87 -0
- package/lib/hooks/condition.js +602 -0
- package/lib/hooks/config.d.ts +85 -0
- package/lib/hooks/config.js +154 -0
- package/lib/hooks/glob.d.ts +41 -0
- package/lib/hooks/glob.js +114 -0
- package/lib/hooks/matcher.d.ts +20 -0
- package/lib/hooks/matcher.js +39 -0
- package/lib/hooks/notice.d.ts +17 -0
- package/lib/hooks/notice.js +39 -0
- package/lib/hooks/output.d.ts +56 -0
- package/lib/hooks/output.js +214 -0
- package/lib/hooks/permissions.d.ts +19 -0
- package/lib/hooks/permissions.js +202 -0
- package/lib/hooks/powershell-aliases.d.ts +19 -0
- package/lib/hooks/powershell-aliases.js +58 -0
- package/lib/hooks/process.d.ts +64 -0
- package/lib/hooks/process.js +289 -0
- package/lib/hooks/row.d.ts +17 -0
- package/lib/hooks/row.js +96 -0
- package/lib/hooks/runner.d.ts +98 -0
- package/lib/hooks/runner.js +322 -0
- package/lib/hooks/shell-commands.d.ts +28 -0
- package/lib/hooks/shell-commands.js +241 -0
- package/lib/hooks/shell.d.ts +44 -0
- package/lib/hooks/shell.js +129 -0
- package/lib/hooks/transcript.d.ts +28 -0
- package/lib/hooks/transcript.js +141 -0
- package/lib/hooks/vocabulary.d.ts +57 -0
- package/lib/hooks/vocabulary.js +366 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +287 -0
- package/lib/mcp/auth.d.ts +35 -0
- package/lib/mcp/auth.js +178 -0
- package/lib/mcp/catalog.d.ts +39 -0
- package/lib/mcp/catalog.js +69 -0
- package/lib/mcp/mount.d.ts +113 -0
- package/lib/mcp/mount.js +317 -0
- package/lib/mcp/policy.d.ts +42 -0
- package/lib/mcp/policy.js +43 -0
- package/lib/mcp/remote.d.ts +45 -0
- package/lib/mcp/remote.js +133 -0
- package/lib/mcp/row.d.ts +9 -0
- package/lib/mcp/row.js +225 -0
- package/lib/mods/bundler.d.ts +38 -0
- package/lib/mods/bundler.js +157 -0
- package/lib/mods/chain.d.ts +103 -0
- package/lib/mods/chain.js +436 -0
- package/lib/mods/claude.d.ts +27 -0
- package/lib/mods/claude.js +56 -0
- package/lib/mods/engine.d.ts +160 -0
- package/lib/mods/engine.js +701 -0
- package/lib/mods/expect.d.ts +8 -0
- package/lib/mods/expect.js +248 -0
- package/lib/mods/host.d.ts +105 -0
- package/lib/mods/host.js +462 -0
- package/lib/mods/loader.d.ts +53 -0
- package/lib/mods/loader.js +231 -0
- package/lib/mods/ops.d.ts +13 -0
- package/lib/mods/ops.js +117 -0
- package/lib/mods/row.d.ts +9 -0
- package/lib/mods/row.js +77 -0
- package/lib/mods/runtime.d.ts +60 -0
- package/lib/mods/runtime.js +133 -0
- package/lib/mods/service/commands.d.ts +17 -0
- package/lib/mods/service/commands.js +121 -0
- package/lib/mods/service/drawings.d.ts +36 -0
- package/lib/mods/service/drawings.js +64 -0
- package/lib/mods/service/sessions.d.ts +63 -0
- package/lib/mods/service/sessions.js +345 -0
- package/lib/mods/service/tools.d.ts +32 -0
- package/lib/mods/service/tools.js +253 -0
- package/lib/mods/service/turns.d.ts +33 -0
- package/lib/mods/service/turns.js +136 -0
- package/lib/mods/service/types.d.ts +151 -0
- package/lib/mods/service/types.js +1 -0
- package/lib/mods/service.d.ts +72 -0
- package/lib/mods/service.js +104 -0
- package/lib/mods/surfaces.d.ts +93 -0
- package/lib/mods/surfaces.js +309 -0
- package/lib/mods/values.d.ts +30 -0
- package/lib/mods/values.js +95 -0
- package/lib/opencode/bun.d.ts +40 -0
- package/lib/opencode/bun.js +168 -0
- package/lib/opencode/convert.d.ts +53 -0
- package/lib/opencode/convert.js +255 -0
- package/lib/opencode/row.d.ts +22 -0
- package/lib/opencode/row.js +104 -0
- package/lib/opencode/runtime/core.d.ts +74 -0
- package/lib/opencode/runtime/core.js +249 -0
- package/lib/opencode/runtime/events.d.ts +80 -0
- package/lib/opencode/runtime/events.js +281 -0
- package/lib/opencode/runtime/mount.d.ts +27 -0
- package/lib/opencode/runtime/mount.js +283 -0
- package/lib/opencode/runtime/server.d.ts +27 -0
- package/lib/opencode/runtime/server.js +354 -0
- package/lib/opencode/runtime/types.d.ts +109 -0
- package/lib/opencode/runtime/types.js +1 -0
- package/lib/opencode/runtime.d.ts +55 -0
- package/lib/opencode/runtime.js +79 -0
- package/lib/porting/adapter-paths.d.ts +13 -0
- package/lib/porting/adapter-paths.js +120 -0
- package/lib/porting/port-gap.d.ts +36 -0
- package/lib/porting/port-gap.js +158 -0
- package/lib/porting/port-sessions.d.ts +41 -0
- package/lib/porting/port-sessions.js +98 -0
- package/lib/porting/prompt.d.ts +23 -0
- package/lib/porting/prompt.js +51 -0
- package/lib/porting/row.d.ts +16 -0
- package/lib/porting/row.js +27 -0
- package/lib/porting/verify-port.d.ts +46 -0
- package/lib/porting/verify-port.js +82 -0
- package/lib/presets/fs-search.d.ts +25 -0
- package/lib/presets/fs-search.js +17 -0
- package/lib/presets/tool-filter.d.ts +35 -0
- package/lib/presets/tool-filter.js +91 -0
- package/lib/sessions/chat-import.d.ts +48 -0
- package/lib/sessions/chat-import.js +44 -0
- package/lib/sessions/claude.d.ts +35 -0
- package/lib/sessions/claude.js +104 -0
- package/lib/sessions/codex-discover.d.ts +34 -0
- package/lib/sessions/codex-discover.js +205 -0
- package/lib/sessions/codex-meta.d.ts +63 -0
- package/lib/sessions/codex-meta.js +148 -0
- package/lib/sessions/codex-text.d.ts +9 -0
- package/lib/sessions/codex-text.js +44 -0
- package/lib/sessions/codex.d.ts +42 -0
- package/lib/sessions/codex.js +270 -0
- package/lib/sessions/opencode.d.ts +38 -0
- package/lib/sessions/opencode.js +339 -0
- package/lib/sessions/persist.d.ts +162 -0
- package/lib/sessions/persist.js +377 -0
- package/lib/sessions/row.d.ts +15 -0
- package/lib/sessions/row.js +101 -0
- package/lib/sessions/turns.d.ts +31 -0
- package/lib/sessions/turns.js +63 -0
- package/lib/sessions/zstd.d.ts +15 -0
- package/lib/sessions/zstd.js +152 -0
- package/lib/shared/invocation.d.ts +169 -0
- package/lib/shared/invocation.js +325 -0
- package/lib/shared/render.d.ts +101 -0
- package/lib/shared/render.js +1353 -0
- package/lib/shared/util.d.ts +21 -0
- package/lib/shared/util.js +32 -0
- package/lib/skills/bundled.d.ts +3 -0
- package/lib/skills/bundled.js +42 -0
- package/lib/skills/provider.d.ts +74 -0
- package/lib/skills/provider.js +346 -0
- package/lib/skills/row.d.ts +22 -0
- package/lib/skills/row.js +204 -0
- package/lib/workbench/adapter-coverage.d.ts +65 -0
- package/lib/workbench/adapter-coverage.js +141 -0
- package/lib/workbench/model-tools.d.ts +10 -0
- package/lib/workbench/model-tools.js +122 -0
- package/lib/workbench/overview.d.ts +153 -0
- package/lib/workbench/overview.js +246 -0
- package/lib/workbench/remote.d.ts +161 -0
- package/lib/workbench/remote.js +561 -0
- package/lib/workbench/row.d.ts +15 -0
- package/lib/workbench/row.js +16 -0
- package/lib/workbench/settings.d.ts +19 -0
- package/lib/workbench/settings.js +60 -0
- package/lib/workbench/workbench.d.ts +130 -0
- package/lib/workbench/workbench.js +361 -0
- package/locale/agents/en.json +6 -0
- package/locale/agents/zh.json +6 -0
- package/locale/commands/en.json +6 -0
- package/locale/commands/zh.json +6 -0
- package/locale/context/en.json +6 -0
- package/locale/context/zh.json +6 -0
- package/locale/en.json +6 -0
- package/locale/hooks/en.json +6 -0
- package/locale/hooks/zh.json +6 -0
- package/locale/mcp/en.json +6 -0
- package/locale/mcp/zh.json +6 -0
- package/locale/mods/en.json +6 -0
- package/locale/mods/zh.json +6 -0
- package/locale/opencode/en.json +6 -0
- package/locale/opencode/zh.json +6 -0
- package/locale/porter/en.json +6 -0
- package/locale/porter/zh.json +6 -0
- package/locale/sessions/en.json +6 -0
- package/locale/sessions/zh.json +6 -0
- package/locale/skills/en.json +6 -0
- package/locale/skills/zh.json +6 -0
- package/locale/workbench/en.json +6 -0
- package/locale/workbench/zh.json +6 -0
- package/locale/zh.json +7 -0
- package/package.json +247 -3
- package/runtime/opencode-host.mjs +270 -0
- package/skills/harness-forge/SKILL.md +47 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hook broker's types: what an imported hooks configuration, its host and
|
|
3
|
+
* a permission verdict look like, and structural views of the DSH objects the
|
|
4
|
+
* broker touches.
|
|
5
|
+
* @module @kirkchinese/harness-forge
|
|
6
|
+
*/
|
|
7
|
+
import type { FSWatcher } from 'node:fs';
|
|
8
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
9
|
+
import type { McpToolCall, McpToolVerdict } from '../../forge/contract.js';
|
|
10
|
+
import type { HookHandler, HookTable } from '../config.js';
|
|
11
|
+
import type { Decoded } from '../output.js';
|
|
12
|
+
import type { PermissionRuleSet } from '../permissions.js';
|
|
13
|
+
import type { ModelVerdict } from '../runner.js';
|
|
14
|
+
import type { ForeignShell } from '../shell.js';
|
|
15
|
+
import type { HookDialect } from '../vocabulary.js';
|
|
16
|
+
/** One imported hooks configuration. */
|
|
17
|
+
export interface HookSource {
|
|
18
|
+
readonly componentId: string;
|
|
19
|
+
readonly pluginId: string;
|
|
20
|
+
readonly dialect: HookDialect;
|
|
21
|
+
readonly pluginRoot: string;
|
|
22
|
+
readonly dataDir: string;
|
|
23
|
+
readonly table: HookTable;
|
|
24
|
+
/** Where the hooks are declared; only skill hooks honor `once`, only settings hooks deduplicate. */
|
|
25
|
+
readonly origin?: 'plugin' | 'settings' | 'skill' | 'agent';
|
|
26
|
+
/** Skill hooks: active in this session after the skill ran. */
|
|
27
|
+
readonly sessionId?: string;
|
|
28
|
+
/** Agent hooks: active while this delegated session runs; their `Stop` runs as `SubagentStop`. */
|
|
29
|
+
readonly agentSessionId?: string;
|
|
30
|
+
/** Plugin user-config values. */
|
|
31
|
+
readonly options?: Readonly<Record<string, string>>;
|
|
32
|
+
}
|
|
33
|
+
/** One handler run, reported to the evidence ledger. */
|
|
34
|
+
export interface HookObservation {
|
|
35
|
+
readonly componentId: string;
|
|
36
|
+
readonly event: string;
|
|
37
|
+
readonly ok: boolean;
|
|
38
|
+
readonly detail: string;
|
|
39
|
+
}
|
|
40
|
+
/** What the broker needs from its host. */
|
|
41
|
+
export interface HookBrokerHost {
|
|
42
|
+
readonly shell: ForeignShell;
|
|
43
|
+
/** Variables other runtimes add to a shell call's environment (OpenCode's `shell.env`). */
|
|
44
|
+
shellEnv?(exec: ToolExecutionLike): Promise<Record<string, string>>;
|
|
45
|
+
/** Profile-local writable directory: transcripts, env files, spilled output. */
|
|
46
|
+
readonly dataRoot: string;
|
|
47
|
+
observe(observation: HookObservation): void;
|
|
48
|
+
/** The foreign agent name (`plugin:agent`) of an imported agent preset. */
|
|
49
|
+
agentName(presetId: string): string | undefined;
|
|
50
|
+
/** The DSH preset of a foreign agent name. */
|
|
51
|
+
presetOf?(foreignName: string): string | undefined;
|
|
52
|
+
/** Hooks declared in an imported skill's frontmatter, by DSH skill name. */
|
|
53
|
+
skillHooks?(skillName: string): HookSource | undefined;
|
|
54
|
+
/** Hooks declared in an imported agent's frontmatter, by preset id. */
|
|
55
|
+
agentHooks?(presetId: string): HookSource | undefined;
|
|
56
|
+
/** Re-scan imported skills (SessionStart `reloadSkills`). */
|
|
57
|
+
reloadSkills?(): void;
|
|
58
|
+
/** Environment imported settings declare for a session, set for every hook process. */
|
|
59
|
+
environment?(session?: {
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly parentSession?: string;
|
|
62
|
+
}): Readonly<Record<string, string>>;
|
|
63
|
+
/** Imported Claude-syntax permission rules that gate a session's tool calls. */
|
|
64
|
+
permissionRules?(session?: {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly parentSession?: string;
|
|
67
|
+
}): PermissionRuleSet;
|
|
68
|
+
/** True while the settings in effect say `disableAllHooks: true`. */
|
|
69
|
+
hooksDisabled?(session?: {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly parentSession?: string;
|
|
72
|
+
}): boolean;
|
|
73
|
+
/** Load a new top-level session's project assets (its hooks among them) before SessionStart. */
|
|
74
|
+
prepareSession?(agent: unknown, cwd: string): Promise<void>;
|
|
75
|
+
/** A session ended: withdraw what `prepareSession` loaded. */
|
|
76
|
+
releaseSession?(sessionId: string): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Mods' `tool.check` over the verdict Claude Code would reach for a call
|
|
79
|
+
* (PreToolUse hooks, permission rules, the mode); returns the decision.
|
|
80
|
+
*/
|
|
81
|
+
check?(exec: unknown, verdict: ToolVerdict): Promise<ToolVerdict>;
|
|
82
|
+
/** Whether any mod hooks `tool.check` in the call's session. */
|
|
83
|
+
checks?(exec: unknown): boolean;
|
|
84
|
+
/** The registered server an `mcp_tool` hook of a plugin names (see `McpApi.hookServer`). */
|
|
85
|
+
mcpHookServer?(pluginId: string, server: string, sessionId?: string): string | undefined;
|
|
86
|
+
/** The MCP row's tool policy for a call an `mcp_tool` hook makes (see `McpApi.toolPolicy`). */
|
|
87
|
+
mcpToolPolicy?(call: McpToolCall): McpToolVerdict | undefined;
|
|
88
|
+
}
|
|
89
|
+
/** A permission verdict as Claude Code's `tool.check` carries it. */
|
|
90
|
+
export interface ToolVerdict {
|
|
91
|
+
readonly decision: 'allow' | 'ask' | 'deny';
|
|
92
|
+
readonly reason?: string;
|
|
93
|
+
readonly rule?: string;
|
|
94
|
+
readonly hook?: string;
|
|
95
|
+
}
|
|
96
|
+
/** Structural view of the DSH objects the broker touches. */
|
|
97
|
+
export interface AgentLike {
|
|
98
|
+
readonly id?: string;
|
|
99
|
+
readonly ctx?: unknown;
|
|
100
|
+
readonly options?: {
|
|
101
|
+
readonly provider?: string;
|
|
102
|
+
readonly model?: string;
|
|
103
|
+
readonly reasoningEffort?: string;
|
|
104
|
+
};
|
|
105
|
+
readonly status?: unknown;
|
|
106
|
+
readonly session: SessionLike;
|
|
107
|
+
inject(message: unknown): void;
|
|
108
|
+
steer(message: unknown): void;
|
|
109
|
+
followup(message: unknown): void;
|
|
110
|
+
cancel?(cause: {
|
|
111
|
+
kind: 'hook';
|
|
112
|
+
reason: string;
|
|
113
|
+
}): void;
|
|
114
|
+
}
|
|
115
|
+
export interface SessionLike {
|
|
116
|
+
readonly header: {
|
|
117
|
+
readonly id: string;
|
|
118
|
+
readonly cwd?: string;
|
|
119
|
+
readonly delegationDepth?: number;
|
|
120
|
+
readonly parentSession?: string;
|
|
121
|
+
};
|
|
122
|
+
readonly seq: number;
|
|
123
|
+
snapshotEvents(): ReadonlyArray<{
|
|
124
|
+
readonly type: string;
|
|
125
|
+
readonly time: number;
|
|
126
|
+
readonly data: unknown;
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
export interface ToolExecutionLike {
|
|
130
|
+
readonly name: string;
|
|
131
|
+
readonly arguments: unknown;
|
|
132
|
+
readonly callId?: string;
|
|
133
|
+
readonly agent?: AgentLike;
|
|
134
|
+
readonly signal: AbortSignal;
|
|
135
|
+
}
|
|
136
|
+
export interface ToolResultLike {
|
|
137
|
+
readonly isError: boolean;
|
|
138
|
+
readonly content: readonly ContentBlock[];
|
|
139
|
+
readonly value?: unknown;
|
|
140
|
+
readonly error?: {
|
|
141
|
+
readonly message?: string;
|
|
142
|
+
readonly info?: {
|
|
143
|
+
readonly code?: string;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export interface WorkingDirectoryLike {
|
|
148
|
+
ensure(agent: AgentLike, signal: AbortSignal): Promise<string>;
|
|
149
|
+
get(session: unknown): string | undefined;
|
|
150
|
+
}
|
|
151
|
+
/** One occurrence of a foreign event. */
|
|
152
|
+
export interface Occurrence {
|
|
153
|
+
readonly event: string;
|
|
154
|
+
/** The agent the event happens in. */
|
|
155
|
+
readonly agent?: AgentLike;
|
|
156
|
+
readonly signal: AbortSignal;
|
|
157
|
+
/** What a non-tool event matches on. */
|
|
158
|
+
readonly subject?: string;
|
|
159
|
+
readonly tool?: {
|
|
160
|
+
readonly dshName: string;
|
|
161
|
+
readonly args: unknown;
|
|
162
|
+
readonly callId?: string;
|
|
163
|
+
};
|
|
164
|
+
/** Event-specific payload fields. */
|
|
165
|
+
readonly fields?: Readonly<Record<string, unknown>>;
|
|
166
|
+
/** The command of a slash-command event, matched in both spellings. */
|
|
167
|
+
readonly subjects?: readonly string[];
|
|
168
|
+
readonly cwd?: string;
|
|
169
|
+
/** Fixed per-hook timeout default, when the event has its own. */
|
|
170
|
+
readonly defaultTimeoutMs?: number;
|
|
171
|
+
}
|
|
172
|
+
/** One handler's decoded outcome. */
|
|
173
|
+
export interface Ran {
|
|
174
|
+
readonly source: HookSource;
|
|
175
|
+
readonly handler: Exclude<HookHandler, {
|
|
176
|
+
type: 'invalid';
|
|
177
|
+
}>;
|
|
178
|
+
readonly decoded: Decoded;
|
|
179
|
+
readonly verdict?: ModelVerdict;
|
|
180
|
+
/** The block produced by `onFailure: "block"` or a suspect capture. */
|
|
181
|
+
readonly failureBlock?: string;
|
|
182
|
+
/** What the handler ran, for messages (`[cmd]`). */
|
|
183
|
+
readonly label: string;
|
|
184
|
+
/** The tool name the handler saw. */
|
|
185
|
+
readonly toolName?: string;
|
|
186
|
+
}
|
|
187
|
+
/** Per-session state. */
|
|
188
|
+
export interface SessionState {
|
|
189
|
+
lastTurn?: number;
|
|
190
|
+
promptId?: string;
|
|
191
|
+
stopActive: boolean;
|
|
192
|
+
stopContinuations: number;
|
|
193
|
+
/** Tool calls of the current step, for PostToolBatch. */
|
|
194
|
+
batch: Array<{
|
|
195
|
+
tool_name: string;
|
|
196
|
+
tool_input: unknown;
|
|
197
|
+
tool_use_id?: string;
|
|
198
|
+
tool_response: unknown;
|
|
199
|
+
}>;
|
|
200
|
+
/** Expanded command prompts already checked by UserPromptSubmit. */
|
|
201
|
+
expanded: Set<string>;
|
|
202
|
+
/** Last async SessionStart text per handler, to skip unchanged repeats. */
|
|
203
|
+
asyncSessionStart: Map<string, string>;
|
|
204
|
+
watchers: FSWatcher[];
|
|
205
|
+
watchPaths: string[];
|
|
206
|
+
}
|
|
207
|
+
export interface PreStepPayload {
|
|
208
|
+
readonly agent: AgentLike;
|
|
209
|
+
readonly messages: ReadonlyArray<{
|
|
210
|
+
readonly content: readonly ContentBlock[];
|
|
211
|
+
readonly source?: {
|
|
212
|
+
readonly kind?: string;
|
|
213
|
+
};
|
|
214
|
+
}>;
|
|
215
|
+
readonly turn: number;
|
|
216
|
+
readonly signal: AbortSignal;
|
|
217
|
+
}
|
|
218
|
+
export type PreStepDecision = {
|
|
219
|
+
readonly kind: string;
|
|
220
|
+
readonly messages?: readonly unknown[];
|
|
221
|
+
};
|
|
222
|
+
export type PostDecision = {
|
|
223
|
+
readonly kind: string;
|
|
224
|
+
readonly additionalContexts?: readonly unknown[];
|
|
225
|
+
readonly [key: string]: unknown;
|
|
226
|
+
};
|
|
227
|
+
/** DSH's question to the person (`user-questions/request`). */
|
|
228
|
+
export interface QuestionRequest {
|
|
229
|
+
readonly questions: ReadonlyArray<{
|
|
230
|
+
readonly id: string;
|
|
231
|
+
readonly question: string;
|
|
232
|
+
readonly header?: string;
|
|
233
|
+
readonly options?: ReadonlyArray<{
|
|
234
|
+
readonly label: string;
|
|
235
|
+
readonly description?: string;
|
|
236
|
+
}>;
|
|
237
|
+
readonly multiSelect?: boolean;
|
|
238
|
+
}>;
|
|
239
|
+
readonly agent?: AgentLike;
|
|
240
|
+
signal?: AbortSignal;
|
|
241
|
+
readonly wait?: {
|
|
242
|
+
readonly callId: string;
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
export interface QuestionAnswer {
|
|
246
|
+
readonly answers: ReadonlyArray<{
|
|
247
|
+
readonly id: string;
|
|
248
|
+
readonly selected: readonly string[];
|
|
249
|
+
readonly custom?: string;
|
|
250
|
+
}>;
|
|
251
|
+
}
|
|
252
|
+
export interface ApprovalRequest {
|
|
253
|
+
readonly agent: AgentLike;
|
|
254
|
+
readonly toolName: string;
|
|
255
|
+
readonly callId?: string;
|
|
256
|
+
readonly reason?: string;
|
|
257
|
+
readonly signal?: AbortSignal;
|
|
258
|
+
}
|
|
259
|
+
export interface ToolDefinitionLike {
|
|
260
|
+
execute(args: unknown, exec: unknown): Promise<unknown>;
|
|
261
|
+
readonly output: {
|
|
262
|
+
render(args: unknown, value: unknown): ContentBlock[];
|
|
263
|
+
};
|
|
264
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One hook broker for every imported plugin. Each foreign hooks configuration
|
|
3
|
+
* becomes a source; the broker listens once on DSH's interception points,
|
|
4
|
+
* presents each occurrence to the matching handlers in their own dialect
|
|
5
|
+
* (event names, matchers, tool names and shapes, payload fields, transcript),
|
|
6
|
+
* runs the handlers in parallel, and applies their combined outcome the way
|
|
7
|
+
* Claude Code or Codex does: blocking, rewriting input or output, adding
|
|
8
|
+
* context, continuing or stopping the turn, notifying the user.
|
|
9
|
+
*
|
|
10
|
+
* | Foreign event | DSH seam |
|
|
11
|
+
* | SessionStart / SubagentStart | `agent/created` of a root / delegated agent |
|
|
12
|
+
* | UserPromptSubmit, PostToolBatch, PreModelRequest | `agent/pre-step` |
|
|
13
|
+
* | UserPromptExpansion | an imported command's handler |
|
|
14
|
+
* | PreToolUse | `tools/pre-execute`; `updatedInput` runs through `tools/execute` |
|
|
15
|
+
* | PermissionRequest | `approval/request` |
|
|
16
|
+
* | PostToolUse / PostToolUseFailure | `tools/post-execute` |
|
|
17
|
+
* | Stop / SubagentStop | `agent/turn-stopping` of a root / delegated agent |
|
|
18
|
+
* | SessionEnd | `agent/disposed` |
|
|
19
|
+
* | PreCompact, PostCompact, StopFailure, Notification, CwdChanged, Interrupt, PostModelRequest | committed session events |
|
|
20
|
+
* | FileChanged | a file watcher |
|
|
21
|
+
* @module @kirkchinese/harness-forge
|
|
22
|
+
*/
|
|
23
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
24
|
+
import type { AgentLike, HookBrokerHost, HookSource } from './broker/types.js';
|
|
25
|
+
export type { HookBrokerHost, HookObservation, HookSource, ToolVerdict } from './broker/types.js';
|
|
26
|
+
/** Coordinates every imported hooks configuration. */
|
|
27
|
+
export declare class HookBroker {
|
|
28
|
+
private readonly ctx;
|
|
29
|
+
private readonly engine;
|
|
30
|
+
private readonly events;
|
|
31
|
+
private readonly lifecycle;
|
|
32
|
+
private readonly tools;
|
|
33
|
+
constructor(ctx: Context, host: HookBrokerHost);
|
|
34
|
+
/** Register one source; the returned disposer removes it. */
|
|
35
|
+
add(source: HookSource): () => void;
|
|
36
|
+
/** Listen on every interception point. Returns the disposer for all of them. */
|
|
37
|
+
install(): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* DSH is exiting: the sessions still open end now, and their SessionEnd hooks start (within DSH's shutdown grace,
|
|
40
|
+
* so first). Harness Forge being reloaded or removed while DSH goes on ends no session.
|
|
41
|
+
*/
|
|
42
|
+
beginShutdown(): void;
|
|
43
|
+
/** Settle background hook runs (tests and shutdown). */
|
|
44
|
+
drain(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* An imported slash command was typed: `UserPromptSubmit` sees the typed
|
|
47
|
+
* line, then `UserPromptExpansion` sees the command. Returns the block
|
|
48
|
+
* message, or the context to send with the expanded prompt.
|
|
49
|
+
*/
|
|
50
|
+
expandCommand(agent: AgentLike, command: {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly foreignName: string;
|
|
53
|
+
readonly args: string;
|
|
54
|
+
readonly expanded: string;
|
|
55
|
+
}, signal: AbortSignal): Promise<{
|
|
56
|
+
blocked?: string;
|
|
57
|
+
context: string[];
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* The user typed `/skill args`: `UserPromptExpansion` sees the skill (the
|
|
61
|
+
* typed line already went through `UserPromptSubmit`). Returns the block
|
|
62
|
+
* message, or the reminders to send with the skill content.
|
|
63
|
+
*/
|
|
64
|
+
expandSkill(agent: AgentLike, skill: {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly foreignName: string;
|
|
67
|
+
readonly args: string;
|
|
68
|
+
readonly source: string;
|
|
69
|
+
}, signal: AbortSignal): Promise<{
|
|
70
|
+
blocked?: string;
|
|
71
|
+
context: string[];
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* The DSH arguments a pending call runs with after a hook rewrote them.
|
|
75
|
+
* The tool's own `tools/execute` listener reads this.
|
|
76
|
+
*/
|
|
77
|
+
rewriteOf(callId: string | undefined): Record<string, unknown> | undefined;
|
|
78
|
+
/** A mod rewrote a call's arguments (Claude vocabulary already mapped to DSH's): the hooks and the tool see them. */
|
|
79
|
+
rewrite(callId: string, args: Record<string, unknown>): void;
|
|
80
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { hostShuttingDown, onDsh } from '../dsh/host.js';
|
|
2
|
+
import { HookEngine } from './broker/engine.js';
|
|
3
|
+
import { SessionEvents } from './broker/session-events.js';
|
|
4
|
+
import { SessionLifecycle } from './broker/lifecycle.js';
|
|
5
|
+
import { ToolGate } from './broker/tools.js';
|
|
6
|
+
/** Coordinates every imported hooks configuration. */
|
|
7
|
+
export class HookBroker {
|
|
8
|
+
ctx;
|
|
9
|
+
engine;
|
|
10
|
+
events;
|
|
11
|
+
lifecycle;
|
|
12
|
+
tools;
|
|
13
|
+
constructor(ctx, host) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
this.engine = new HookEngine(ctx, host);
|
|
16
|
+
this.events = new SessionEvents(this.engine);
|
|
17
|
+
this.lifecycle = new SessionLifecycle(this.engine, this.events);
|
|
18
|
+
this.tools = new ToolGate(this.engine);
|
|
19
|
+
}
|
|
20
|
+
/** Register one source; the returned disposer removes it. */
|
|
21
|
+
add(source) {
|
|
22
|
+
return this.engine.add(source);
|
|
23
|
+
}
|
|
24
|
+
/** Listen on every interception point. Returns the disposer for all of them. */
|
|
25
|
+
install() {
|
|
26
|
+
const ctx = { on: (name, listener, options) => onDsh(this.ctx, name, listener, { ...options, owner: 'hooks' }) };
|
|
27
|
+
const disposers = [
|
|
28
|
+
ctx.on('agent/created', ((payload) => this.lifecycle.agentCreated(payload))),
|
|
29
|
+
ctx.on('agent/pre-step', ((payload, next) => this.lifecycle.preStep(payload, next))),
|
|
30
|
+
ctx.on('tools/pre-execute', ((exec, next) => this.tools.preTool(exec, next))),
|
|
31
|
+
ctx.on('tools/execute', ((exec, next) => this.tools.executeTool(exec, next))),
|
|
32
|
+
ctx.on('tools/post-execute', ((exec, result, next) => this.tools.postTool(exec, result, next))),
|
|
33
|
+
ctx.on('agent/turn-stopping', ((payload) => this.lifecycle.turnStopping(payload))),
|
|
34
|
+
ctx.on('agent/disposed', ((payload) => this.lifecycle.agentDisposed(payload.agent))),
|
|
35
|
+
// Ahead of DSH's own answerer (the person), as PermissionRequest hooks and allow rules run before Claude Code shows its dialog.
|
|
36
|
+
ctx.on('approval/request', ((request, next) => this.tools.permission(request, next)), { prepend: true }),
|
|
37
|
+
// Claude Code's question dialog is a permission dialog too: PermissionRequest[AskUserQuestion] may answer or close it.
|
|
38
|
+
ctx.on('user-questions/request', ((request, next) => this.tools.question(request, next)), { prepend: true }),
|
|
39
|
+
ctx.on('session/event', ((session, event) => this.events.sessionEvent(session, event))),
|
|
40
|
+
];
|
|
41
|
+
return async () => {
|
|
42
|
+
for (const dispose of disposers)
|
|
43
|
+
dispose();
|
|
44
|
+
this.beginShutdown();
|
|
45
|
+
// SessionEnd hooks of sessions closed during shutdown keep their own budget.
|
|
46
|
+
await Promise.allSettled([...this.engine.ending]);
|
|
47
|
+
this.engine.lifetime.abort();
|
|
48
|
+
for (const timer of [...this.engine.notifyTimers.values(), ...this.engine.idleTimers.values()])
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
for (const state of this.engine.sessions.values())
|
|
51
|
+
for (const watcher of state.watchers)
|
|
52
|
+
watcher.close();
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* DSH is exiting: the sessions still open end now, and their SessionEnd hooks start (within DSH's shutdown grace,
|
|
57
|
+
* so first). Harness Forge being reloaded or removed while DSH goes on ends no session.
|
|
58
|
+
*/
|
|
59
|
+
beginShutdown() {
|
|
60
|
+
if (hostShuttingDown(this.ctx))
|
|
61
|
+
this.lifecycle.endLive();
|
|
62
|
+
}
|
|
63
|
+
/** Settle background hook runs (tests and shutdown). */
|
|
64
|
+
async drain() {
|
|
65
|
+
while (this.engine.detached.size > 0)
|
|
66
|
+
await Promise.allSettled([...this.engine.detached]);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An imported slash command was typed: `UserPromptSubmit` sees the typed
|
|
70
|
+
* line, then `UserPromptExpansion` sees the command. Returns the block
|
|
71
|
+
* message, or the context to send with the expanded prompt.
|
|
72
|
+
*/
|
|
73
|
+
expandCommand(agent, command, signal) {
|
|
74
|
+
return this.lifecycle.expandCommand(agent, command, signal);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The user typed `/skill args`: `UserPromptExpansion` sees the skill (the
|
|
78
|
+
* typed line already went through `UserPromptSubmit`). Returns the block
|
|
79
|
+
* message, or the reminders to send with the skill content.
|
|
80
|
+
*/
|
|
81
|
+
expandSkill(agent, skill, signal) {
|
|
82
|
+
return this.lifecycle.expandSkill(agent, skill, signal);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The DSH arguments a pending call runs with after a hook rewrote them.
|
|
86
|
+
* The tool's own `tools/execute` listener reads this.
|
|
87
|
+
*/
|
|
88
|
+
rewriteOf(callId) {
|
|
89
|
+
return this.tools.rewriteOf(callId);
|
|
90
|
+
}
|
|
91
|
+
/** A mod rewrote a call's arguments (Claude vocabulary already mapped to DSH's): the hooks and the tool see them. */
|
|
92
|
+
rewrite(callId, args) {
|
|
93
|
+
this.tools.rewrite(callId, args);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
/** Run Codex's `notify` program at every completed main-conversation turn. Returns the disposer. */
|
|
3
|
+
export declare function mountCodexNotify(ctx: Context, codexRoot: string, observe: (ok: boolean, detail: string) => void): () => void;
|
|
4
|
+
/** Add Codex's global instructions to the main conversation's system prompt. Returns the disposer. */
|
|
5
|
+
export declare function mountCodexInstructions(ctx: Context, codexRoot: string, file: string, observe: (ok: boolean, detail: string) => void): () => void;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of a user's Codex configuration that act at run time:
|
|
3
|
+
*
|
|
4
|
+
* - `notify`: when a turn of a main conversation completes, Codex runs the
|
|
5
|
+
* configured program with one more argument, a JSON object
|
|
6
|
+
* `{ type: "agent-turn-complete", "thread-id", "turn-id", cwd,
|
|
7
|
+
* "input-messages", "last-assistant-message" }`; so does DSH.
|
|
8
|
+
* - the global instructions (`AGENTS.override.md`, else `AGENTS.md`), which
|
|
9
|
+
* Codex adds to every conversation, as a section of the main system prompt.
|
|
10
|
+
* @module @kirkchinese/harness-forge
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from 'node:child_process';
|
|
13
|
+
import { readFileSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { readCodexConfig } from '@kirkchinese/harness-forge-core';
|
|
16
|
+
import { dshService, onDsh } from '../dsh/host.js';
|
|
17
|
+
/** Run Codex's `notify` program at every completed main-conversation turn. Returns the disposer. */
|
|
18
|
+
export function mountCodexNotify(ctx, codexRoot, observe) {
|
|
19
|
+
const argv = (Array.isArray(readCodexConfig(codexRoot)['notify']) ? readCodexConfig(codexRoot)['notify'] : []).filter((item) => typeof item === 'string');
|
|
20
|
+
if (argv.length === 0)
|
|
21
|
+
return () => { };
|
|
22
|
+
const on = (name, listener) => onDsh(ctx, name, listener);
|
|
23
|
+
return on('session/event', ((session, event) => {
|
|
24
|
+
if (event.type !== 'turn/end' || event.data.reason === 'aborted')
|
|
25
|
+
return;
|
|
26
|
+
const agent = dshService(ctx, 'agents')?.get(session.id);
|
|
27
|
+
if (agent === undefined || (agent.session.header.delegationDepth ?? 0) > 0)
|
|
28
|
+
return;
|
|
29
|
+
const payload = {
|
|
30
|
+
type: 'agent-turn-complete',
|
|
31
|
+
'thread-id': session.id,
|
|
32
|
+
'turn-id': String(event.data.turn ?? ''),
|
|
33
|
+
cwd: agent.session.header.cwd ?? process.cwd(),
|
|
34
|
+
'input-messages': turnInputs(agent, event.data.turn),
|
|
35
|
+
'last-assistant-message': lastAnswer(agent),
|
|
36
|
+
};
|
|
37
|
+
const [command = '', ...args] = argv;
|
|
38
|
+
try {
|
|
39
|
+
const child = spawn(command, [...args, JSON.stringify(payload)], { detached: true, stdio: 'ignore', windowsHide: true });
|
|
40
|
+
child.on('error', (error) => { observe(false, `notify could not start: ${error.message}`); });
|
|
41
|
+
child.on('spawn', () => { observe(true, `notify ran after turn ${String(event.data.turn ?? '')}`); });
|
|
42
|
+
child.unref();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
observe(false, `notify could not start: ${error instanceof Error ? error.message : String(error)}`);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
/** The user's messages of one turn, as text. */
|
|
50
|
+
function turnInputs(agent, turn) {
|
|
51
|
+
const out = [];
|
|
52
|
+
let inTurn = false;
|
|
53
|
+
for (let seq = 0; seq < agent.session.seq; seq++) {
|
|
54
|
+
const event = agent.session.eventAt(seq);
|
|
55
|
+
if (event === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
if (event.type === 'turn/start')
|
|
58
|
+
inTurn = event.data.turn === turn;
|
|
59
|
+
if (!inTurn || event.type !== 'user/message')
|
|
60
|
+
continue;
|
|
61
|
+
const message = event.data;
|
|
62
|
+
if (message.source?.kind !== 'user')
|
|
63
|
+
continue;
|
|
64
|
+
out.push((message.content ?? []).filter(block => block.type === 'text').map(block => block.text ?? '').join(''));
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function lastAnswer(agent) {
|
|
69
|
+
for (let seq = agent.session.seq - 1; seq >= 0; seq--) {
|
|
70
|
+
const event = agent.session.eventAt(seq);
|
|
71
|
+
if (event?.type !== 'assistant/message')
|
|
72
|
+
continue;
|
|
73
|
+
const message = event.data.message;
|
|
74
|
+
const text = (message?.content ?? []).filter(block => block.type === 'text').map(block => block.text ?? '').join('');
|
|
75
|
+
if (text.length > 0)
|
|
76
|
+
return text;
|
|
77
|
+
}
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
/** Add Codex's global instructions to the main conversation's system prompt. Returns the disposer. */
|
|
81
|
+
export function mountCodexInstructions(ctx, codexRoot, file, observe) {
|
|
82
|
+
const prompt = dshService(ctx, 'systemPrompt');
|
|
83
|
+
if (prompt === undefined)
|
|
84
|
+
return () => { };
|
|
85
|
+
const path = join(codexRoot, file);
|
|
86
|
+
let reported = false;
|
|
87
|
+
return prompt.section({
|
|
88
|
+
name: 'harness-forge:codex-instructions',
|
|
89
|
+
order: prompt.getSectionOrder('DEPLOYMENT_PERSONA_SUFFIX') - 2,
|
|
90
|
+
interpolate: false,
|
|
91
|
+
text: ({ scope }) => {
|
|
92
|
+
const depth = scope?.session?.header?.delegationDepth ?? 0;
|
|
93
|
+
if (depth > 0)
|
|
94
|
+
return '';
|
|
95
|
+
let text;
|
|
96
|
+
try {
|
|
97
|
+
text = readFileSync(path, 'utf8').trim();
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
102
|
+
if (!reported) {
|
|
103
|
+
reported = true;
|
|
104
|
+
observe(true, `${file} is in the system prompt`);
|
|
105
|
+
}
|
|
106
|
+
return text.length === 0 ? '' : `# Instructions from ~/.codex/${file}\n\n${text}`;
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type LinkReader } from '@kirkchinese/harness-forge-core';
|
|
2
|
+
import { type ForeignTool } from './vocabulary.js';
|
|
3
|
+
/** How a permission rule is used, which file rules depend on. */
|
|
4
|
+
export interface RuleUse {
|
|
5
|
+
/** Where a `/path` file rule anchors: the directory of the settings source that defines it (default: the working directory). */
|
|
6
|
+
readonly root?: string;
|
|
7
|
+
/** A deny or ask rule: `dir/**` matches at any depth, and a pattern naming a directory everything in it. */
|
|
8
|
+
readonly restricts?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Which path a file rule matches: the path as `spelled`, or its `real` path
|
|
11
|
+
* (see `realPathOf`; anchors resolved alike). Unset: a restricting answer
|
|
12
|
+
* (`unknown` true) matches either, an approving one only both.
|
|
13
|
+
*/
|
|
14
|
+
readonly path?: 'spelled' | 'real';
|
|
15
|
+
}
|
|
16
|
+
/** Whether a call is a file call that `Read(...)`/`Edit(...)` rules match by path. */
|
|
17
|
+
export declare function isFileCall(tool: ForeignTool): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether `rule` selects this tool call.
|
|
20
|
+
* @param cwd - the session's working directory, for relative file rules.
|
|
21
|
+
* @param unknown - the answer when a wildcard or what it is matched against is
|
|
22
|
+
* too large to match within budget: true (the default) for a hook's `if` (the
|
|
23
|
+
* hook runs) and for deny and ask rules, false for allow rules.
|
|
24
|
+
* @param use - how a permission rule is used, for file rules (see `RuleUse`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function conditionMatches(rule: string, tool: ForeignTool, cwd: string, unknown?: boolean, use?: RuleUse): boolean;
|
|
27
|
+
/** A file one redirection of a command reads or writes. */
|
|
28
|
+
export interface RedirectFile {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly reads: boolean;
|
|
31
|
+
readonly writes: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The path is known as written: not expanded at run time, not starting with
|
|
34
|
+
* `~` and without a glob character, which Claude Code always asks about
|
|
35
|
+
* (https://code.claude.com/docs/en/permissions#redirections).
|
|
36
|
+
*/
|
|
37
|
+
readonly plain: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The files the redirections of one simple command of `shell` read or write;
|
|
41
|
+
* undefined when its words cannot be read. Here-documents, here-strings,
|
|
42
|
+
* descriptor copies and closes (`2>&1`, `<&3`, `>&-`) and the shell's null
|
|
43
|
+
* device (see `nullDevice`) name no file.
|
|
44
|
+
*/
|
|
45
|
+
export declare function redirectFiles(command: string, shell: Shell): RedirectFile[] | undefined;
|
|
46
|
+
/** A shell whose words a command or rule is read as. */
|
|
47
|
+
export type Shell = 'bash' | 'powershell';
|
|
48
|
+
/** The shell that reads a shell call's command: PowerShell for DSH's `pwsh` tool, bash otherwise. */
|
|
49
|
+
export declare function shellOf(tool: ForeignTool): Shell;
|
|
50
|
+
/**
|
|
51
|
+
* Whether a gitignore-style pattern, relative to the working directory,
|
|
52
|
+
* matches a path as spelled (skill `paths`): no link is followed.
|
|
53
|
+
*/
|
|
54
|
+
export declare function pathPatternMatches(pattern: string, path: string, cwd: string): boolean;
|
|
55
|
+
/** The filesystem calls the resolver makes, and the platform whose paths it reads: the system's, or a test's. */
|
|
56
|
+
export interface RealPathSystem extends LinkReader {
|
|
57
|
+
readonly platform: NodeJS.Platform;
|
|
58
|
+
realpath(path: string): string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The real path of an absolute path, or undefined when it cannot be known (a
|
|
62
|
+
* link loop, more than {@link SYMLINK_HOPS} links, a link or folder that
|
|
63
|
+
* cannot be read, or, on Windows, a path or link that leads to a network share
|
|
64
|
+
* or device `base` is not on). What exists is resolved by the system; a part
|
|
65
|
+
* that does not exist yet is followed link by link (`readlink`), so a dangling
|
|
66
|
+
* link leads where a write through it would create its file. The one resolver
|
|
67
|
+
* file rules and redirection targets use; nothing else follows links.
|
|
68
|
+
*
|
|
69
|
+
* On Windows, opening, resolving or reading a link on `\\server\share` makes
|
|
70
|
+
* the system connect to that server and sign in with the person's credentials,
|
|
71
|
+
* and `realpath` follows links by itself. So before any call that could follow
|
|
72
|
+
* one, `linksReachNewShare` walks the path with `lstat` and `readlink` only;
|
|
73
|
+
* realpath runs only for a path that stays local (it is what expands a short
|
|
74
|
+
* name such as `RUNNER~1`).
|
|
75
|
+
* @param base - the working directory: a share it is on is not new.
|
|
76
|
+
*/
|
|
77
|
+
export declare function realPathOf(path: string, base: string, system?: RealPathSystem): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* A Windows path in the form rules match, as Claude Code writes them
|
|
80
|
+
* (https://code.claude.com/docs/en/permissions#where-a-pattern-anchors: "`C:\Users\alice` becomes `/c/Users/alice`"):
|
|
81
|
+
* either separator becomes `/`, the long-path prefix goes, a drive `C:` becomes `/c` and a share `\\server` stays
|
|
82
|
+
* `//server`. The whole path is compared without case, as Windows' file systems compare names by default, so the
|
|
83
|
+
* rule, the working directory and every path, spelled or real, go through this one function.
|
|
84
|
+
*/
|
|
85
|
+
export declare function windowsRulePath(path: string): string;
|
|
86
|
+
/** A rule-form Windows path (`/c/users/x`, `//server/share/x`) as Windows names it (`c:\users\x`). */
|
|
87
|
+
export declare function windowsNativePath(path: string): string;
|