typeclaw 0.46.1 → 0.46.2
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 +2 -2
- package/src/agent/tool-file-safety.ts +18 -9
- package/src/agent/tools/webfetch/strategies/jq.ts +1 -2
- package/src/agent/tools/webfetch/strategies/readability.ts +39 -16
- package/src/agent/tools/webfetch/strategies/selector.ts +4 -2
- package/src/agent/tools/webfetch/strategies/snapshot.ts +3 -2
- package/src/agent/tools/webfetch/tool.ts +3 -3
- package/src/bundled-plugins/backup/index.ts +21 -4
- package/src/bundled-plugins/backup/runner.ts +19 -5
- package/src/bundled-plugins/memory/vector/hybrid.ts +10 -2
- package/src/bundled-plugins/memory/vector/store.ts +21 -9
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +8 -3
- package/src/bundled-plugins/security/policies/private-surface-read.ts +6 -0
- package/src/cli/inspect.ts +16 -0
- package/src/container/shared.ts +19 -6
- package/src/init/checkpoint.ts +4 -4
- package/src/init/dockerfile.ts +87 -88
- package/src/init/gitignore.ts +5 -6
- package/src/init/run-bun-install.ts +16 -2
- package/src/init/validate-api-key.ts +1 -0
- package/src/inspect/item-list.ts +12 -6
- package/src/permissions/permissions.ts +93 -2
- package/src/role-claim/code.ts +9 -5
- package/src/run/index.ts +45 -36
- package/src/sandbox/canonical-secrets.ts +6 -0
- package/src/sandbox/index.ts +1 -0
- package/src/sandbox/symlinks.ts +1 -1
- package/src/secrets/export-claude-credentials-file.ts +13 -22
- package/src/secrets/export-codex-auth-file.ts +12 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.2",
|
|
4
4
|
"homepage": "https://github.com/typeclaw/typeclaw#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/typeclaw/typeclaw/issues"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@mariozechner/pi-tui": "^0.73.1",
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
52
52
|
"@mozilla/readability": "^0.6.0",
|
|
53
|
-
"agent-messenger": "^2.32.
|
|
53
|
+
"agent-messenger": "^2.32.3",
|
|
54
54
|
"cheerio": "^1.2.0",
|
|
55
55
|
"citty": "^0.2.2",
|
|
56
56
|
"cron-parser": "^5.5.0",
|
|
@@ -861,15 +861,24 @@ async function streamSnapshot(
|
|
|
861
861
|
callback(null, chunk)
|
|
862
862
|
},
|
|
863
863
|
})
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
864
|
+
// `autoClose: false` leaves the FileHandle to the caller, but the ReadStream
|
|
865
|
+
// opens its OWN fd that `source.close()` never releases and GC never reclaims
|
|
866
|
+
// — one leaked fd per snapshotted file, reaching EMFILE on a long-running
|
|
867
|
+
// agent. Destroy the stream explicitly to free that fd deterministically.
|
|
868
|
+
const readStream = source.createReadStream({ autoClose: false, start: 0 })
|
|
869
|
+
try {
|
|
870
|
+
await pipeline(
|
|
871
|
+
readStream,
|
|
872
|
+
limiter,
|
|
873
|
+
createWriteStream(destination, {
|
|
874
|
+
flags: 'wx',
|
|
875
|
+
mode: 0o400,
|
|
876
|
+
}),
|
|
877
|
+
{ signal },
|
|
878
|
+
)
|
|
879
|
+
} finally {
|
|
880
|
+
readStream.destroy()
|
|
881
|
+
}
|
|
873
882
|
return copied
|
|
874
883
|
}
|
|
875
884
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { raw } from 'jq-wasm'
|
|
2
|
-
|
|
3
1
|
export class JqError extends Error {
|
|
4
2
|
constructor(message: string) {
|
|
5
3
|
super(message)
|
|
@@ -17,6 +15,7 @@ export async function applyJq(content: string, query: string): Promise<string> {
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
try {
|
|
18
|
+
const { raw } = await import('jq-wasm')
|
|
20
19
|
const result = await raw(parsed as string | object, query)
|
|
21
20
|
if (result.exitCode !== 0 || result.stderr) {
|
|
22
21
|
const detail = result.stderr.trim() || `exit code ${result.exitCode}`
|
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
import { Readability } from '@mozilla/readability'
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import type { Readability as ReadabilityClass } from '@mozilla/readability'
|
|
2
|
+
import type TurndownService from 'turndown'
|
|
3
|
+
|
|
4
|
+
// Perf: jsdom (+readability+turndown) costs ~40-60MB RSS at import time. Keep it
|
|
5
|
+
// lazy so idle agents that never call web_fetch don't pay for it. Do NOT hoist to
|
|
6
|
+
// a top-level import.
|
|
7
|
+
type ReadabilityDeps = {
|
|
8
|
+
Readability: typeof ReadabilityClass
|
|
9
|
+
JSDOM: typeof import('jsdom').JSDOM
|
|
10
|
+
turndown: TurndownService
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let depsPromise: Promise<ReadabilityDeps> | undefined
|
|
14
|
+
|
|
15
|
+
async function loadDeps(): Promise<ReadabilityDeps> {
|
|
16
|
+
depsPromise ??= (async () => {
|
|
17
|
+
const [{ Readability }, { JSDOM }, { default: TurndownCtor }] = await Promise.all([
|
|
18
|
+
import('@mozilla/readability'),
|
|
19
|
+
import('jsdom'),
|
|
20
|
+
import('turndown'),
|
|
21
|
+
])
|
|
22
|
+
const turndown = new TurndownCtor({
|
|
23
|
+
headingStyle: 'atx',
|
|
24
|
+
codeBlockStyle: 'fenced',
|
|
25
|
+
bulletListMarker: '-',
|
|
26
|
+
emDelimiter: '*',
|
|
27
|
+
hr: '---',
|
|
28
|
+
})
|
|
29
|
+
turndown.remove(['script', 'style', 'meta', 'link', 'noscript', 'iframe'])
|
|
30
|
+
return { Readability, JSDOM, turndown }
|
|
31
|
+
})()
|
|
32
|
+
return depsPromise
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type ReadabilityDocument = ConstructorParameters<typeof ReadabilityClass>[0]
|
|
36
|
+
|
|
37
|
+
export async function applyReadability(html: string, url: string): Promise<string> {
|
|
38
|
+
const { Readability, JSDOM, turndown } = await loadDeps()
|
|
39
|
+
|
|
17
40
|
const dom = new JSDOM(html, { url })
|
|
18
41
|
const document = dom.window.document.cloneNode(true) as unknown as ReadabilityDocument
|
|
19
42
|
const article = new Readability(document).parse()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as cheerio from 'cheerio'
|
|
1
|
+
import type * as cheerio from 'cheerio'
|
|
2
2
|
|
|
3
3
|
export class SelectorError extends Error {
|
|
4
4
|
constructor(message: string) {
|
|
@@ -7,7 +7,9 @@ export class SelectorError extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function applySelector(html: string, selector: string): string {
|
|
10
|
+
export async function applySelector(html: string, selector: string): Promise<string> {
|
|
11
|
+
const cheerio = await import('cheerio')
|
|
12
|
+
|
|
11
13
|
let $: cheerio.CheerioAPI
|
|
12
14
|
try {
|
|
13
15
|
$ = cheerio.load(html)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as cheerio from 'cheerio'
|
|
1
|
+
import type * as cheerio from 'cheerio'
|
|
2
2
|
import type { AnyNode, Element } from 'domhandler'
|
|
3
3
|
|
|
4
4
|
const SEMANTIC_TAGS = new Set([
|
|
@@ -65,7 +65,8 @@ const ROLE_FOR_TAG: Record<string, string> = {
|
|
|
65
65
|
label: 'label',
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function applySnapshot(html: string): string {
|
|
68
|
+
export async function applySnapshot(html: string): Promise<string> {
|
|
69
|
+
const cheerio = await import('cheerio')
|
|
69
70
|
const $ = cheerio.load(html)
|
|
70
71
|
const lines: string[] = []
|
|
71
72
|
const body = $('body').get(0)
|
|
@@ -226,7 +226,7 @@ async function runStrategy(
|
|
|
226
226
|
case 'raw':
|
|
227
227
|
return applyRaw(body)
|
|
228
228
|
case 'readability':
|
|
229
|
-
return applyReadability(body, url)
|
|
229
|
+
return await applyReadability(body, url)
|
|
230
230
|
case 'jq':
|
|
231
231
|
try {
|
|
232
232
|
return await applyJq(body, params.query ?? '')
|
|
@@ -236,7 +236,7 @@ async function runStrategy(
|
|
|
236
236
|
}
|
|
237
237
|
case 'selector':
|
|
238
238
|
try {
|
|
239
|
-
return applySelector(body, params.selector ?? '')
|
|
239
|
+
return await applySelector(body, params.selector ?? '')
|
|
240
240
|
} catch (error) {
|
|
241
241
|
if (error instanceof SelectorError) throw new Error(error.message)
|
|
242
242
|
throw error
|
|
@@ -255,7 +255,7 @@ async function runStrategy(
|
|
|
255
255
|
throw error
|
|
256
256
|
}
|
|
257
257
|
case 'snapshot':
|
|
258
|
-
return applySnapshot(body)
|
|
258
|
+
return await applySnapshot(body)
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -299,8 +299,11 @@ async function resolveBackupAuthEnv(
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
export async function resolveOriginPushUrl(
|
|
303
|
-
|
|
302
|
+
export async function resolveOriginPushUrl(
|
|
303
|
+
cwd: string,
|
|
304
|
+
bunOverride?: { spawn: typeof Bun.spawn },
|
|
305
|
+
): Promise<string | null> {
|
|
306
|
+
const bun = bunOverride ?? (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
|
|
304
307
|
if (!bun) return null
|
|
305
308
|
const repo = resolveAgentGit(cwd)
|
|
306
309
|
if (!repo) return null
|
|
@@ -311,8 +314,22 @@ export async function resolveOriginPushUrl(cwd: string): Promise<string | null>
|
|
|
311
314
|
stderr: 'ignore',
|
|
312
315
|
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0' },
|
|
313
316
|
})
|
|
314
|
-
|
|
315
|
-
const
|
|
317
|
+
const exited = proc.exited
|
|
318
|
+
const stdoutDrain = new Response(proc.stdout).text()
|
|
319
|
+
let exitCode: number
|
|
320
|
+
let stdout: string
|
|
321
|
+
try {
|
|
322
|
+
;[exitCode, stdout] = await Promise.all([exited, stdoutDrain])
|
|
323
|
+
} catch {
|
|
324
|
+
// A stdout-drain rejection must not leave the git child running: kill it
|
|
325
|
+
// and await exit + drain before returning, so `Promise.all`'s early reject
|
|
326
|
+
// can't orphan the subprocess or its pipe.
|
|
327
|
+
proc.kill()
|
|
328
|
+
await Promise.allSettled([exited, stdoutDrain])
|
|
329
|
+
return null
|
|
330
|
+
}
|
|
331
|
+
if (exitCode !== 0) return null
|
|
332
|
+
const out = stdout.trim()
|
|
316
333
|
return out === '' ? null : out
|
|
317
334
|
} catch {
|
|
318
335
|
return null
|
|
@@ -399,9 +399,9 @@ function sanitizeCommitMessage(raw: string): string {
|
|
|
399
399
|
return rest.length > 0 ? `${subject}\n\n${rest}` : subject
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
export function makeDefaultGitSpawn(): GitSpawn {
|
|
402
|
+
export function makeDefaultGitSpawn(bunOverride?: { spawn: typeof Bun.spawn }): GitSpawn {
|
|
403
403
|
return withIndexLockRetry(async (args, { cwd, timeoutMs, env }) => {
|
|
404
|
-
const bun = (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
|
|
404
|
+
const bun = bunOverride ?? (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
|
|
405
405
|
if (!bun) {
|
|
406
406
|
return { exitCode: 127, stdout: '', stderr: 'Bun runtime not available', timedOut: false }
|
|
407
407
|
}
|
|
@@ -419,9 +419,23 @@ export function makeDefaultGitSpawn(): GitSpawn {
|
|
|
419
419
|
env: { ...process.env, ...NONINTERACTIVE_ENV, ...env },
|
|
420
420
|
signal: controller.signal,
|
|
421
421
|
})
|
|
422
|
-
const
|
|
423
|
-
const
|
|
424
|
-
const
|
|
422
|
+
const exitedDrain = proc.exited
|
|
423
|
+
const stdoutDrain = new Response(proc.stdout).text()
|
|
424
|
+
const stderrDrain = new Response(proc.stderr).text()
|
|
425
|
+
let exitCode: number
|
|
426
|
+
let stdout: string
|
|
427
|
+
let stderr: string
|
|
428
|
+
try {
|
|
429
|
+
;[exitCode, stdout, stderr] = await Promise.all([exitedDrain, stdoutDrain, stderrDrain])
|
|
430
|
+
} catch (drainErr) {
|
|
431
|
+
// A pipe-read rejection must not escape while the git child is still
|
|
432
|
+
// running (the outer `finally` would clear the abort timer and leave a
|
|
433
|
+
// stuck child unbounded). Abort to kill it, then wait for exit and both
|
|
434
|
+
// drains to settle before surfacing the error.
|
|
435
|
+
controller.abort()
|
|
436
|
+
await Promise.allSettled([exitedDrain, stdoutDrain, stderrDrain])
|
|
437
|
+
throw drainErr
|
|
438
|
+
}
|
|
425
439
|
const timedOut = controller.signal.aborted
|
|
426
440
|
return { exitCode, stdout, stderr, timedOut }
|
|
427
441
|
} catch (err) {
|
|
@@ -24,7 +24,7 @@ import { embed, EMBEDDING_MODEL_ID, type EmbedType } from './embedder'
|
|
|
24
24
|
import type { Passage } from './passages'
|
|
25
25
|
import { clearsBaseline, gateRelevance, MARGIN, streamAdmissionBaseline } from './relevance-gate'
|
|
26
26
|
import { crossScriptMarginScale, dominantScript, type ScriptClass } from './script'
|
|
27
|
-
import { VectorStore, type ScoredVectorRow, type VectorRow } from './store'
|
|
27
|
+
import { scoreRows, VectorStore, type ScoredVectorRow, type VectorRow } from './store'
|
|
28
28
|
import { chunkEmbeddableText } from './truncation'
|
|
29
29
|
|
|
30
30
|
export { collectPassages, findMissingPassages, type Passage } from './passages'
|
|
@@ -241,9 +241,17 @@ function maxScoreAcrossChunks(
|
|
|
241
241
|
queryEmbeddings: Float32Array[],
|
|
242
242
|
store: VectorStore,
|
|
243
243
|
): { scored: ScoredVectorRow[]; winnerChunkByRowId: Map<string, number> } {
|
|
244
|
+
// Decode the compatible corpus ONCE and score every chunk against it, instead
|
|
245
|
+
// of re-reading and re-decoding the whole table per chunk (queryScored did a
|
|
246
|
+
// full SELECT + BLOB decode on each call). Same MAX-across-chunks result, but
|
|
247
|
+
// the O(rows) decode runs once per turn instead of once per chunk.
|
|
248
|
+
const dims = queryEmbeddings[0]?.length
|
|
249
|
+
if (dims === undefined) return { scored: [], winnerChunkByRowId: new Map() }
|
|
250
|
+
const rows = store.loadRows(EMBEDDING_MODEL_ID, dims)
|
|
251
|
+
|
|
244
252
|
const best = new Map<string, { scored: ScoredVectorRow; chunkIndex: number }>()
|
|
245
253
|
queryEmbeddings.forEach((embedding, chunkIndex) => {
|
|
246
|
-
for (const scoredRow of
|
|
254
|
+
for (const scoredRow of scoreRows(rows, embedding)) {
|
|
247
255
|
const existing = best.get(scoredRow.row.id)
|
|
248
256
|
if (existing === undefined || scoredRow.score > existing.scored.score) {
|
|
249
257
|
best.set(scoredRow.row.id, { scored: scoredRow, chunkIndex })
|
|
@@ -95,24 +95,28 @@ export class VectorStore {
|
|
|
95
95
|
// Same cosine scan as `query` but returns every compatible row WITH its score
|
|
96
96
|
// and unsliced, so a caller can reason about the full score distribution (the
|
|
97
97
|
// relevance gate's per-query baseline) before deciding how many to keep.
|
|
98
|
+
queryScored(embedding: Float32Array, modelId: string): ScoredVectorRow[] {
|
|
99
|
+
return scoreRows(this.loadRows(modelId, embedding.length), embedding).sort((a, b) => b.score - a.score)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Decodes every compatible row's embedding BLOB into a Float32Array ONCE. A
|
|
103
|
+
// multi-chunk query scores many embeddings against the SAME corpus, so callers
|
|
104
|
+
// that decode here once and reuse the result across chunks avoid re-reading and
|
|
105
|
+
// re-decoding the whole table per chunk (the per-turn allocation hot path). The
|
|
106
|
+
// returned rows are transient — held only for the current search, never cached
|
|
107
|
+
// across turns (that would trade collectable garbage for permanent resident
|
|
108
|
+
// memory, the opposite of what we want).
|
|
98
109
|
//
|
|
99
110
|
// Filter by embedding identity, not dims alone: a stale row from a different
|
|
100
111
|
// model/dtype variant can share the same dims but lives in an incompatible
|
|
101
112
|
// vector space, so cosine against it is garbage. Excluding it here keeps a
|
|
102
113
|
// partial re-embed (mixed variants mid-rebuild) at reduced recall, never
|
|
103
114
|
// wrong scores.
|
|
104
|
-
|
|
105
|
-
// The query vector's magnitude is identical for every row in this scan, so
|
|
106
|
-
// hoist it out of the per-row cosine instead of recomputing N times (each
|
|
107
|
-
// recompute is 768 multiply-adds + a sqrt). Behavior is unchanged — same
|
|
108
|
-
// cosine values, fewer operations on the brute-force hot path.
|
|
109
|
-
const queryMagnitude = magnitude(embedding)
|
|
115
|
+
loadRows(modelId: string, dims: number): VectorRow[] {
|
|
110
116
|
return this.db
|
|
111
117
|
.query<StoredVectorRow, [string, number]>('SELECT * FROM vectors WHERE model = ? AND dims = ?')
|
|
112
|
-
.all(modelId,
|
|
118
|
+
.all(modelId, dims)
|
|
113
119
|
.map(toVectorRow)
|
|
114
|
-
.map((row) => ({ row, score: cosineSimilarity(embedding, queryMagnitude, row.embedding) }))
|
|
115
|
-
.sort((a, b) => b.score - a.score)
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
deleteOtherModels(modelId: string): void {
|
|
@@ -160,6 +164,14 @@ export class VectorStore {
|
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
|
|
167
|
+
// Scores pre-decoded rows against one query embedding. The query vector's
|
|
168
|
+
// magnitude is identical for every row, so hoist it out of the per-row cosine
|
|
169
|
+
// instead of recomputing N times (each recompute is 768 multiply-adds + a sqrt).
|
|
170
|
+
export function scoreRows(rows: VectorRow[], embedding: Float32Array): ScoredVectorRow[] {
|
|
171
|
+
const queryMagnitude = magnitude(embedding)
|
|
172
|
+
return rows.map((row) => ({ row, score: cosineSimilarity(embedding, queryMagnitude, row.embedding) }))
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
function toVectorRow(row: StoredVectorRow): VectorRow {
|
|
164
176
|
return {
|
|
165
177
|
id: row.id,
|
|
@@ -88,6 +88,12 @@ const ENV_KEY_RECON_TARGETS: ReadonlyArray<string> = [
|
|
|
88
88
|
|
|
89
89
|
const ENV_KEY_RECON_THRESHOLD = 3
|
|
90
90
|
|
|
91
|
+
// Names are fixed literals, so these boundary regexes are constant. Compile
|
|
92
|
+
// once at module load, not ~30 RegExps per outbound message (guard is per-send).
|
|
93
|
+
const ENV_KEY_RECON_MATCHERS: ReadonlyArray<readonly [name: string, pattern: RegExp]> = ENV_KEY_RECON_TARGETS.map(
|
|
94
|
+
(name) => [name, new RegExp(`\\b${name}\\b`)] as const,
|
|
95
|
+
)
|
|
96
|
+
|
|
91
97
|
const TEXT_KEYS = ['text', 'message', 'content', 'body']
|
|
92
98
|
|
|
93
99
|
export type OutboundSecretMatch = {
|
|
@@ -137,9 +143,8 @@ export function findOutboundSecrets(text: string, env: NodeJS.ProcessEnv = proce
|
|
|
137
143
|
|
|
138
144
|
function findReconEnvKeys(text: string): string[] {
|
|
139
145
|
const out: string[] = []
|
|
140
|
-
for (const name of
|
|
141
|
-
|
|
142
|
-
if (re.test(text)) out.push(name)
|
|
146
|
+
for (const [name, pattern] of ENV_KEY_RECON_MATCHERS) {
|
|
147
|
+
if (pattern.test(text)) out.push(name)
|
|
143
148
|
}
|
|
144
149
|
return out
|
|
145
150
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
CANONICAL_AGENT_SECRET_FILES,
|
|
23
23
|
CANONICAL_HOME_SECRET_DIRS,
|
|
24
24
|
CANONICAL_HOME_SECRET_FILES,
|
|
25
|
+
CONTAINER_RUNTIME_HOME,
|
|
25
26
|
type HiddenPaths,
|
|
26
27
|
} from '@/sandbox'
|
|
27
28
|
|
|
@@ -166,7 +167,11 @@ function deniedSurface(agentDir: string, hidden: HiddenPaths): { deniedDirs: str
|
|
|
166
167
|
...new Set([
|
|
167
168
|
...hidden.dirs,
|
|
168
169
|
...CANONICAL_AGENT_SECRET_DIRS.map((dir) => path.join(agentDir, dir)),
|
|
170
|
+
// homedir() follows the live container HOME; the fixed runtime path
|
|
171
|
+
// keeps the same denial deterministic in host-stage tests and any
|
|
172
|
+
// partially-initialized caller whose environment has not switched yet.
|
|
169
173
|
...CANONICAL_HOME_SECRET_DIRS.map((dir) => path.join(homedir(), dir)),
|
|
174
|
+
...CANONICAL_HOME_SECRET_DIRS.map((dir) => path.join(CONTAINER_RUNTIME_HOME, dir)),
|
|
170
175
|
]),
|
|
171
176
|
],
|
|
172
177
|
// Keep runtime-owned credential stores independent of role-derived
|
|
@@ -176,6 +181,7 @@ function deniedSurface(agentDir: string, hidden: HiddenPaths): { deniedDirs: str
|
|
|
176
181
|
...hidden.files,
|
|
177
182
|
...CANONICAL_AGENT_SECRET_FILES.map((file) => path.join(agentDir, file)),
|
|
178
183
|
...CANONICAL_HOME_SECRET_FILES.map((file) => path.join(homedir(), file)),
|
|
184
|
+
...CANONICAL_HOME_SECRET_FILES.map((file) => path.join(CONTAINER_RUNTIME_HOME, file)),
|
|
179
185
|
]),
|
|
180
186
|
],
|
|
181
187
|
}
|
package/src/cli/inspect.ts
CHANGED
|
@@ -150,6 +150,19 @@ export async function runInspectViewer(opts: RunInspectViewerOptions): Promise<n
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
const interactive = Boolean(process.stdin.isTTY)
|
|
153
|
+
|
|
154
|
+
// Without a TTY, clack's picker keypress loop busy-spins kevent64 at 100% CPU
|
|
155
|
+
// forever instead of resolving (e.g. `typeclaw inspect | head`, a daemon
|
|
156
|
+
// spawn). A resolved session arg auto-opens without the picker, so only the
|
|
157
|
+
// picker-mandatory case is refused — mirroring --json's explicit-id rule.
|
|
158
|
+
if (!interactive && preselectKey === undefined) {
|
|
159
|
+
process.stderr.write(`${errorLine('typeclaw inspect needs an interactive terminal to pick a session.')}\n`)
|
|
160
|
+
process.stderr.write(
|
|
161
|
+
'Pass an explicit session id (`typeclaw inspect <id>`) or use `--json <id>` for a scriptable stream.\n',
|
|
162
|
+
)
|
|
163
|
+
return 2
|
|
164
|
+
}
|
|
165
|
+
|
|
153
166
|
const liveHint = interactive ? escHintLine(color) : undefined
|
|
154
167
|
const inspectUrl = containerRunning ? await resolveInspectUrl(cwd) : undefined
|
|
155
168
|
const liveSource = inspectUrl !== undefined ? buildLiveSource(inspectUrl) : undefined
|
|
@@ -181,6 +194,9 @@ export async function runInspectViewer(opts: RunInspectViewerOptions): Promise<n
|
|
|
181
194
|
const listOpts: Parameters<typeof listViewerItems>[0] = {
|
|
182
195
|
sessionsDir,
|
|
183
196
|
containerRunning,
|
|
197
|
+
// listViewerItems also gates writable promotion on `interactive`, so a
|
|
198
|
+
// non-TTY explicit id can't auto-open a TUI it cannot drive.
|
|
199
|
+
interactive,
|
|
184
200
|
// Compose the CLI-level permission (false on tui detach handoff) with
|
|
185
201
|
// the loop-level one (false after returning to the picker from a viewer).
|
|
186
202
|
allowWritable: cliAllowWritable && loopAllowWritable,
|
package/src/container/shared.ts
CHANGED
|
@@ -92,7 +92,7 @@ export const defaultDockerExec: DockerExec = async (args, options) => {
|
|
|
92
92
|
// needs both: the user watches the build, and start() inspects the captured
|
|
93
93
|
// stderr to detect a missing credential helper and retry under a sanitized
|
|
94
94
|
// DOCKER_CONFIG.
|
|
95
|
-
async function spawnInheritTeeStderr(
|
|
95
|
+
export async function spawnInheritTeeStderr(
|
|
96
96
|
bun: NonNullable<ReturnType<typeof getBun>>,
|
|
97
97
|
cmd: string[],
|
|
98
98
|
cwd: string | undefined,
|
|
@@ -102,11 +102,24 @@ async function spawnInheritTeeStderr(
|
|
|
102
102
|
const proc = bun.spawn({ cmd, cwd, stdout: 'inherit', stderr: 'pipe', signal, env })
|
|
103
103
|
const chunks: Uint8Array[] = []
|
|
104
104
|
const reader = proc.stderr.getReader()
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
try {
|
|
106
|
+
for (;;) {
|
|
107
|
+
const { done, value } = await reader.read()
|
|
108
|
+
if (done) break
|
|
109
|
+
process.stderr.write(value)
|
|
110
|
+
chunks.push(value)
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {
|
|
113
|
+
// A read/write throw skips the normal drain: cancel (not just releaseLock,
|
|
114
|
+
// which leaves the pipe live per the Streams contract), kill the child, and
|
|
115
|
+
// await its exit so neither the stderr pipe nor the docker subprocess is
|
|
116
|
+
// orphaned. releaseLock is handled in `finally` for both paths.
|
|
117
|
+
await reader.cancel().catch(() => {})
|
|
118
|
+
proc.kill()
|
|
119
|
+
await proc.exited.catch(() => {})
|
|
120
|
+
throw err
|
|
121
|
+
} finally {
|
|
122
|
+
reader.releaseLock()
|
|
110
123
|
}
|
|
111
124
|
const exitCode = await proc.exited
|
|
112
125
|
return { exitCode, stdout: '', stderr: Buffer.concat(chunks).toString('utf8') }
|
package/src/init/checkpoint.ts
CHANGED
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
|
|
14
14
|
// In-folder scratch for an in-progress `typeclaw init`, co-located with the
|
|
15
15
|
// agent it describes. Lives under the agent's `.typeclaw/` (the same gitignored
|
|
16
|
-
// local-scratch dir
|
|
17
|
-
// the half-init folder is deleted, survives a folder
|
|
18
|
-
// inspectable right next to the thing being resumed.
|
|
19
|
-
// `TRULY_IGNORED_PATTERNS`; never committed.
|
|
16
|
+
// local-scratch dir that may contain orphaned legacy runtime-HOME credentials),
|
|
17
|
+
// so it self-cleans when the half-init folder is deleted, survives a folder
|
|
18
|
+
// rename mid-init, and is inspectable right next to the thing being resumed.
|
|
19
|
+
// Gitignored via `TRULY_IGNORED_PATTERNS`; never committed.
|
|
20
20
|
export const INIT_CHECKPOINT_PATH = join('.typeclaw', 'init-progress.json')
|
|
21
21
|
|
|
22
22
|
export const WIZARD_CHECKPOINT_VERSION = 1
|