typeclaw 0.50.0 → 0.52.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/dist/types/agent/bash-sandbox-env.d.ts +17 -0
- package/dist/types/agent/bash-sandbox-proc.d.ts +8 -0
- package/dist/types/agent/bash-sandbox.d.ts +98 -0
- package/dist/types/agent/compaction.d.ts +4 -4
- package/dist/types/agent/idle-compaction.d.ts +1 -0
- package/dist/types/agent/index.d.ts +10 -17
- package/dist/types/agent/multimodal/look-at.d.ts +1 -1
- package/dist/types/agent/output-allowance.d.ts +4 -0
- package/dist/types/agent/plugin-tools.d.ts +8 -75
- package/dist/types/agent/prompt-cache-key.d.ts +1 -0
- package/dist/types/agent/session-tail.d.ts +12 -0
- package/dist/types/agent/subagents.d.ts +5 -0
- package/dist/types/agent/system-prompt-composition.d.ts +18 -0
- package/dist/types/agent/system-prompt.d.ts +2 -0
- package/dist/types/agent/tools/channel-disengage.d.ts +1 -1
- package/dist/types/agent/tools/channel-edit.d.ts +1 -1
- package/dist/types/agent/tools/channel-fetch-attachment.d.ts +1 -1
- package/dist/types/agent/tools/channel-handoff.d.ts +1 -1
- package/dist/types/agent/tools/channel-history.d.ts +1 -1
- package/dist/types/agent/tools/channel-react.d.ts +1 -1
- package/dist/types/agent/tools/channel-read.d.ts +10 -2
- package/dist/types/agent/tools/channel-reply.d.ts +1 -1
- package/dist/types/agent/tools/channel-send.d.ts +1 -1
- package/dist/types/agent/tools/channel-session-search.d.ts +1 -1
- package/dist/types/agent/tools/ddg.d.ts +9 -0
- package/dist/types/agent/tools/grant-role.d.ts +1 -1
- package/dist/types/agent/tools/post-github-review.d.ts +1 -1
- package/dist/types/agent/tools/restart.d.ts +1 -1
- package/dist/types/agent/tools/skip-response.d.ts +1 -1
- package/dist/types/agent/tools/spawn-subagent.d.ts +2 -1
- package/dist/types/agent/tools/stream-snapshot.d.ts +2 -2
- package/dist/types/agent/tools/subagent-cancel.d.ts +1 -1
- package/dist/types/agent/tools/subagent-output.d.ts +1 -1
- package/dist/types/agent/tools/todo/index.d.ts +1 -1
- package/dist/types/agent/tools/webfetch/adaptive-html.d.ts +3 -3
- package/dist/types/agent/tools/webfetch/strategies/readability-process.d.ts +48 -0
- package/dist/types/agent/tools/webfetch/tool.d.ts +2 -2
- package/dist/types/agent/tools/websearch.d.ts +1 -1
- package/dist/types/channels/adapters/github/auth-app.d.ts +25 -0
- package/dist/types/channels/adapters/github/auth-pat.d.ts +17 -0
- package/dist/types/channels/adapters/github/auth.d.ts +24 -0
- package/dist/types/channels/github-review-check.d.ts +1 -1
- package/dist/types/channels/github-token-bridge.d.ts +4 -0
- package/dist/types/channels/lost-background-context.d.ts +2 -0
- package/dist/types/channels/persistence.d.ts +1 -0
- package/dist/types/channels/router.d.ts +16 -50
- package/dist/types/channels/types.d.ts +1 -0
- package/dist/types/coding-agent/tool.d.ts +1 -1
- package/dist/types/config/config.d.ts +22 -0
- package/dist/types/config/providers.d.ts +50 -1
- package/dist/types/container/start.d.ts +1 -0
- package/dist/types/eval/cell.d.ts +26 -0
- package/dist/types/eval/config.d.ts +19 -0
- package/dist/types/eval/dispatch.d.ts +7 -0
- package/dist/types/eval/kernel.d.ts +28 -0
- package/dist/types/eval/process.d.ts +23 -0
- package/dist/types/eval/protocol.d.ts +34 -0
- package/dist/types/eval/sandbox.d.ts +12 -0
- package/dist/types/eval/tool.d.ts +17 -0
- package/dist/types/eval/wire.d.ts +33 -0
- package/dist/types/git/resolve-identity.d.ts +2 -0
- package/dist/types/init/dockerfile.d.ts +1 -0
- package/dist/types/init/gitignore.d.ts +1 -1
- package/dist/types/permissions/builtins.d.ts +1 -0
- package/dist/types/plugin/types.d.ts +3 -0
- package/dist/types/sandbox/canonical-secrets.d.ts +2 -2
- package/dist/types/sandbox/coding-agent.d.ts +1 -1
- package/dist/types/sandbox/dependency-bins.d.ts +1 -0
- package/dist/types/sandbox/dev-source.d.ts +2 -2
- package/dist/types/sandbox/env-exposure.d.ts +2 -0
- package/dist/types/sandbox/hidden-paths.d.ts +1 -0
- package/dist/types/sandbox/index.d.ts +1 -1
- package/dist/types/sandbox/policy.d.ts +3 -0
- package/dist/types/typevault/cli-path.d.ts +2 -0
- package/dist/types/typevault/envelope-store.d.ts +11 -0
- package/dist/types/typevault/lifecycle.d.ts +13 -0
- package/dist/types/typevault/vault.d.ts +27 -0
- package/package.json +8 -7
- package/scripts/test.ts +252 -0
- package/src/agent/bash-sandbox-env.ts +136 -0
- package/src/agent/bash-sandbox-proc.ts +70 -0
- package/src/agent/bash-sandbox.ts +239 -0
- package/src/agent/compaction.ts +22 -10
- package/src/agent/idle-compaction.ts +7 -3
- package/src/agent/index.ts +185 -187
- package/src/agent/multimodal/look-at.ts +1 -1
- package/src/agent/output-allowance.ts +7 -0
- package/src/agent/plugin-tools.ts +64 -380
- package/src/agent/prompt-cache-key.ts +26 -3
- package/src/agent/session-origin.ts +41 -19
- package/src/agent/session-tail.ts +28 -0
- package/src/agent/subagent-completion-reminder.ts +2 -2
- package/src/agent/subagents.ts +21 -2
- package/src/agent/system-prompt-composition.ts +159 -0
- package/src/agent/system-prompt.ts +43 -5
- package/src/agent/todo/scope.ts +1 -1
- package/src/agent/tool-error-remediation.ts +18 -3
- package/src/agent/tools/channel-disengage.ts +1 -1
- package/src/agent/tools/channel-edit.ts +1 -1
- package/src/agent/tools/channel-fetch-attachment.ts +1 -1
- package/src/agent/tools/channel-handoff.ts +3 -2
- package/src/agent/tools/channel-history.ts +2 -1
- package/src/agent/tools/channel-react.ts +1 -1
- package/src/agent/tools/channel-read.ts +36 -3
- package/src/agent/tools/channel-reply.ts +1 -1
- package/src/agent/tools/channel-send.ts +4 -3
- package/src/agent/tools/channel-session-search.ts +13 -4
- package/src/agent/tools/ddg.ts +71 -11
- package/src/agent/tools/grant-role.ts +1 -1
- package/src/agent/tools/post-github-review.ts +1 -1
- package/src/agent/tools/restart.ts +1 -1
- package/src/agent/tools/skip-response.ts +1 -1
- package/src/agent/tools/spawn-subagent.ts +15 -1
- package/src/agent/tools/stream-snapshot.ts +1 -1
- package/src/agent/tools/subagent-cancel.ts +1 -1
- package/src/agent/tools/subagent-output.ts +1 -1
- package/src/agent/tools/todo/index.ts +1 -1
- package/src/agent/tools/webfetch/adaptive-html.ts +6 -4
- package/src/agent/tools/webfetch/strategies/readability-child.ts +25 -0
- package/src/agent/tools/webfetch/strategies/readability-process.ts +185 -0
- package/src/agent/tools/webfetch/tool.ts +6 -5
- package/src/agent/tools/websearch.ts +1 -1
- package/src/agent/tools-without-local-file-operands.ts +4 -0
- package/src/browser/dockerfile.ts +1 -1
- package/src/browser/fill-secret.ts +364 -0
- package/src/browser/registry.ts +6 -6
- package/src/bundled-plugins/agent-messenger-cli-auth/command.ts +211 -0
- package/src/bundled-plugins/agent-messenger-cli-auth/index.ts +186 -0
- package/src/bundled-plugins/backup/index.ts +17 -2
- package/src/bundled-plugins/backup/runner.ts +37 -2
- package/src/bundled-plugins/browser-agent/browser-agent.ts +51 -14
- package/src/bundled-plugins/browser-agent/index.ts +12 -5
- package/src/bundled-plugins/explorer/explorer.ts +1 -1
- package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +40 -16
- package/src/bundled-plugins/github-cli-auth/graphql-auth-nudge.ts +12 -7
- package/src/bundled-plugins/github-cli-auth/index.ts +10 -1
- package/src/bundled-plugins/managed-browser/index.ts +130 -2
- package/src/bundled-plugins/managed-browser/skills/browserskill/browserskill/SKILL.md +13 -5
- package/src/bundled-plugins/managed-browser/skills/omowright/omowright/SKILL.md +56 -5
- package/src/bundled-plugins/memory/README.md +23 -2
- package/src/bundled-plugins/memory/append-fragment.ts +133 -0
- package/src/bundled-plugins/memory/append-tool.ts +80 -149
- package/src/bundled-plugins/memory/dreaming.ts +6 -1
- package/src/bundled-plugins/memory/index.ts +33 -6
- package/src/bundled-plugins/memory/load-memory.ts +2 -4
- package/src/bundled-plugins/memory/memory-logger.ts +200 -6
- package/src/bundled-plugins/memory/references/store-reference-tool.ts +56 -32
- package/src/bundled-plugins/memory/remember-tool.ts +81 -0
- package/src/bundled-plugins/memory/search-tool-hybrid.ts +91 -0
- package/src/bundled-plugins/memory/search-tool.ts +58 -12
- package/src/bundled-plugins/memory/stream-events.ts +2 -0
- package/src/bundled-plugins/memory/transcript-cursor.ts +30 -0
- package/src/bundled-plugins/memory/transcript-preload.ts +208 -0
- package/src/bundled-plugins/memory/transcript-view.ts +36 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +25 -14
- package/src/bundled-plugins/memory/watermark.ts +19 -10
- package/src/bundled-plugins/reviewer/reviewer.ts +20 -0
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +3 -6
- package/src/bundled-plugins/security/policies/outbound-text.ts +20 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +166 -201
- package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -7
- package/src/bundled-plugins/typevault/grants.ts +119 -0
- package/src/bundled-plugins/typevault/index.ts +152 -0
- package/src/bundled-plugins/typevault/request.ts +87 -0
- package/src/bundled-plugins/typevault/runtime.ts +45 -0
- package/src/bundled-plugins/typevault/skills/typevault/SKILL.md +65 -0
- package/src/channels/adapter-halt.ts +17 -0
- package/src/channels/adapters/discord-bot-reference.ts +5 -4
- package/src/channels/adapters/discord-bot.ts +1 -0
- package/src/channels/adapters/discord-classify.ts +8 -3
- package/src/channels/adapters/discord.ts +29 -0
- package/src/channels/adapters/github/history.ts +23 -2
- package/src/channels/adapters/github/inbound.ts +60 -1
- package/src/channels/adapters/github/index.ts +27 -5
- package/src/channels/adapters/github/reconcile-open-prs.ts +7 -1
- package/src/channels/adapters/kakaotalk-author-resolver.ts +7 -5
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +45 -15
- package/src/channels/adapters/kakaotalk-classify.ts +7 -9
- package/src/channels/adapters/kakaotalk-list.ts +62 -0
- package/src/channels/adapters/kakaotalk-member-cache.ts +67 -0
- package/src/channels/adapters/kakaotalk-membership.ts +27 -10
- package/src/channels/adapters/kakaotalk-mention.ts +61 -0
- package/src/channels/adapters/kakaotalk.ts +159 -125
- package/src/channels/adapters/teams-classify.ts +18 -8
- package/src/channels/github-review-check.ts +5 -1
- package/src/channels/github-review-verdict-coordinator.ts +68 -2
- package/src/channels/github-token-bridge.ts +13 -0
- package/src/channels/lost-background-context.ts +46 -0
- package/src/channels/manager.ts +52 -3
- package/src/channels/persistence.ts +5 -0
- package/src/channels/router.ts +208 -128
- package/src/channels/schema.ts +1 -1
- package/src/channels/subagent-completion-bridge.ts +3 -2
- package/src/channels/types.ts +3 -0
- package/src/cli/hostd.ts +3 -0
- package/src/coding-agent/tool.ts +1 -1
- package/src/config/config.ts +35 -1
- package/src/config/providers.ts +75 -4
- package/src/container/start.ts +52 -3
- package/src/doctor/channel-checks.ts +33 -0
- package/src/doctor/checks.ts +37 -18
- package/src/doctor/index.ts +48 -12
- package/src/doctor/operational-incidents.ts +16 -1
- package/src/doctor/plugin-bridge.ts +14 -1
- package/src/doctor/stage.ts +14 -0
- package/src/doctor/types.ts +6 -0
- package/src/eval/cell.ts +93 -0
- package/src/eval/config.ts +32 -0
- package/src/eval/dispatch.ts +67 -0
- package/src/eval/entry.ts +261 -0
- package/src/eval/kernel.ts +154 -0
- package/src/eval/process.ts +113 -0
- package/src/eval/protocol.ts +26 -0
- package/src/eval/redeclare.ts +174 -0
- package/src/eval/sandbox.ts +117 -0
- package/src/eval/tool.ts +99 -0
- package/src/eval/wire.ts +93 -0
- package/src/git/resolve-identity.ts +67 -2
- package/src/git/system-commit.ts +7 -0
- package/src/init/dockerfile.ts +5 -1
- package/src/init/gitignore.ts +3 -3
- package/src/init/index.ts +1 -0
- package/src/init/models-dev.ts +2 -0
- package/src/init/validate-api-key.ts +5 -0
- package/src/migrations/secrets-v1-to-v2.ts +2 -0
- package/src/operations/classify-tool-outcome.ts +1 -1
- package/src/permissions/builtins.ts +8 -0
- package/src/plugin/core-tool-names.ts +6 -1
- package/src/plugin/types.ts +6 -0
- package/src/run/bundled-plugins.ts +12 -0
- package/src/run/channel-session-factory.ts +3 -0
- package/src/run/index.ts +13 -2
- package/src/sandbox/build.ts +1 -0
- package/src/sandbox/canonical-secrets.ts +6 -0
- package/src/sandbox/dependency-bins.ts +13 -1
- package/src/sandbox/dev-source.ts +21 -12
- package/src/sandbox/env-exposure.ts +20 -0
- package/src/sandbox/hidden-paths.ts +1 -1
- package/src/sandbox/index.ts +1 -0
- package/src/sandbox/policy.ts +5 -0
- package/src/secrets/hydrate.ts +4 -1
- package/src/secrets/storage.ts +10 -1
- package/src/server/command-runner.ts +4 -0
- package/src/server/index.ts +54 -12
- package/src/skills/typeclaw-config/SKILL.md +36 -2
- package/src/skills/typeclaw-memory/SKILL.md +3 -1
- package/src/skills/typeclaw-permissions/SKILL.md +8 -8
- package/src/skills/typeclaw-troubleshooting/SKILL.md +18 -1
- package/src/tunnels/active.ts +14 -0
- package/src/typevault/bash-cli.ts +18 -0
- package/src/typevault/cli-path.ts +11 -0
- package/src/typevault/envelope-helper.ts +17 -0
- package/src/typevault/envelope-store.ts +98 -0
- package/src/typevault/lifecycle.ts +132 -0
- package/src/typevault/prompt-tunnel.ts +33 -0
- package/src/typevault/redaction.ts +37 -0
- package/src/typevault/vault.ts +283 -0
- package/typeclaw.schema.json +92 -10
package/src/doctor/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DockerExec } from '@/container'
|
|
2
2
|
import { findAgentDir } from '@/init'
|
|
3
|
+
import { TYPECLAW_CLI_ENTRY } from '@/init/dockerfile'
|
|
3
4
|
import type { DoctorCheckPayload } from '@/shared'
|
|
4
5
|
|
|
5
6
|
import { buildStaticChecks } from './checks'
|
|
@@ -12,12 +13,14 @@ import {
|
|
|
12
13
|
type PluginBridgeFetchFix,
|
|
13
14
|
type PluginBridgeFixResult,
|
|
14
15
|
} from './plugin-bridge'
|
|
16
|
+
import { detectDoctorStage } from './stage'
|
|
15
17
|
import type {
|
|
16
18
|
CheckContext,
|
|
17
19
|
CheckResult,
|
|
18
20
|
DoctorCheck,
|
|
19
21
|
DoctorReport,
|
|
20
22
|
DoctorRunResult,
|
|
23
|
+
DoctorStage,
|
|
21
24
|
FixAttempt,
|
|
22
25
|
ReportEntry,
|
|
23
26
|
ReportSummary,
|
|
@@ -26,6 +29,7 @@ import type {
|
|
|
26
29
|
|
|
27
30
|
export * from './types'
|
|
28
31
|
export { buildStaticChecks } from './checks'
|
|
32
|
+
export { detectDoctorStage } from './stage'
|
|
29
33
|
export { formatJson, formatReport } from './report'
|
|
30
34
|
export { buildCommitMessage, commitAutoFixes } from './commit'
|
|
31
35
|
export {
|
|
@@ -39,6 +43,7 @@ export type RunDoctorOptions = {
|
|
|
39
43
|
cwd?: string
|
|
40
44
|
only?: string[]
|
|
41
45
|
fix?: boolean
|
|
46
|
+
stage?: DoctorStage
|
|
42
47
|
// Docker executor used by BOTH the static checks and plugin discovery, so a
|
|
43
48
|
// test can drive the whole command against one wedged daemon and prove the
|
|
44
49
|
// real sequencing terminates — not just each half in isolation.
|
|
@@ -53,27 +58,32 @@ export async function runDoctor(opts: RunDoctorOptions = {}): Promise<DoctorRunR
|
|
|
53
58
|
const cwd = opts.cwd ?? findAgentDir(process.cwd()) ?? process.cwd()
|
|
54
59
|
const hasAgentFolder = findAgentDir(cwd) === cwd
|
|
55
60
|
const ctx: CheckContext = { cwd, hasAgentFolder }
|
|
61
|
+
const stage = opts.stage ?? detectDoctorStage(cwd)
|
|
62
|
+
const inContainer = stage === 'container'
|
|
56
63
|
|
|
57
64
|
const staticChecks = (
|
|
58
65
|
opts.staticChecks ?? buildStaticChecks(opts.dockerExec === undefined ? {} : { dockerExec: opts.dockerExec })
|
|
59
|
-
).filter((c) => isAllowed(c, opts.only, c.category))
|
|
66
|
+
).filter((c) => isAllowed(c, opts.only, c.category) && !(inContainer && c.hostOnly === true))
|
|
60
67
|
const staticResults = await runStaticChecks(staticChecks, ctx)
|
|
61
68
|
|
|
62
69
|
const fetchPluginChecks =
|
|
63
70
|
opts.fetchPluginChecks ??
|
|
64
71
|
((bridgeOpts) =>
|
|
65
|
-
defaultFetchPluginDoctorChecks(
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
defaultFetchPluginDoctorChecks({
|
|
73
|
+
...bridgeOpts,
|
|
74
|
+
inContainer,
|
|
75
|
+
...(opts.dockerExec === undefined ? {} : { exec: opts.dockerExec }),
|
|
76
|
+
}))
|
|
68
77
|
const pluginResults = await collectPluginChecks(fetchPluginChecks, ctx, opts.only)
|
|
69
78
|
|
|
70
|
-
const initial = buildReport(ctx, staticResults, pluginResults)
|
|
79
|
+
const initial = buildReport(ctx, stage, staticResults, pluginResults)
|
|
71
80
|
|
|
72
81
|
if (opts.fix !== true || initial.ok) {
|
|
73
82
|
return { initial }
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
const fetchPluginFix =
|
|
85
|
+
const fetchPluginFix =
|
|
86
|
+
opts.fetchPluginFix ?? ((bridgeOpts) => defaultFetchPluginDoctorFix({ ...bridgeOpts, inContainer }))
|
|
77
87
|
const attempts: FixAttempt[] = []
|
|
78
88
|
attempts.push(...(await runStaticFixes(staticResults, ctx)))
|
|
79
89
|
attempts.push(...(await runPluginFixes(pluginResults.entries, fetchPluginFix, ctx)))
|
|
@@ -84,7 +94,7 @@ export async function runDoctor(opts: RunDoctorOptions = {}): Promise<DoctorRunR
|
|
|
84
94
|
|
|
85
95
|
const finalStaticResults = await runStaticChecks(staticChecks, ctx)
|
|
86
96
|
const finalPluginResults = await collectPluginChecks(fetchPluginChecks, ctx, opts.only)
|
|
87
|
-
const final = buildReport(ctx, finalStaticResults, finalPluginResults)
|
|
97
|
+
const final = buildReport(ctx, stage, finalStaticResults, finalPluginResults)
|
|
88
98
|
|
|
89
99
|
return { initial, fixAttempts: attempts, commit, final }
|
|
90
100
|
}
|
|
@@ -133,8 +143,14 @@ async function collectPluginChecks(
|
|
|
133
143
|
return { entries: filtered.map((payload) => ({ payload })), reachability }
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
function buildReport(
|
|
146
|
+
function buildReport(
|
|
147
|
+
ctx: CheckContext,
|
|
148
|
+
stage: DoctorStage,
|
|
149
|
+
staticResults: StaticResult[],
|
|
150
|
+
plugin: PluginCollect,
|
|
151
|
+
): DoctorReport {
|
|
137
152
|
const entries: ReportEntry[] = []
|
|
153
|
+
if (stage === 'container') entries.push(containerStageNote())
|
|
138
154
|
for (const { check, result } of staticResults) {
|
|
139
155
|
const entry: ReportEntry = {
|
|
140
156
|
name: check.name,
|
|
@@ -152,7 +168,7 @@ function buildReport(ctx: CheckContext, staticResults: StaticResult[], plugin: P
|
|
|
152
168
|
}
|
|
153
169
|
|
|
154
170
|
if (ctx.hasAgentFolder && plugin.reachability.kind !== 'ok') {
|
|
155
|
-
entries.push(reachabilityNote(plugin.reachability))
|
|
171
|
+
entries.push(reachabilityNote(plugin.reachability, stage))
|
|
156
172
|
}
|
|
157
173
|
|
|
158
174
|
for (const { payload } of plugin.entries) {
|
|
@@ -174,10 +190,25 @@ function buildReport(ctx: CheckContext, staticResults: StaticResult[], plugin: P
|
|
|
174
190
|
|
|
175
191
|
const summary = summarize(entries)
|
|
176
192
|
const ok = summary.error === 0 && summary.warning === 0
|
|
177
|
-
return { cwd: ctx.cwd, hasAgentFolder: ctx.hasAgentFolder, entries, summary, ok }
|
|
193
|
+
return { cwd: ctx.cwd, stage, hasAgentFolder: ctx.hasAgentFolder, entries, summary, ok }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function containerStageNote(): ReportEntry {
|
|
197
|
+
return {
|
|
198
|
+
name: 'doctor.container-stage',
|
|
199
|
+
category: 'runtime',
|
|
200
|
+
description: 'doctor is running inside the agent container',
|
|
201
|
+
source: 'static',
|
|
202
|
+
status: 'info',
|
|
203
|
+
message: 'running inside the agent container; host-only checks were omitted',
|
|
204
|
+
details: [
|
|
205
|
+
'Docker, hostd, Bun, config mounts, AppArmor, file ownership, managed templates, and channel credentials are checked only on the host.',
|
|
206
|
+
'Run `typeclaw doctor` in the agent folder on the host for the full report.',
|
|
207
|
+
],
|
|
208
|
+
}
|
|
178
209
|
}
|
|
179
210
|
|
|
180
|
-
function reachabilityNote(reach: PluginBridgeChecksResult): ReportEntry {
|
|
211
|
+
function reachabilityNote(reach: PluginBridgeChecksResult, stage: DoctorStage): ReportEntry {
|
|
181
212
|
const message =
|
|
182
213
|
reach.kind === 'unreachable'
|
|
183
214
|
? `plugin checks deferred: container not reachable (${reach.reason})`
|
|
@@ -191,7 +222,12 @@ function reachabilityNote(reach: PluginBridgeChecksResult): ReportEntry {
|
|
|
191
222
|
source: 'static',
|
|
192
223
|
status: 'info',
|
|
193
224
|
message,
|
|
194
|
-
details:
|
|
225
|
+
details:
|
|
226
|
+
stage === 'container'
|
|
227
|
+
? [
|
|
228
|
+
`Sandboxed bash does not receive the agent websocket token. Run \`typeclaw doctor\` on the host, or \`docker exec <container> bun ${TYPECLAW_CLI_ENTRY} doctor\`, to include plugin checks.`,
|
|
229
|
+
]
|
|
230
|
+
: ['Run `typeclaw start` then re-run `typeclaw doctor` to include plugin checks.'],
|
|
195
231
|
}
|
|
196
232
|
}
|
|
197
233
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
import { incidentsPath, readIncidentLedger } from '@/operations'
|
|
2
4
|
|
|
3
5
|
import type { DoctorCheck } from './types'
|
|
4
6
|
|
|
@@ -10,6 +12,19 @@ export function buildOperationalIncidentChecks(): DoctorCheck[] {
|
|
|
10
12
|
description: 'deterministic operational incidents are resolved',
|
|
11
13
|
applies: (ctx) => ctx.hasAgentFolder,
|
|
12
14
|
async run(ctx) {
|
|
15
|
+
// Sandboxed bash sees the runtime-private ledger as a 0-byte mask
|
|
16
|
+
// (src/sandbox/runtime-private.ts); the ledger itself is always written
|
|
17
|
+
// as JSON. readIncidentLedger would read that as "no incidents".
|
|
18
|
+
const raw = await readFile(incidentsPath(ctx.cwd), 'utf8').catch(() => null)
|
|
19
|
+
if (raw !== null && raw.trim() === '') {
|
|
20
|
+
return {
|
|
21
|
+
status: 'info',
|
|
22
|
+
message: 'operational incident check deferred: the incident ledger is not readable here',
|
|
23
|
+
details: [
|
|
24
|
+
'Sandboxed bash masks .typeclaw/incidents.json. Run doctor on the host or via `docker exec` to check incidents.',
|
|
25
|
+
],
|
|
26
|
+
}
|
|
27
|
+
}
|
|
13
28
|
const ledger = await readIncidentLedger(ctx.cwd)
|
|
14
29
|
const unresolved = ledger.incidents.filter((incident) => incident.status === 'unresolved')
|
|
15
30
|
if (unresolved.length === 0) return { status: 'ok', message: 'no unresolved operational incidents' }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveHostPort, resolveTuiToken, type DockerExec } from '@/container'
|
|
1
|
+
import { CONTAINER_PORT, resolveHostPort, resolveTuiToken, type DockerExec } from '@/container'
|
|
2
2
|
import type { ClientMessage, DoctorCheckPayload, DoctorFixPayload, ServerMessage } from '@/shared'
|
|
3
3
|
|
|
4
4
|
import { boundedExec } from './bounded-exec'
|
|
@@ -10,6 +10,8 @@ export type PluginBridgeOptions = {
|
|
|
10
10
|
// Injectable so a regression test can prove the late discovery path is
|
|
11
11
|
// bounded too, not just the static checks.
|
|
12
12
|
exec?: DockerExec
|
|
13
|
+
// Inside the container there is no `docker`; dial the agent's own loopback.
|
|
14
|
+
inContainer?: boolean
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export type PluginBridgeFetchChecks = (opts: PluginBridgeOptions) => Promise<PluginBridgeChecksResult>
|
|
@@ -82,6 +84,9 @@ type DialResult = { kind: 'ok'; ws: WebSocket; timeoutMs: number } | { kind: 'un
|
|
|
82
84
|
async function dial(opts: PluginBridgeOptions): Promise<DialResult> {
|
|
83
85
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
84
86
|
let url = opts.url
|
|
87
|
+
if (url === undefined && opts.inContainer === true) {
|
|
88
|
+
url = resolveInContainerBridgeUrl(process.env)
|
|
89
|
+
}
|
|
85
90
|
if (url === undefined) {
|
|
86
91
|
try {
|
|
87
92
|
// Plugin discovery runs AFTER the static checks, so it is the last place
|
|
@@ -148,6 +153,14 @@ async function dial(opts: PluginBridgeOptions): Promise<DialResult> {
|
|
|
148
153
|
return { kind: 'ok', ws, timeoutMs }
|
|
149
154
|
}
|
|
150
155
|
|
|
156
|
+
// Sandboxed model bash never receives TYPECLAW_TUI_TOKEN (src/sandbox/env-exposure.ts),
|
|
157
|
+
// so there a token-protected server rejects the dial and plugin checks are
|
|
158
|
+
// reported as deferred. `docker exec` keeps the container env and authenticates.
|
|
159
|
+
export function resolveInContainerBridgeUrl(env: NodeJS.ProcessEnv): string {
|
|
160
|
+
const token = env.TYPECLAW_TUI_TOKEN
|
|
161
|
+
return buildBridgeUrl(CONTAINER_PORT, token !== undefined && token !== '' ? token : null)
|
|
162
|
+
}
|
|
163
|
+
|
|
151
164
|
function buildBridgeUrl(port: number, token: string | null): string {
|
|
152
165
|
const url = new URL(`ws://127.0.0.1:${port}`)
|
|
153
166
|
if (token !== null) url.searchParams.set('token', token)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DoctorStage } from './types'
|
|
2
|
+
|
|
3
|
+
const CONTAINER_AGENT_DIR = '/agent'
|
|
4
|
+
|
|
5
|
+
// `docker run` sets TYPECLAW_CONTAINER_NAME, so a `docker exec` doctor run
|
|
6
|
+
// sees it. Model bash does not: the bwrap sandbox clears the container
|
|
7
|
+
// env (src/sandbox/policy.ts DEFAULT_SANDBOX_ENV) and hides /.dockerenv. Its
|
|
8
|
+
// cwd still resolves to the agent folder at its container mount point, so the
|
|
9
|
+
// /agent agent folder is the marker that survives the sandbox.
|
|
10
|
+
export function detectDoctorStage(agentDir: string, env: NodeJS.ProcessEnv = process.env): DoctorStage {
|
|
11
|
+
if (env.TYPECLAW_CONTAINER_NAME !== undefined) return 'container'
|
|
12
|
+
if (agentDir === CONTAINER_AGENT_DIR) return 'container'
|
|
13
|
+
return 'host'
|
|
14
|
+
}
|
package/src/doctor/types.ts
CHANGED
|
@@ -34,10 +34,15 @@ export type CheckContext = {
|
|
|
34
34
|
hasAgentFolder: boolean
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export type DoctorStage = 'host' | 'container'
|
|
38
|
+
|
|
37
39
|
export type DoctorCheck = {
|
|
38
40
|
name: string
|
|
39
41
|
category: DoctorCategory
|
|
40
42
|
description: string
|
|
43
|
+
// Probes host-only state (Docker, hostd, host kernel, host paths, host-side
|
|
44
|
+
// secrets). Omitted when doctor runs inside the agent container.
|
|
45
|
+
hostOnly?: boolean
|
|
41
46
|
applies?: (ctx: CheckContext) => boolean
|
|
42
47
|
run: (ctx: CheckContext) => Promise<CheckResult>
|
|
43
48
|
}
|
|
@@ -64,6 +69,7 @@ export type ReportSummary = {
|
|
|
64
69
|
|
|
65
70
|
export type DoctorReport = {
|
|
66
71
|
cwd: string
|
|
72
|
+
stage: DoctorStage
|
|
67
73
|
hasAgentFolder: boolean
|
|
68
74
|
entries: ReportEntry[]
|
|
69
75
|
summary: ReportSummary
|
package/src/eval/cell.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
import { CellOutput, EVAL_LIMITS, EvalError, type HostFrame, type KernelFrame } from './protocol'
|
|
4
|
+
import { assertNever } from './wire'
|
|
5
|
+
|
|
6
|
+
export type EvalDispatch = (
|
|
7
|
+
request: {
|
|
8
|
+
readonly name: string
|
|
9
|
+
readonly args: Extract<KernelFrame, { type: 'tool-call' }>['args']
|
|
10
|
+
readonly callId: string
|
|
11
|
+
},
|
|
12
|
+
signal: AbortSignal,
|
|
13
|
+
) => Promise<unknown>
|
|
14
|
+
|
|
15
|
+
export class EvalCell {
|
|
16
|
+
readonly id = randomUUID()
|
|
17
|
+
readonly output = new CellOutput()
|
|
18
|
+
readonly completed = Promise.withResolvers<void>()
|
|
19
|
+
private readonly ids = new Set<string>()
|
|
20
|
+
private readonly pending = new Set<Promise<void>>()
|
|
21
|
+
private finished = false
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly dispatch: EvalDispatch,
|
|
25
|
+
private readonly signal: AbortSignal,
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
receive(frame: KernelFrame, send: (frame: HostFrame) => void): void {
|
|
29
|
+
switch (frame.type) {
|
|
30
|
+
case 'ready':
|
|
31
|
+
throw new EvalError('protocol', 'unexpected ready frame')
|
|
32
|
+
case 'output':
|
|
33
|
+
this.assertActive(frame.cellId)
|
|
34
|
+
this.output.append(frame.text)
|
|
35
|
+
return
|
|
36
|
+
case 'done':
|
|
37
|
+
this.assertActive(frame.cellId)
|
|
38
|
+
this.finished = true
|
|
39
|
+
void Promise.all(this.pending).then(() => {
|
|
40
|
+
if (frame.error === undefined) this.completed.resolve()
|
|
41
|
+
else this.completed.reject(new EvalError('cell', frame.error))
|
|
42
|
+
}, this.completed.reject)
|
|
43
|
+
return
|
|
44
|
+
case 'tool-call': {
|
|
45
|
+
this.assertActive(frame.cellId)
|
|
46
|
+
if (
|
|
47
|
+
this.ids.has(frame.id) ||
|
|
48
|
+
this.ids.size >= EVAL_LIMITS.calls ||
|
|
49
|
+
this.pending.size >= EVAL_LIMITS.concurrency
|
|
50
|
+
) {
|
|
51
|
+
throw new EvalError('protocol', 'eval tool-call id, count, or concurrency limit exceeded')
|
|
52
|
+
}
|
|
53
|
+
this.ids.add(frame.id)
|
|
54
|
+
const task = this.invoke(frame, send)
|
|
55
|
+
this.pending.add(task)
|
|
56
|
+
void task.then(() => this.pending.delete(task), this.completed.reject)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
assertNever(frame)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private assertActive(cellId: string): void {
|
|
65
|
+
if (this.finished || this.signal.aborted || cellId !== this.id) {
|
|
66
|
+
throw new EvalError('protocol', 'eval frame is outside its active cell')
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private async invoke(
|
|
71
|
+
frame: Extract<KernelFrame, { type: 'tool-call' }>,
|
|
72
|
+
send: (frame: HostFrame) => void,
|
|
73
|
+
): Promise<void> {
|
|
74
|
+
try {
|
|
75
|
+
const value = await this.dispatch(
|
|
76
|
+
{
|
|
77
|
+
name: frame.name,
|
|
78
|
+
args: frame.args,
|
|
79
|
+
callId: `eval:${this.id}:${frame.id}`,
|
|
80
|
+
},
|
|
81
|
+
this.signal,
|
|
82
|
+
)
|
|
83
|
+
if (!this.signal.aborted) send({ type: 'tool-result', id: frame.id, value })
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!this.signal.aborted)
|
|
86
|
+
send({
|
|
87
|
+
type: 'tool-error',
|
|
88
|
+
id: frame.id,
|
|
89
|
+
error: (error instanceof Error ? error.message : String(error)).slice(0, 4096),
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { WrapSystemToolOptions } from '@/agent/plugin-tools'
|
|
4
|
+
import type { SessionOrigin } from '@/agent/session-origin'
|
|
5
|
+
|
|
6
|
+
const origins = ['tui', 'channel', 'cron', 'subagent', 'system'] as const
|
|
7
|
+
|
|
8
|
+
export const evalConfigSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
enabled: z.boolean().default(false),
|
|
11
|
+
origins: z.array(z.enum(origins)).default([...origins]),
|
|
12
|
+
})
|
|
13
|
+
.strict()
|
|
14
|
+
.default({ enabled: false, origins: [...origins] })
|
|
15
|
+
|
|
16
|
+
export function evalEnabledForSession(options: {
|
|
17
|
+
readonly settings: z.infer<typeof evalConfigSchema>
|
|
18
|
+
readonly origin: SessionOrigin | undefined
|
|
19
|
+
readonly tools: readonly string[]
|
|
20
|
+
readonly bashPolicy?: WrapSystemToolOptions['bashPolicy']
|
|
21
|
+
}): boolean {
|
|
22
|
+
// Raw JavaScript is arbitrary code, just like unrestricted bash. The command
|
|
23
|
+
// fence is NOT a filesystem policy and cannot be enforced on JavaScript.
|
|
24
|
+
// Use the wrapper's actual policy source, never a list of subagent names.
|
|
25
|
+
return (
|
|
26
|
+
options.settings.enabled &&
|
|
27
|
+
options.origin !== undefined &&
|
|
28
|
+
options.settings.origins.includes(options.origin.kind) &&
|
|
29
|
+
options.tools.includes('bash') &&
|
|
30
|
+
options.bashPolicy === undefined
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { validateToolArguments } from '@earendil-works/pi-ai'
|
|
2
|
+
import type { ToolDefinition } from '@earendil-works/pi-coding-agent'
|
|
3
|
+
|
|
4
|
+
import type { EvalDispatch } from './cell'
|
|
5
|
+
import { EvalError } from './protocol'
|
|
6
|
+
|
|
7
|
+
// These operations need their own model-visible call: recursion would re-enter
|
|
8
|
+
// a busy kernel; orchestration/lifecycle tools can outlive or terminate its
|
|
9
|
+
// foreground lease; posting and role changes need an explicit separate action.
|
|
10
|
+
// MCP dispatch is excluded because its chosen target is not statically known.
|
|
11
|
+
// Ordinary active plugin tools retain their normal wrapped execution path.
|
|
12
|
+
const refused = new Set([
|
|
13
|
+
'eval',
|
|
14
|
+
'spawn_subagent',
|
|
15
|
+
'coding_agent',
|
|
16
|
+
'subagent_cancel',
|
|
17
|
+
'channel_send',
|
|
18
|
+
'channel_reply',
|
|
19
|
+
'channel_edit',
|
|
20
|
+
'channel_react',
|
|
21
|
+
'channel_handoff',
|
|
22
|
+
'channel_disengage',
|
|
23
|
+
'post_github_review',
|
|
24
|
+
'skip_response',
|
|
25
|
+
'restart',
|
|
26
|
+
'reload',
|
|
27
|
+
'grant_role',
|
|
28
|
+
'mcp_call',
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
export function createEvalDispatch(options: {
|
|
32
|
+
readonly tools: readonly ToolDefinition[]
|
|
33
|
+
readonly getActiveNames: () => readonly string[]
|
|
34
|
+
readonly context: Parameters<ToolDefinition['execute']>[4]
|
|
35
|
+
}): EvalDispatch {
|
|
36
|
+
const tools = new Map(options.tools.map((tool) => [tool.name, tool]))
|
|
37
|
+
return async (request, signal) => {
|
|
38
|
+
signal.throwIfAborted()
|
|
39
|
+
if (refused.has(request.name) || !options.getActiveNames().includes(request.name)) {
|
|
40
|
+
throw new EvalError('refused', `tool "${request.name}" is not active or is not batchable in eval`)
|
|
41
|
+
}
|
|
42
|
+
const tool = tools.get(request.name)
|
|
43
|
+
if (tool === undefined) throw new EvalError('refused', `tool "${request.name}" is unavailable`)
|
|
44
|
+
// Use Pi's direct-call validator, followed by the EXACT post-budget
|
|
45
|
+
// definition supplied to createAgentSession. Never rebuild raw builtins.
|
|
46
|
+
const args = validateToolArguments(tool, {
|
|
47
|
+
type: 'toolCall',
|
|
48
|
+
id: request.callId,
|
|
49
|
+
name: request.name,
|
|
50
|
+
arguments: request.args,
|
|
51
|
+
})
|
|
52
|
+
try {
|
|
53
|
+
return await tool.execute(request.callId, args, signal, undefined, options.context)
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (request.name === 'grep' && error instanceof Error && error.message.includes('regex parse error')) {
|
|
56
|
+
throw new Error(error.message + GREP_REGEX_HINT, { cause: error })
|
|
57
|
+
}
|
|
58
|
+
throw error
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Cells keep failing on patterns like '\(' even with the rules in the tool
|
|
64
|
+
// description: inside a JS string literal that is just '(', so rg sees an
|
|
65
|
+
// unclosed group. Name the cause where the failure surfaces.
|
|
66
|
+
const GREP_REGEX_HINT =
|
|
67
|
+
"\nHint: in a JS string '\\(' is just '(' - write '\\\\(' or String.raw`\\(`, or pass literal: true for plain text. Lookaround is unsupported."
|