typeclaw 0.48.11 → 0.48.13
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/package.json +7 -4
- package/src/agent/attention-escalation.ts +8 -5
- package/src/agent/auth-reloadable.ts +2 -3
- package/src/agent/auth.ts +59 -79
- package/src/agent/compaction.ts +2 -2
- package/src/agent/index.ts +42 -16
- package/src/agent/llm-replay-sanitizer.ts +1 -1
- package/src/agent/model-overrides.ts +1 -1
- package/src/agent/multimodal/look-at.ts +3 -3
- package/src/agent/multimodal/read-redirect.ts +1 -1
- package/src/agent/plugin-tools.ts +26 -31
- package/src/agent/reload-tool.ts +1 -1
- package/src/agent/subagents.ts +1 -1
- package/src/agent/tool-error-remediation.ts +1 -1
- package/src/agent/tool-result-budget.ts +2 -2
- package/src/agent/tools/channel-disengage.ts +2 -2
- package/src/agent/tools/channel-edit.ts +2 -2
- package/src/agent/tools/channel-fetch-attachment.ts +2 -2
- package/src/agent/tools/channel-history.ts +2 -2
- package/src/agent/tools/channel-react.ts +2 -2
- package/src/agent/tools/channel-read.ts +2 -2
- package/src/agent/tools/channel-reply.ts +2 -2
- package/src/agent/tools/channel-send.ts +2 -2
- package/src/agent/tools/grant-role.ts +2 -2
- package/src/agent/tools/post-github-review.ts +2 -2
- package/src/agent/tools/restart.ts +2 -2
- package/src/agent/tools/skip-response.ts +2 -2
- package/src/agent/tools/spawn-subagent.ts +2 -2
- package/src/agent/tools/stream-snapshot.ts +2 -2
- package/src/agent/tools/subagent-cancel.ts +2 -2
- package/src/agent/tools/subagent-output.ts +2 -2
- package/src/agent/tools/todo/index.ts +2 -2
- package/src/agent/tools/webfetch/tool.ts +2 -2
- package/src/agent/tools/websearch.ts +2 -2
- package/src/bundled-plugins/github-cli-auth/gh-command.ts +7 -1
- package/src/bundled-plugins/github-cli-auth/index.ts +1 -1
- package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -1
- package/src/bundled-plugins/memory/dreaming.ts +21 -6
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +86 -16
- package/src/channels/adapters/kakaotalk.ts +7 -8
- package/src/channels/adapters/teams-classify.ts +21 -0
- package/src/channels/adapters/teams-edit.ts +2 -1
- package/src/channels/adapters/teams-format.ts +16 -0
- package/src/channels/adapters/teams.ts +12 -5
- package/src/channels/github-review-verdict-coordinator.ts +26 -3
- package/src/channels/router.ts +50 -25
- package/src/cli/compose.ts +3 -3
- package/src/cli/docker-preflight.ts +8 -4
- package/src/cli/model.ts +7 -5
- package/src/cli/oauth-callbacks.ts +38 -23
- package/src/cli/restart.ts +89 -23
- package/src/cli/start.ts +68 -16
- package/src/cli/status.ts +38 -6
- package/src/cli/stop.ts +5 -2
- package/src/compose/stop.ts +5 -4
- package/src/config/config.ts +62 -25
- package/src/config/providers.ts +272 -47
- package/src/container/build-cache.ts +807 -0
- package/src/container/compose-project.ts +4 -0
- package/src/container/docker-app.ts +74 -0
- package/src/container/log-archive.ts +33 -5
- package/src/container/memory-limit.ts +80 -0
- package/src/container/memory-oversubscription.ts +125 -0
- package/src/container/restart.ts +6 -1
- package/src/container/shared.ts +43 -16
- package/src/container/start.ts +280 -53
- package/src/container/stop.ts +19 -13
- package/src/container/verify-running.ts +12 -0
- package/src/cron/scheduler.ts +12 -4
- package/src/doctor/bounded-exec.ts +14 -0
- package/src/doctor/checks.ts +40 -15
- package/src/doctor/index.ts +14 -2
- package/src/doctor/plugin-bridge.ts +15 -3
- package/src/hostd/paths.ts +4 -0
- package/src/init/index.ts +4 -4
- package/src/init/oauth-login.ts +57 -17
- package/src/inspect/transcript-view.ts +6 -3
- package/src/run/channel-session-factory.ts +5 -4
- package/src/run/index.ts +27 -11
- package/src/run/resource-sample.ts +171 -0
- package/src/sandbox/index.ts +8 -1
- package/src/sandbox/session-tmp.ts +26 -1
- package/src/secrets/refresh-provider-oauth.ts +30 -76
- package/src/secrets/schema.ts +3 -4
- package/src/secrets/storage.ts +133 -234
- package/src/server/index.ts +1 -1
- package/src/sessions/index.ts +1 -1
- package/src/skills/typeclaw-config/SKILL.md +4 -4
- package/src/skills/typeclaw-plugins/SKILL.md +5 -5
- package/src/tui/index.ts +5 -3
- package/src/tui/theme.ts +1 -1
- package/typeclaw.schema.json +32 -1
- package/src/agent/adaptive-thinking-compat.ts +0 -79
- package/src/secrets/oauth-xai.ts +0 -348
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defaultDockerExec, type DockerExec } from '@/container'
|
|
2
|
+
|
|
3
|
+
// Every Docker call reachable from `doctor` must carry a deadline.
|
|
4
|
+
//
|
|
5
|
+
// The bounded availability probe only proves the daemon answered ONCE; it can
|
|
6
|
+
// wedge immediately afterward, so gating on it is necessary but not sufficient.
|
|
7
|
+
// This is the whole point of the command: an operator runs `doctor` precisely
|
|
8
|
+
// when the host is sick, and a diagnostic that blocks forever on the thing it
|
|
9
|
+
// is diagnosing is worse than useless.
|
|
10
|
+
export const DOCTOR_DOCKER_TIMEOUT_MS = 5_000
|
|
11
|
+
|
|
12
|
+
export function boundedExec(exec: DockerExec = defaultDockerExec, timeoutMs = DOCTOR_DOCKER_TIMEOUT_MS): DockerExec {
|
|
13
|
+
return (args, options) => exec(args, { ...options, signal: options?.signal ?? AbortSignal.timeout(timeoutMs) })
|
|
14
|
+
}
|
package/src/doctor/checks.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
refreshDockerfile,
|
|
14
14
|
refreshGitignore,
|
|
15
15
|
resolveHostPort,
|
|
16
|
+
type DockerAvailability,
|
|
16
17
|
type DockerExec,
|
|
17
18
|
} from '@/container'
|
|
18
19
|
import { homeRoot, isDaemonReachable, send } from '@/hostd'
|
|
@@ -23,6 +24,7 @@ import { buildGitignore, GITIGNORE_FILE } from '@/init/gitignore'
|
|
|
23
24
|
import { detectWsl, isWindows, isWindowsDriveMount, type WslInfo } from '@/shared'
|
|
24
25
|
|
|
25
26
|
import { apparmorSandbox } from './apparmor'
|
|
27
|
+
import { boundedExec } from './bounded-exec'
|
|
26
28
|
import { buildChannelChecks } from './channel-checks'
|
|
27
29
|
import { agentFileOwnership, type FileOwnershipDeps } from './file-ownership'
|
|
28
30
|
import { buildOperationalIncidentChecks } from './operational-incidents'
|
|
@@ -32,7 +34,7 @@ export function buildStaticChecks(opts: { dockerExec?: DockerExec } & FileOwners
|
|
|
32
34
|
const dockerExec = opts.dockerExec ?? defaultDockerExec
|
|
33
35
|
|
|
34
36
|
return [
|
|
35
|
-
dockerDaemon(dockerExec),
|
|
37
|
+
dockerDaemon(boundedExec(dockerExec)),
|
|
36
38
|
bunRuntime(),
|
|
37
39
|
agentFolderInitialized(),
|
|
38
40
|
agentFolderDockerfileTemplate(),
|
|
@@ -48,8 +50,8 @@ export function buildStaticChecks(opts: { dockerExec?: DockerExec } & FileOwners
|
|
|
48
50
|
hostdReachable(),
|
|
49
51
|
hostdRegistration(),
|
|
50
52
|
windowsBindMount(),
|
|
51
|
-
containerState(dockerExec),
|
|
52
|
-
containerHostPort(),
|
|
53
|
+
containerState(boundedExec(dockerExec)),
|
|
54
|
+
containerHostPort(dockerExec),
|
|
53
55
|
...buildOperationalIncidentChecks(),
|
|
54
56
|
...buildChannelChecks(),
|
|
55
57
|
]
|
|
@@ -65,20 +67,38 @@ function dockerDaemon(exec: DockerExec): DoctorCheck {
|
|
|
65
67
|
if (result.ok) return { status: 'ok', message: 'docker info responded' }
|
|
66
68
|
return {
|
|
67
69
|
status: 'error',
|
|
68
|
-
message: result.reason
|
|
70
|
+
message: dockerDaemonMessage(result.reason),
|
|
69
71
|
details: [result.detail],
|
|
70
|
-
fix:
|
|
71
|
-
result.reason === 'binary-missing'
|
|
72
|
-
? { description: 'Install Docker (Docker Desktop, OrbStack, or docker-ce).' }
|
|
73
|
-
: {
|
|
74
|
-
description:
|
|
75
|
-
'Start the Docker runtime (Docker Desktop, OrbStack, or `systemctl start docker`). If it is already running, check `docker context ls`, `DOCKER_CONTEXT`, and `DOCKER_HOST`.',
|
|
76
|
-
},
|
|
72
|
+
fix: { description: dockerDaemonFix(result.reason) },
|
|
77
73
|
}
|
|
78
74
|
},
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
77
|
|
|
78
|
+
type DockerUnavailableReason = Extract<DockerAvailability, { ok: false }>['reason']
|
|
79
|
+
|
|
80
|
+
function dockerDaemonMessage(reason: DockerUnavailableReason): string {
|
|
81
|
+
switch (reason) {
|
|
82
|
+
case 'binary-missing':
|
|
83
|
+
return 'docker binary missing on $PATH'
|
|
84
|
+
case 'unresponsive':
|
|
85
|
+
return 'docker daemon accepted the request but never responded'
|
|
86
|
+
case 'daemon-down':
|
|
87
|
+
return 'docker daemon not reachable'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function dockerDaemonFix(reason: DockerUnavailableReason): string {
|
|
92
|
+
switch (reason) {
|
|
93
|
+
case 'binary-missing':
|
|
94
|
+
return 'Install Docker (Docker Desktop, OrbStack, or docker-ce), or if it is already installed, add its bin directory to PATH — a non-interactive or SSH shell often misses it.'
|
|
95
|
+
case 'unresponsive':
|
|
96
|
+
return 'Restart the Docker runtime (`orb stop` then reopen OrbStack, restart Docker Desktop, or `systemctl restart docker`). A daemon that answers nothing is usually host or VM memory exhaustion, so check memory pressure or it will recur.'
|
|
97
|
+
case 'daemon-down':
|
|
98
|
+
return 'Start the Docker runtime (Docker Desktop, OrbStack, or `systemctl start docker`). If it is already running, check `docker context ls`, `DOCKER_CONTEXT`, and `DOCKER_HOST`.'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
82
102
|
function bunRuntime(): DoctorCheck {
|
|
83
103
|
return {
|
|
84
104
|
name: 'runtime.bun-available',
|
|
@@ -451,7 +471,7 @@ function containerState(exec: DockerExec): DoctorCheck {
|
|
|
451
471
|
return { status: 'skipped', message: 'docker unavailable (covered by docker.daemon-reachable)' }
|
|
452
472
|
}
|
|
453
473
|
const name = containerNameFromCwd(ctx.cwd)
|
|
454
|
-
const state = await inspectContainer(name)
|
|
474
|
+
const state = await inspectContainer(name, { exec })
|
|
455
475
|
if (!state.exists) {
|
|
456
476
|
return {
|
|
457
477
|
status: 'info',
|
|
@@ -469,20 +489,25 @@ function containerState(exec: DockerExec): DoctorCheck {
|
|
|
469
489
|
}
|
|
470
490
|
}
|
|
471
491
|
|
|
472
|
-
function containerHostPort(): DoctorCheck {
|
|
492
|
+
function containerHostPort(exec: DockerExec): DoctorCheck {
|
|
473
493
|
return {
|
|
474
494
|
name: 'container.host-port-resolves',
|
|
475
495
|
category: 'container',
|
|
476
496
|
description: 'running container exposes its host port',
|
|
477
497
|
applies: (ctx) => ctx.hasAgentFolder,
|
|
478
498
|
async run(ctx) {
|
|
499
|
+
const bounded = boundedExec(exec)
|
|
500
|
+
const available = await checkDockerAvailable(bounded)
|
|
501
|
+
if (!available.ok) {
|
|
502
|
+
return { status: 'skipped', message: 'docker unavailable (covered by docker.daemon-reachable)' }
|
|
503
|
+
}
|
|
479
504
|
const name = containerNameFromCwd(ctx.cwd)
|
|
480
|
-
const state = await inspectContainer(name)
|
|
505
|
+
const state = await inspectContainer(name, { exec: bounded })
|
|
481
506
|
if (!state.exists || !state.running) {
|
|
482
507
|
return { status: 'skipped', message: 'container not running' }
|
|
483
508
|
}
|
|
484
509
|
try {
|
|
485
|
-
const port = await resolveHostPort({ cwd: ctx.cwd })
|
|
510
|
+
const port = await resolveHostPort({ cwd: ctx.cwd, exec: bounded })
|
|
486
511
|
return { status: 'ok', message: `host port ${port} -> container` }
|
|
487
512
|
} catch (err) {
|
|
488
513
|
return {
|
package/src/doctor/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DockerExec } from '@/container'
|
|
1
2
|
import { findAgentDir } from '@/init'
|
|
2
3
|
import type { DoctorCheckPayload } from '@/shared'
|
|
3
4
|
|
|
@@ -38,6 +39,10 @@ export type RunDoctorOptions = {
|
|
|
38
39
|
cwd?: string
|
|
39
40
|
only?: string[]
|
|
40
41
|
fix?: boolean
|
|
42
|
+
// Docker executor used by BOTH the static checks and plugin discovery, so a
|
|
43
|
+
// test can drive the whole command against one wedged daemon and prove the
|
|
44
|
+
// real sequencing terminates — not just each half in isolation.
|
|
45
|
+
dockerExec?: DockerExec
|
|
41
46
|
staticChecks?: DoctorCheck[]
|
|
42
47
|
fetchPluginChecks?: PluginBridgeFetchChecks
|
|
43
48
|
fetchPluginFix?: PluginBridgeFetchFix
|
|
@@ -49,10 +54,17 @@ export async function runDoctor(opts: RunDoctorOptions = {}): Promise<DoctorRunR
|
|
|
49
54
|
const hasAgentFolder = findAgentDir(cwd) === cwd
|
|
50
55
|
const ctx: CheckContext = { cwd, hasAgentFolder }
|
|
51
56
|
|
|
52
|
-
const staticChecks = (
|
|
57
|
+
const staticChecks = (
|
|
58
|
+
opts.staticChecks ?? buildStaticChecks(opts.dockerExec === undefined ? {} : { dockerExec: opts.dockerExec })
|
|
59
|
+
).filter((c) => isAllowed(c, opts.only, c.category))
|
|
53
60
|
const staticResults = await runStaticChecks(staticChecks, ctx)
|
|
54
61
|
|
|
55
|
-
const fetchPluginChecks =
|
|
62
|
+
const fetchPluginChecks =
|
|
63
|
+
opts.fetchPluginChecks ??
|
|
64
|
+
((bridgeOpts) =>
|
|
65
|
+
defaultFetchPluginDoctorChecks(
|
|
66
|
+
opts.dockerExec === undefined ? bridgeOpts : { ...bridgeOpts, exec: opts.dockerExec },
|
|
67
|
+
))
|
|
56
68
|
const pluginResults = await collectPluginChecks(fetchPluginChecks, ctx, opts.only)
|
|
57
69
|
|
|
58
70
|
const initial = buildReport(ctx, staticResults, pluginResults)
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { resolveHostPort, resolveTuiToken } from '@/container'
|
|
1
|
+
import { resolveHostPort, resolveTuiToken, type DockerExec } from '@/container'
|
|
2
2
|
import type { ClientMessage, DoctorCheckPayload, DoctorFixPayload, ServerMessage } from '@/shared'
|
|
3
3
|
|
|
4
|
+
import { boundedExec } from './bounded-exec'
|
|
5
|
+
|
|
4
6
|
export type PluginBridgeOptions = {
|
|
5
7
|
cwd: string
|
|
6
8
|
url?: string
|
|
7
9
|
timeoutMs?: number
|
|
10
|
+
// Injectable so a regression test can prove the late discovery path is
|
|
11
|
+
// bounded too, not just the static checks.
|
|
12
|
+
exec?: DockerExec
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
export type PluginBridgeFetchChecks = (opts: PluginBridgeOptions) => Promise<PluginBridgeChecksResult>
|
|
@@ -79,8 +84,15 @@ async function dial(opts: PluginBridgeOptions): Promise<DialResult> {
|
|
|
79
84
|
let url = opts.url
|
|
80
85
|
if (url === undefined) {
|
|
81
86
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
// Plugin discovery runs AFTER the static checks, so it is the last place
|
|
88
|
+
// a wedged daemon can still hang the command: `docker port` and
|
|
89
|
+
// `docker inspect` here would otherwise block with no deadline of their
|
|
90
|
+
// own, long after the earlier `docker info` probes succeeded.
|
|
91
|
+
// Wrap unconditionally rather than only defaulting: an injected exec is
|
|
92
|
+
// no safer than the default one, and the deadline is the invariant here.
|
|
93
|
+
const exec = boundedExec(opts.exec)
|
|
94
|
+
const port = await resolveHostPort({ cwd: opts.cwd, exec })
|
|
95
|
+
const token = await resolveTuiToken({ cwd: opts.cwd, exec })
|
|
84
96
|
url = buildBridgeUrl(port, token)
|
|
85
97
|
} catch (err) {
|
|
86
98
|
return { kind: 'unreachable', reason: err instanceof Error ? err.message : String(err) }
|
package/src/hostd/paths.ts
CHANGED
|
@@ -87,6 +87,10 @@ export function modelsDir(): string {
|
|
|
87
87
|
return join(homeRoot(), 'models')
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
export function buildCacheDir(): string {
|
|
91
|
+
return join(homeRoot(), 'build-cache')
|
|
92
|
+
}
|
|
93
|
+
|
|
90
94
|
export function versionCachePath(): string {
|
|
91
95
|
return join(homeRoot(), 'version-cache.json')
|
|
92
96
|
}
|
package/src/init/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
} from '@/container'
|
|
30
30
|
import { hooklessGitArgs } from '@/git/hookless'
|
|
31
31
|
import { commitSystemFile } from '@/git/system-commit'
|
|
32
|
-
import {
|
|
32
|
+
import { type Channels, type Secret, SecretsBackend } from '@/secrets'
|
|
33
33
|
import { hostLocaleIsCjk } from '@/shared/host-locale'
|
|
34
34
|
import { isWindows } from '@/shared/platform'
|
|
35
35
|
import { createTui } from '@/tui'
|
|
@@ -949,10 +949,10 @@ export async function writeSecrets(
|
|
|
949
949
|
visionProviderId !== null &&
|
|
950
950
|
KNOWN_PROVIDERS[visionProviderId].apiKeyEnv !== null
|
|
951
951
|
if (wantsDefaultKey || wantsVisionKey) {
|
|
952
|
-
const
|
|
953
|
-
if (wantsDefaultKey)
|
|
952
|
+
const backend = new SecretsBackend(join(root, 'secrets.json'))
|
|
953
|
+
if (wantsDefaultKey) backend.writeProviderCredentialSync(providerId, { type: 'api_key', key: { value: apiKey! } })
|
|
954
954
|
if (wantsVisionKey) {
|
|
955
|
-
|
|
955
|
+
backend.writeProviderCredentialSync(visionProviderId, { type: 'api_key', key: { value: visionApiKey! } })
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
958
|
|
package/src/init/oauth-login.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
+
import type { AuthInteraction, AuthPrompt } from '@earendil-works/pi-ai'
|
|
4
|
+
import { ModelRuntime } from '@earendil-works/pi-coding-agent'
|
|
5
|
+
|
|
3
6
|
import {
|
|
4
7
|
KNOWN_PROVIDERS,
|
|
5
8
|
providerForModelRef,
|
|
@@ -14,13 +17,14 @@ export type OAuthLoginResult = { ok: true } | { ok: false; reason: string }
|
|
|
14
17
|
export type OAuthLoginRunner = (options: { cwd: string; model: ModelRef | string }) => Promise<OAuthLoginResult>
|
|
15
18
|
|
|
16
19
|
// Wrap pi-ai's OAuth callbacks so the CLI doesn't have to know about the
|
|
17
|
-
// upstream callback shape. The CLI sees
|
|
20
|
+
// upstream callback shape. The CLI sees five lifecycle events:
|
|
18
21
|
// (1) onAuth(url) — print the URL the user must visit
|
|
19
22
|
// (2) onProgress(message) — show waiting/finalizing status
|
|
20
|
-
// (3)
|
|
23
|
+
// (3) onSelect(message, options) — choose a provider-defined option by ID
|
|
24
|
+
// (4) onPrompt(prompt) — ask the user for a manual code if the browser flow
|
|
21
25
|
// can't reach the local callback server. Fires only after the local
|
|
22
26
|
// server gave up (bind error -> waitForCode resolves null).
|
|
23
|
-
// (
|
|
27
|
+
// (5) onManualCodeInput() — concurrent paste input that RACES the local
|
|
24
28
|
// callback server. Required for cross-device flows: pi-ai's openai-codex
|
|
25
29
|
// OAuth hardcodes redirect_uri=http://localhost:1455/auth/callback, which
|
|
26
30
|
// resolves to the *browser's* machine. When the user runs `typeclaw init`
|
|
@@ -32,11 +36,19 @@ export type OAuthLoginRunner = (options: { cwd: string; model: ModelRef | string
|
|
|
32
36
|
// code first wins. parseAuthorizationInput on the upstream side accepts
|
|
33
37
|
// the full redirect URL, the bare `code=...&state=...` query string, or
|
|
34
38
|
// just the code value.
|
|
39
|
+
export type OAuthSelectOption = Extract<AuthPrompt, { type: 'select' }>['options'][number]
|
|
40
|
+
|
|
35
41
|
export type OAuthCallbacks = {
|
|
36
42
|
onAuth: (url: string, instructions?: string) => void
|
|
37
43
|
onProgress?: (message: string) => void
|
|
38
|
-
onPrompt: (message: string, placeholder?: string) => Promise<string | null>
|
|
39
|
-
|
|
44
|
+
onPrompt: (message: string, placeholder?: string, signal?: AbortSignal) => Promise<string | null>
|
|
45
|
+
onSecret: (message: string, placeholder?: string, signal?: AbortSignal) => Promise<string | null>
|
|
46
|
+
onSelect: (
|
|
47
|
+
message: string,
|
|
48
|
+
options: readonly OAuthSelectOption[],
|
|
49
|
+
signal?: AbortSignal,
|
|
50
|
+
) => Promise<OAuthSelectOption['id'] | null>
|
|
51
|
+
onManualCodeInput?: (signal?: AbortSignal) => Promise<string>
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
// Default runner: real OAuth flow against pi-ai. Tests inject a stub to skip
|
|
@@ -52,19 +64,12 @@ export function makeOAuthLoginRunner(callbacks: OAuthCallbacks): OAuthLoginRunne
|
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
onPrompt: async (prompt) => {
|
|
60
|
-
const value = await callbacks.onPrompt(prompt.message, prompt.placeholder)
|
|
61
|
-
if (value === null) {
|
|
62
|
-
throw new Error('Login cancelled by user')
|
|
63
|
-
}
|
|
64
|
-
return value
|
|
65
|
-
},
|
|
66
|
-
onManualCodeInput: callbacks.onManualCodeInput,
|
|
67
|
+
const modelRuntime = await ModelRuntime.create({
|
|
68
|
+
credentials: createSecretsStoreForAgent(join(cwd, 'secrets.json')),
|
|
69
|
+
modelsPath: null,
|
|
70
|
+
refreshOnCreate: false,
|
|
67
71
|
})
|
|
72
|
+
await modelRuntime.login(provider.oauthProviderId, 'oauth', createOAuthInteraction(callbacks))
|
|
68
73
|
return { ok: true }
|
|
69
74
|
} catch (error) {
|
|
70
75
|
return { ok: false, reason: error instanceof Error ? error.message : String(error) }
|
|
@@ -72,6 +77,41 @@ export function makeOAuthLoginRunner(callbacks: OAuthCallbacks): OAuthLoginRunne
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
|
|
80
|
+
// Isolate the pi 0.87 AuthInteraction adaptation so manual-code prompt
|
|
81
|
+
// cancellation and callback forwarding remain behavior-testable without a
|
|
82
|
+
// live provider login.
|
|
83
|
+
export function createOAuthInteraction(callbacks: OAuthCallbacks): AuthInteraction {
|
|
84
|
+
return {
|
|
85
|
+
notify: (event) => {
|
|
86
|
+
if (event.type === 'auth_url') callbacks.onAuth(event.url, event.instructions)
|
|
87
|
+
else if (event.type === 'progress') callbacks.onProgress?.(event.message)
|
|
88
|
+
else if (event.type === 'device_code') callbacks.onAuth(event.verificationUri, `Enter code ${event.userCode}`)
|
|
89
|
+
},
|
|
90
|
+
prompt: async (prompt) => {
|
|
91
|
+
if (prompt.type === 'select') {
|
|
92
|
+
const value = await callbacks.onSelect(prompt.message, prompt.options, prompt.signal)
|
|
93
|
+
// pi-ai 0.87 requires select prompts to resolve with an option ID
|
|
94
|
+
// (dist/auth/types.d.ts:153-155); reject stale/corrupt UI values as cancellation.
|
|
95
|
+
if (value === null || !prompt.options.some((option) => option.id === value)) {
|
|
96
|
+
throw new Error('Login cancelled by user')
|
|
97
|
+
}
|
|
98
|
+
return value
|
|
99
|
+
}
|
|
100
|
+
if (prompt.type === 'manual_code' && callbacks.onManualCodeInput) {
|
|
101
|
+
return await callbacks.onManualCodeInput(prompt.signal)
|
|
102
|
+
}
|
|
103
|
+
const callback = prompt.type === 'secret' ? callbacks.onSecret : callbacks.onPrompt
|
|
104
|
+
if (prompt.type === 'text' || prompt.type === 'secret' || prompt.type === 'manual_code') {
|
|
105
|
+
const value = await callback(prompt.message, prompt.placeholder, prompt.signal)
|
|
106
|
+
if (value === null) throw new Error('Login cancelled by user')
|
|
107
|
+
return value
|
|
108
|
+
}
|
|
109
|
+
const unknownPrompt: never = prompt
|
|
110
|
+
throw new Error(`Unsupported OAuth prompt type: ${unknownPrompt}`)
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
// Test seam: lets unit tests assert "OAuth login was invoked with these
|
|
76
116
|
// params" without spinning up a real secrets store / browser callback server.
|
|
77
117
|
export type FakeOAuthLoginRunnerOptions = {
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
type Component,
|
|
7
7
|
type Terminal,
|
|
8
8
|
Text,
|
|
9
|
-
|
|
10
|
-
} from '@
|
|
9
|
+
TuiMainScreen,
|
|
10
|
+
} from '@earendil-works/pi-tui'
|
|
11
11
|
|
|
12
12
|
import { formatToolEnd, formatToolStart, formatUserPromptHistory } from '@/tui/format'
|
|
13
13
|
import { armTerminalGuard } from '@/tui/terminal-guard'
|
|
@@ -41,7 +41,10 @@ export const MAX_LIVE_HISTORY_ENTRIES = 250
|
|
|
41
41
|
export function createTranscriptView(opts: TranscriptViewOptions) {
|
|
42
42
|
async function run(): Promise<TranscriptViewOutcome> {
|
|
43
43
|
const terminal = (opts.createTerminal ?? (() => new ProcessTerminal()))()
|
|
44
|
-
|
|
44
|
+
// pi-tui 0.87 exports TUI only as an interface; use its concrete
|
|
45
|
+
// main-screen renderer to preserve this viewer's scrollback behavior
|
|
46
|
+
// (dist/tui.d.ts:213-244, tui-main-screen.d.ts:11-12).
|
|
47
|
+
const tui = new TuiMainScreen(terminal)
|
|
45
48
|
|
|
46
49
|
const status = new Text(statusLine('replay'), 0, 0)
|
|
47
50
|
tui.addChild(new Text(header(opts.summary), 0, 0))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { SessionManager } from '@
|
|
3
|
+
import { SessionManager } from '@earendil-works/pi-coding-agent'
|
|
4
4
|
|
|
5
5
|
import { createSession as defaultCreateSession } from '@/agent'
|
|
6
6
|
import type { LiveSessionRegistry } from '@/agent/live-sessions'
|
|
@@ -185,8 +185,9 @@ export function buildChannelSessionFactory(deps: BuildChannelSessionFactoryDeps)
|
|
|
185
185
|
// because pi-coding-agent prefixes filenames with an ISO timestamp at write
|
|
186
186
|
// time that is not derivable from sessionId alone. Failure to reopen
|
|
187
187
|
// (corruption, missing file, schema drift, or v2 mapping with no sessionFile)
|
|
188
|
-
// falls back to a fresh session
|
|
189
|
-
//
|
|
188
|
+
// falls back to a fresh session. pi 0.87 preserves a non-empty invalid file
|
|
189
|
+
// rather than silently rewriting it, so the warning below explicitly says its
|
|
190
|
+
// history is unavailable while retaining the file for operator recovery.
|
|
190
191
|
function tryReopenOrCreate(
|
|
191
192
|
cwd: string,
|
|
192
193
|
sessionDir: string,
|
|
@@ -234,7 +235,7 @@ function tryReopenOrCreate(
|
|
|
234
235
|
return sessionManager
|
|
235
236
|
} catch (err) {
|
|
236
237
|
if (!errorChainHasCode(err, 'ENOENT')) {
|
|
237
|
-
logger.warn('[channels] persisted session
|
|
238
|
+
logger.warn('[channels] persisted session history unavailable; creating new')
|
|
238
239
|
}
|
|
239
240
|
return SessionManager.create(cwd, sessionDir)
|
|
240
241
|
}
|
package/src/run/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { SessionManager } from '@
|
|
3
|
+
import { SessionManager } from '@earendil-works/pi-coding-agent'
|
|
4
4
|
|
|
5
5
|
import { createSession, createSessionWithDispose } from '@/agent'
|
|
6
6
|
import { createProviderAuthReloadable } from '@/agent/auth-reloadable'
|
|
@@ -92,6 +92,7 @@ import { installFatalGuard } from './fatal-guard'
|
|
|
92
92
|
import { installLlmFetchObserver } from './llm-fetch-observer'
|
|
93
93
|
import { createPluginRuntime, type PluginRuntime, type PluginSubagentEntry } from './plugin-runtime'
|
|
94
94
|
import { logResourceReport } from './resource-report'
|
|
95
|
+
import { startResourceSampler } from './resource-sample'
|
|
95
96
|
import { acquireSubagentCoalesceLease } from './subagent-coalescing'
|
|
96
97
|
|
|
97
98
|
type BunServer = ReturnType<Server['start']>
|
|
@@ -136,6 +137,9 @@ export type StartAgentOptions = {
|
|
|
136
137
|
// a refresh that holds the real secrets lock on a gate, proving the boot
|
|
137
138
|
// barrier settles this before any session-producing consumer starts.
|
|
138
139
|
refreshProviderOAuth?: (options: { agentDir: string; log: (message: string) => void }) => Promise<unknown>
|
|
140
|
+
// Injectable so a test can prove the sampler's disposer is wired into BOTH
|
|
141
|
+
// teardown paths without waiting out a real sampling interval.
|
|
142
|
+
startResourceSampler?: () => () => void
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
export type StartAgentResult = {
|
|
@@ -200,6 +204,7 @@ async function startAgentRuntime(
|
|
|
200
204
|
exportClaudeCredentialsFile = exportClaudeCredentialsFileForAgent,
|
|
201
205
|
exportGithubCliStore = exportGithubCliStoreForAgent,
|
|
202
206
|
refreshProviderOAuth = refreshProviderOAuthForAgent,
|
|
207
|
+
startResourceSampler: startResourceSamplerFor = startResourceSampler,
|
|
203
208
|
}: StartAgentOptions,
|
|
204
209
|
registerBootCleanup: (cleanup: () => void | Promise<void>) => void,
|
|
205
210
|
): Promise<StartAgentResult> {
|
|
@@ -322,6 +327,16 @@ async function startAgentRuntime(
|
|
|
322
327
|
// startup index build is itself an OOM path; if it kills the process, this
|
|
323
328
|
// line must already be in the log so the ceiling is still recorded.
|
|
324
329
|
logResourceReport(cwd)
|
|
330
|
+
// The boot line names the ceiling; this names the climb toward it. Without a
|
|
331
|
+
// series there is no way to tell a leak from a spike after the fact, which is
|
|
332
|
+
// exactly the question an OOM post-mortem opens with.
|
|
333
|
+
//
|
|
334
|
+
// Registered for boot-failure cleanup the instant it exists, and torn down by
|
|
335
|
+
// stop() on the normal path. `unref()` only keeps it from holding the process
|
|
336
|
+
// open; without an explicit clear, repeated start/stop cycles accumulate
|
|
337
|
+
// intervals that scan /proc and log after their runtime is gone.
|
|
338
|
+
const stopResourceSampler = startResourceSamplerFor()
|
|
339
|
+
registerBootCleanup(() => stopResourceSampler())
|
|
325
340
|
const vectorStartupPromise = runVectorStartup(cwd)
|
|
326
341
|
let pluginsLoaded: LoadPluginsResult
|
|
327
342
|
try {
|
|
@@ -395,15 +410,15 @@ async function startAgentRuntime(
|
|
|
395
410
|
//
|
|
396
411
|
// MUST be awaited, and MUST run before the credential-file exporters below
|
|
397
412
|
// and the first session-producing consumer (subagentConsumer.start /
|
|
398
|
-
// cronConsumer.start / channelManager.start / the websocket server). The
|
|
399
|
-
// refresh holds SecretsBackend's
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
//
|
|
405
|
-
// swallows and logs), so a probe failure can't block
|
|
406
|
-
// hangs on a wedged network hangs the first turn
|
|
413
|
+
// cronConsumer.start / channelManager.start / the websocket server). The
|
|
414
|
+
// refresh holds SecretsBackend's file lock across its network request
|
|
415
|
+
// (`CredentialStore.modify`), while the synchronous readers the exporters and
|
|
416
|
+
// channel hydration use give up after ~200ms and throw ELOCKED.
|
|
417
|
+
// Fire-and-forget here would let a slow refresh still own the lock when an
|
|
418
|
+
// exporter or consumer reads secrets — worse than the lazy path. Awaiting
|
|
419
|
+
// behind this barrier guarantees no synchronous reader races the refresh.
|
|
420
|
+
// Never throws (the wrapper swallows and logs), so a probe failure can't block
|
|
421
|
+
// boot; a refresh that hangs on a wedged network hangs the first turn anyway.
|
|
407
422
|
await refreshProviderOAuth({
|
|
408
423
|
agentDir: cwd,
|
|
409
424
|
log: (message) => console.warn(message),
|
|
@@ -883,7 +898,7 @@ async function startAgentRuntime(
|
|
|
883
898
|
// session teardown observes it. secrets.json provider credentials are not
|
|
884
899
|
// part of the typeclaw.json config diff, so a rotated key takes effect on
|
|
885
900
|
// `typeclaw reload` only via this dedicated scope. Live sessions captured
|
|
886
|
-
// their
|
|
901
|
+
// their ModelRuntime at creation, so teardown recreates them with fresh auth.
|
|
887
902
|
reloadRegistry.register(
|
|
888
903
|
createProviderAuthReloadable({
|
|
889
904
|
onProviderAuthChanged: () => channelManager.router.tearDownAllLive(),
|
|
@@ -1082,6 +1097,7 @@ async function startAgentRuntime(
|
|
|
1082
1097
|
// rejection cannot strand process-global listeners or plugin-owned handles
|
|
1083
1098
|
// into the next `startAgent`.
|
|
1084
1099
|
try {
|
|
1100
|
+
stopResourceSampler()
|
|
1085
1101
|
scheduler?.stop()
|
|
1086
1102
|
cronConsumer.stop()
|
|
1087
1103
|
subagentConsumer.stop()
|