typeclaw 0.51.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 +2 -0
- package/dist/types/agent/bash-sandbox.d.ts +4 -0
- package/dist/types/agent/index.d.ts +5 -0
- package/dist/types/agent/multimodal/look-at.d.ts +1 -1
- package/dist/types/agent/plugin-tools.d.ts +4 -0
- 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 +1 -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/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 +1 -1
- 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-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 +5 -1
- 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 +20 -11
- package/dist/types/config/providers.d.ts +47 -0
- package/dist/types/eval/sandbox.d.ts +2 -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/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 +33 -1
- package/src/agent/bash-sandbox.ts +20 -6
- package/src/agent/index.ts +120 -31
- package/src/agent/multimodal/look-at.ts +1 -1
- package/src/agent/plugin-tools.ts +35 -1
- package/src/agent/prompt-cache-key.ts +26 -3
- package/src/agent/session-origin.ts +39 -18
- package/src/agent/session-tail.ts +28 -0
- package/src/agent/subagents.ts +21 -2
- package/src/agent/system-prompt-composition.ts +18 -0
- package/src/agent/system-prompt.ts +39 -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/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/browser/dockerfile.ts +1 -1
- package/src/browser/fill-secret.ts +92 -35
- 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/managed-browser/index.ts +25 -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 +2 -0
- package/src/bundled-plugins/memory/index.ts +33 -6
- package/src/bundled-plugins/memory/memory-logger.ts +133 -11
- 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 +131 -26
- package/src/bundled-plugins/memory/transcript-view.ts +36 -0
- 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/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/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-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 +120 -21
- package/src/channels/schema.ts +1 -1
- package/src/channels/types.ts +3 -0
- package/src/coding-agent/tool.ts +1 -1
- package/src/config/config.ts +20 -1
- package/src/config/providers.ts +65 -0
- package/src/container/start.ts +15 -2
- package/src/doctor/channel-checks.ts +33 -0
- package/src/doctor/checks.ts +12 -2
- package/src/eval/sandbox.ts +3 -0
- package/src/eval/tool.ts +1 -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/permissions/builtins.ts +8 -0
- 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/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 +8 -1
- package/src/skills/typeclaw-config/SKILL.md +16 -0
- 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 +40 -10
package/scripts/test.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// `bun run test`: runs only the test files impacted by your changes. CI always
|
|
2
|
+
// runs everything, so a heuristic selection can never decide a merge.
|
|
3
|
+
//
|
|
4
|
+
// Why not `bun test --changed`: it follows imports only, but many tests here
|
|
5
|
+
// spawn the CLI or a worker script by path, or read a source file directly, and
|
|
6
|
+
// it knows nothing about inputs that are not modules. Those tests would be
|
|
7
|
+
// skipped silently. The rule below is to over-select rather than miss a test:
|
|
8
|
+
// anything this script cannot trace to specific tests runs the full suite.
|
|
9
|
+
|
|
10
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
11
|
+
import { dirname, relative, resolve, sep } from 'node:path'
|
|
12
|
+
|
|
13
|
+
export type ImportGraph = {
|
|
14
|
+
files: readonly string[]
|
|
15
|
+
importsOf(file: string): readonly string[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Selection = { mode: 'full'; reason: string } | { mode: 'files'; files: string[] }
|
|
19
|
+
|
|
20
|
+
export type ChangeSet = { base: string; baseLabel: string; files: string[] }
|
|
21
|
+
|
|
22
|
+
const MODULE_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/
|
|
23
|
+
const TEST_FILE = /\.test\.(?:[cm]?[jt]s|[jt]sx)$/
|
|
24
|
+
const MODULE_ROOTS = ['src/', 'scripts/']
|
|
25
|
+
// Verified not to be read by any test. Everything else that is not a module,
|
|
26
|
+
// including the skill Markdown under src/, may be a test input.
|
|
27
|
+
const NON_INPUT_DIRECTORIES = ['docs/', '.github/']
|
|
28
|
+
const NON_INPUT_FILES = new Set(['LICENSE', '.gitattributes', '.oxlintrc.json', '.oxfmtrc.json'])
|
|
29
|
+
// A path in a string, such as './worker.ts', '../cli/index', or 'src/cli/index.ts'.
|
|
30
|
+
const PATH_LITERAL = /(?:\.{1,2}\/[\w@./-]+|[\w@./-]+\.(?:[cm]?[jt]s|[jt]sx))(?![\w/-])/g
|
|
31
|
+
// `join(import.meta.dir, '..', 'plugin', 'index.ts')` spreads one path over several strings.
|
|
32
|
+
const JOINED_PATH = /(?:join|resolve)\(\s*import\.meta\.dir((?:\s*,\s*'[^']*')+)/g
|
|
33
|
+
const QUOTED_SIBLING = /['"](?:\.\/)?([\w@.-]+\.(?:[cm]?[jt]s|[jt]sx))['"]/g
|
|
34
|
+
// Type-only imports do not run, so their paths must not count as path literals.
|
|
35
|
+
const TYPE_ONLY_IMPORT = /^\s*(?:import|export)\s+type\b[^;'"`]*?\bfrom\s+['"][^'"]+['"]/gm
|
|
36
|
+
|
|
37
|
+
export function selectImpactedTests(
|
|
38
|
+
changedFiles: readonly string[],
|
|
39
|
+
preloads: readonly string[],
|
|
40
|
+
graph: ImportGraph,
|
|
41
|
+
): Selection {
|
|
42
|
+
const existing = new Set(graph.files)
|
|
43
|
+
const changedModules: string[] = []
|
|
44
|
+
|
|
45
|
+
for (const file of changedFiles) {
|
|
46
|
+
if (isNonInput(file)) continue
|
|
47
|
+
if (!MODULE_FILE.test(file)) return { mode: 'full', reason: `${file} is not a module` }
|
|
48
|
+
if (existing.has(file)) changedModules.push(file)
|
|
49
|
+
else if (!TEST_FILE.test(file)) return { mode: 'full', reason: `${file} was deleted` }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const importers = new Map<string, string[]>()
|
|
53
|
+
for (const file of graph.files) {
|
|
54
|
+
for (const dependency of graph.importsOf(file)) {
|
|
55
|
+
const list = importers.get(dependency)
|
|
56
|
+
if (list) list.push(file)
|
|
57
|
+
else importers.set(dependency, [file])
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const impacted = new Set(changedModules)
|
|
62
|
+
const pending = [...changedModules]
|
|
63
|
+
for (let file = pending.pop(); file !== undefined; file = pending.pop()) {
|
|
64
|
+
for (const importer of importers.get(file) ?? []) {
|
|
65
|
+
if (impacted.has(importer)) continue
|
|
66
|
+
impacted.add(importer)
|
|
67
|
+
pending.push(importer)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const preload = preloads.find((file) => impacted.has(file))
|
|
72
|
+
if (preload) return { mode: 'full', reason: `the test preload ${preload} is impacted` }
|
|
73
|
+
return { mode: 'files', files: [...impacted].filter((file) => TEST_FILE.test(file)).sort() }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function createImportGraph(repoRoot: string, files: readonly string[]): ImportGraph {
|
|
77
|
+
// Bun resolves symlinks, so a checkout under one (macOS /tmp) must compare by real path.
|
|
78
|
+
const root = realpathSync(repoRoot)
|
|
79
|
+
const known = new Set(files)
|
|
80
|
+
const toRepoPath = (path: string) => relative(root, path).split(sep).join('/')
|
|
81
|
+
const lookup = (path: string) =>
|
|
82
|
+
[path, `${path}.ts`, `${path}.tsx`, `${path}/index.ts`].map(toRepoPath).find((file) => known.has(file))
|
|
83
|
+
const transpilers = {
|
|
84
|
+
ts: new Bun.Transpiler({ loader: 'ts' }),
|
|
85
|
+
tsx: new Bun.Transpiler({ loader: 'tsx' }),
|
|
86
|
+
js: new Bun.Transpiler({ loader: 'js' }),
|
|
87
|
+
}
|
|
88
|
+
const cache = new Map<string, string[]>()
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
files,
|
|
92
|
+
importsOf(file) {
|
|
93
|
+
const cached = cache.get(file)
|
|
94
|
+
if (cached) return cached
|
|
95
|
+
|
|
96
|
+
const path = resolve(root, file)
|
|
97
|
+
const directory = dirname(path)
|
|
98
|
+
// scanImports treats a shebang as a syntax error.
|
|
99
|
+
const source = readFileSync(path, 'utf8').replace(/^#!.*/, '')
|
|
100
|
+
const imports = new Set<string>()
|
|
101
|
+
|
|
102
|
+
let scanned: Bun.Import[]
|
|
103
|
+
try {
|
|
104
|
+
scanned = transpilers[loaderOf(file)].scanImports(source)
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw new Error(`Could not scan imports of ${file}. Run with --full to skip change detection.`, {
|
|
107
|
+
cause: error,
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
for (const { path: specifier } of scanned) {
|
|
111
|
+
const target = resolveImport(specifier, directory)
|
|
112
|
+
const repoPath = target && lookup(target)
|
|
113
|
+
if (repoPath) imports.add(repoPath)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// A test can name anything it spawns or reads. A runtime module only counts for
|
|
117
|
+
// a sibling it names as a quoted file, like a script it launches: its other
|
|
118
|
+
// paths are mostly prose, and following those ties the whole tree into one
|
|
119
|
+
// cycle through the CLI entry, which would select most tests for any change.
|
|
120
|
+
if (!TEST_FILE.test(file)) {
|
|
121
|
+
for (const [, sibling = ''] of source.matchAll(QUOTED_SIBLING)) {
|
|
122
|
+
const repoPath = lookup(resolve(directory, sibling))
|
|
123
|
+
if (repoPath) imports.add(repoPath)
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
const code = source.replace(TYPE_ONLY_IMPORT, '')
|
|
127
|
+
for (const [literal] of code.matchAll(PATH_LITERAL)) {
|
|
128
|
+
for (const base of [directory, root]) {
|
|
129
|
+
const repoPath = lookup(resolve(base, literal))
|
|
130
|
+
if (repoPath) imports.add(repoPath)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const [, segments = ''] of code.matchAll(JOINED_PATH)) {
|
|
134
|
+
const parts = [...segments.matchAll(/'([^']*)'/g)].flatMap(([, part]) => (part ? [part] : []))
|
|
135
|
+
const repoPath = lookup(resolve(directory, ...parts))
|
|
136
|
+
if (repoPath) imports.add(repoPath)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
imports.delete(file)
|
|
141
|
+
const result = [...imports]
|
|
142
|
+
cache.set(file, result)
|
|
143
|
+
return result
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Branch commits plus staged, unstaged, and untracked files. The base is the
|
|
149
|
+
// merge-base, not origin/main itself, so commits landed on main after branching
|
|
150
|
+
// do not count as changes.
|
|
151
|
+
export async function collectChangeSet(repoRoot: string): Promise<ChangeSet> {
|
|
152
|
+
const mergeBase = await git(repoRoot, ['merge-base', 'HEAD', 'origin/main'])
|
|
153
|
+
const base = mergeBase ?? (await git(repoRoot, ['rev-parse', 'HEAD']))
|
|
154
|
+
if (!base) throw new Error('Could not resolve a git base commit. Run with --full outside a git checkout.')
|
|
155
|
+
|
|
156
|
+
const [tracked, untracked] = await Promise.all([
|
|
157
|
+
git(repoRoot, ['diff', '--name-only', '--no-renames', base]),
|
|
158
|
+
git(repoRoot, ['ls-files', '--others', '--exclude-standard']),
|
|
159
|
+
])
|
|
160
|
+
return {
|
|
161
|
+
base,
|
|
162
|
+
baseLabel: mergeBase ? 'merge-base with origin/main' : 'HEAD, origin/main not found',
|
|
163
|
+
files: [...new Set([...lines(tracked), ...lines(untracked)])].sort(),
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function listModuleFiles(repoRoot: string): Promise<string[]> {
|
|
168
|
+
const output = await git(repoRoot, ['ls-files', '--cached', '--others', '--exclude-standard'])
|
|
169
|
+
return lines(output).filter(
|
|
170
|
+
(file) =>
|
|
171
|
+
MODULE_FILE.test(file) &&
|
|
172
|
+
MODULE_ROOTS.some((root) => file.startsWith(root)) &&
|
|
173
|
+
existsSync(resolve(repoRoot, file)),
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function readPreloads(repoRoot: string): string[] {
|
|
178
|
+
const config = Bun.TOML.parse(readFileSync(resolve(repoRoot, 'bunfig.toml'), 'utf8')) as {
|
|
179
|
+
test?: { preload?: string | string[] }
|
|
180
|
+
}
|
|
181
|
+
return [config.test?.preload ?? []].flat().flatMap((entry) => (entry.startsWith('./') ? [entry.slice(2)] : []))
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function loaderOf(file: string): 'ts' | 'tsx' | 'js' {
|
|
185
|
+
if (file.endsWith('x')) return 'tsx'
|
|
186
|
+
return /\.[cm]?js$/.test(file) ? 'js' : 'ts'
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function isNonInput(file: string): boolean {
|
|
190
|
+
if (NON_INPUT_FILES.has(file) || NON_INPUT_DIRECTORIES.some((directory) => file.startsWith(directory))) return true
|
|
191
|
+
return file.endsWith('.md') && !file.includes('/')
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Failures here are builtins and uninstalled optional dependencies. Neither is a repository file.
|
|
195
|
+
function resolveImport(specifier: string, fromDirectory: string): string | undefined {
|
|
196
|
+
try {
|
|
197
|
+
return Bun.resolveSync(specifier, fromDirectory)
|
|
198
|
+
} catch {
|
|
199
|
+
return undefined
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function git(cwd: string, args: readonly string[]): Promise<string | undefined> {
|
|
204
|
+
const result = await Bun.$`git ${args}`.cwd(cwd).quiet().nothrow()
|
|
205
|
+
return result.exitCode === 0 ? result.stdout.toString().trim() : undefined
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function lines(output: string | undefined): string[] {
|
|
209
|
+
return output ? output.split('\n').filter((line) => line.length > 0) : []
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function isCi(): boolean {
|
|
213
|
+
const value = process.env.CI?.toLowerCase()
|
|
214
|
+
return value !== undefined && value !== '' && value !== '0' && value !== 'false'
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function runBunTest(args: readonly string[]): Promise<number> {
|
|
218
|
+
const proc = Bun.spawn([process.execPath, 'test', '--parallel', '--no-orphans', ...args], {
|
|
219
|
+
stdio: ['inherit', 'inherit', 'inherit'],
|
|
220
|
+
})
|
|
221
|
+
return proc.exited
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function main(argv: readonly string[]): Promise<number> {
|
|
225
|
+
const args = argv.filter((arg) => arg !== '--full')
|
|
226
|
+
// Any other argument is a selection of its own, such as a path or `-t`.
|
|
227
|
+
if (args.length !== argv.length || args.length > 0 || isCi()) return runBunTest(args)
|
|
228
|
+
|
|
229
|
+
const repoRoot = resolve(import.meta.dir, '..')
|
|
230
|
+
const [changeSet, moduleFiles] = await Promise.all([collectChangeSet(repoRoot), listModuleFiles(repoRoot)])
|
|
231
|
+
const selection = selectImpactedTests(
|
|
232
|
+
changeSet.files,
|
|
233
|
+
readPreloads(repoRoot),
|
|
234
|
+
createImportGraph(repoRoot, moduleFiles),
|
|
235
|
+
)
|
|
236
|
+
const since = `${changeSet.files.length} changed file(s) since ${changeSet.base.slice(0, 9)} (${changeSet.baseLabel})`
|
|
237
|
+
|
|
238
|
+
if (selection.mode === 'full') {
|
|
239
|
+
console.log(`Running every test because ${selection.reason}.\n`)
|
|
240
|
+
return runBunTest([])
|
|
241
|
+
}
|
|
242
|
+
if (selection.files.length === 0) {
|
|
243
|
+
console.log(`No tests impacted by ${since}. Run with --full to test everything.\n`)
|
|
244
|
+
return 0
|
|
245
|
+
}
|
|
246
|
+
console.log(`Impacted: ${selection.files.length} test file(s), from ${since}. --full runs everything.\n`)
|
|
247
|
+
return runBunTest(selection.files.map((file) => `./${file}`))
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (import.meta.main) {
|
|
251
|
+
process.exitCode = await main(process.argv.slice(2))
|
|
252
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
+
import type { GithubSelfUser } from '@/channels/adapters/github/auth'
|
|
4
|
+
import { isFallbackGitIdentity, resolveGitIdentity } from '@/git/resolve-identity'
|
|
3
5
|
import { readEnvFile } from '@/init/env-file'
|
|
4
6
|
import { resolveExposableEnvNames } from '@/sandbox/env-exposure'
|
|
5
7
|
type BashEnvOverlay = Record<string, string>
|
|
6
|
-
|
|
8
|
+
// TYPECLAW_VAULT_GRANT is a bearer credential whose name the pattern below
|
|
9
|
+
// misses; in argv another sandboxed session could read it from proc cmdline.
|
|
10
|
+
const SECRET_BASH_ENV_NAMES = new Set(['GH_TOKEN', 'GITHUB_TOKEN', 'TYPECLAW_VAULT_GRANT'])
|
|
7
11
|
// Transport classifier for the TRUSTED hook-injected overlay only (e.g.
|
|
8
12
|
// github-cli-auth's per-repo GH_TOKEN). Token/secret-shaped names use `inherit`
|
|
9
13
|
// so their value never renders into the bwrap argv; plain names (GH_REPO) go
|
|
@@ -83,6 +87,34 @@ export function resolveExposableBashEnvNames(agentDir: string): { exposable: str
|
|
|
83
87
|
return { exposable, withheld }
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
// `typeclaw start` withholds a synthesized fallback identity from the container
|
|
91
|
+
// env so a later `git config` in the agent repo still takes effect. Without this,
|
|
92
|
+
// commits in any other repository (workspace clones, /tmp worktrees) fail with
|
|
93
|
+
// "Author identity unknown" and the model invents an identity, which can credit a
|
|
94
|
+
// stranger's GitHub account. Reading the agent repo per command keeps it live.
|
|
95
|
+
export async function resolveAgentGitIdentityEnv(
|
|
96
|
+
agentDir: string,
|
|
97
|
+
exposableEnvNames: readonly string[],
|
|
98
|
+
githubSelf: GithubSelfUser | null = null,
|
|
99
|
+
): Promise<BashEnvOverlay> {
|
|
100
|
+
const exposable = new Set(exposableEnvNames)
|
|
101
|
+
const names = {
|
|
102
|
+
GIT_AUTHOR_NAME: 'name',
|
|
103
|
+
GIT_AUTHOR_EMAIL: 'email',
|
|
104
|
+
GIT_COMMITTER_NAME: 'name',
|
|
105
|
+
GIT_COMMITTER_EMAIL: 'email',
|
|
106
|
+
} as const
|
|
107
|
+
const missing = Object.entries(names).filter(([name]) => !exposable.has(name))
|
|
108
|
+
if (missing.length === 0) return {}
|
|
109
|
+
const repoIdentity = await resolveGitIdentity(agentDir)
|
|
110
|
+
const identity =
|
|
111
|
+
githubSelf !== null && (repoIdentity === null || (await isFallbackGitIdentity(agentDir, repoIdentity)))
|
|
112
|
+
? { name: githubSelf.login, email: `${githubSelf.id}+${githubSelf.login}@users.noreply.github.com` }
|
|
113
|
+
: repoIdentity
|
|
114
|
+
if (identity === null) return {}
|
|
115
|
+
return Object.fromEntries(missing.map(([name, field]) => [name, identity[field]]))
|
|
116
|
+
}
|
|
117
|
+
|
|
86
118
|
export function buildRoleScopedConfigEnv(
|
|
87
119
|
agentDir: string,
|
|
88
120
|
hiddenDirs: string[],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
+
import type { GetGithubSelf } from '@/channels/github-token-bridge'
|
|
3
4
|
import { config, getSandboxWritablePathSpecs } from '@/config/config'
|
|
4
5
|
import type { PermissionService } from '@/permissions/permissions'
|
|
5
6
|
import {
|
|
@@ -29,11 +30,13 @@ import {
|
|
|
29
30
|
type SandboxPolicy,
|
|
30
31
|
type DependencyBinReconciliation,
|
|
31
32
|
} from '@/sandbox'
|
|
32
|
-
import {
|
|
33
|
+
import { resolveDevSourceMounts } from '@/sandbox/dev-source'
|
|
34
|
+
import { typevaultBashCliPath } from '@/typevault/cli-path'
|
|
33
35
|
|
|
34
36
|
import {
|
|
35
37
|
buildRoleScopedConfigEnv,
|
|
36
38
|
buildSandboxEnvPolicy,
|
|
39
|
+
resolveAgentGitIdentityEnv,
|
|
37
40
|
resolveExposableBashEnvNames,
|
|
38
41
|
spreadSandboxEnv,
|
|
39
42
|
} from './bash-sandbox-env'
|
|
@@ -89,7 +92,10 @@ export function buildBashFilesystemPolicy(options: BashFilesystemPolicyOptions)
|
|
|
89
92
|
return { masks, writable, protected: protectedZones }
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
export type BashSandboxReveal = NonNullable<SandboxPolicy['reveal']>
|
|
96
|
+
|
|
92
97
|
export type BashSandboxRequest = {
|
|
98
|
+
readonly getGithubSelf?: GetGithubSelf
|
|
93
99
|
readonly command: string
|
|
94
100
|
readonly permissions: PermissionService
|
|
95
101
|
readonly origin: SessionOrigin | undefined
|
|
@@ -98,6 +104,7 @@ export type BashSandboxRequest = {
|
|
|
98
104
|
readonly envOverlay?: Record<string, string>
|
|
99
105
|
readonly envWithhold?: string[]
|
|
100
106
|
readonly deferredPreparation?: DeferredBashPreparation
|
|
107
|
+
readonly reveal?: BashSandboxReveal
|
|
101
108
|
readonly boundary?: BashSandboxBoundary
|
|
102
109
|
readonly network?: SandboxNetwork
|
|
103
110
|
}
|
|
@@ -131,15 +138,21 @@ export async function prepareBashSandbox(options: BashSandboxRequest): Promise<P
|
|
|
131
138
|
try {
|
|
132
139
|
preparation = await deferredPreparation?.()
|
|
133
140
|
const command = preparation?.command ?? originalCommand
|
|
134
|
-
const preparedEnvOverlay = preparation?.env === undefined ? envOverlay : { ...envOverlay, ...preparation.env }
|
|
135
|
-
const { dirs, files } = resolveHiddenPaths(permissions, origin, agentDir)
|
|
136
141
|
const envNames = resolveExposableBashEnvNames(agentDir)
|
|
142
|
+
const gitIdentityEnv = await resolveAgentGitIdentityEnv(agentDir, envNames.exposable, options.getGithubSelf?.())
|
|
143
|
+
const mergedEnvOverlay = { ...gitIdentityEnv, ...envOverlay, ...preparation?.env }
|
|
144
|
+
const preparedEnvOverlay = Object.keys(mergedEnvOverlay).length > 0 ? mergedEnvOverlay : undefined
|
|
145
|
+
const { dirs, files } = resolveHiddenPaths(permissions, origin, agentDir)
|
|
137
146
|
const sandboxEnvOverlay = buildRoleScopedConfigEnv(agentDir, dirs, preparedEnvOverlay)
|
|
138
147
|
const effectiveEnvWithhold = (envWithhold ?? []).filter((name) => !Object.hasOwn(sandboxEnvOverlay ?? {}, name))
|
|
139
148
|
const maskTargets = await ensureHiddenMaskTargets({ dirs, files })
|
|
140
149
|
await boundary.ensureAvailable()
|
|
141
150
|
const sessionTmp = await ensureSessionTmpDir(sessionId)
|
|
142
|
-
const dependencyBins = await reconcileDependencyBinWrappers({
|
|
151
|
+
const dependencyBins = await reconcileDependencyBinWrappers({
|
|
152
|
+
agentDir,
|
|
153
|
+
sessionTmp,
|
|
154
|
+
...(config.typevault.enabled ? { runtimeBins: { typevault: typevaultBashCliPath() } } : {}),
|
|
155
|
+
})
|
|
143
156
|
const writable = subtractMasked(await resolveWritableZones(agentDir, getSandboxWritablePathSpecs(config)), {
|
|
144
157
|
dirs,
|
|
145
158
|
files,
|
|
@@ -168,7 +181,7 @@ export async function prepareBashSandbox(options: BashSandboxRequest): Promise<P
|
|
|
168
181
|
env: sandboxEnvOverlay,
|
|
169
182
|
})
|
|
170
183
|
await verifyHiddenMaskTargets(maskTargets)
|
|
171
|
-
const
|
|
184
|
+
const devSourceMounts = await resolveDevSourceMounts(agentDir)
|
|
172
185
|
const policy: SandboxPolicy = {
|
|
173
186
|
mounts: [
|
|
174
187
|
{ type: 'ro-bind', source: agentDir, dest: agentDir },
|
|
@@ -181,7 +194,7 @@ export async function prepareBashSandbox(options: BashSandboxRequest): Promise<P
|
|
|
181
194
|
// Dev/CI installations may place it outside /usr; expose only the
|
|
182
195
|
// executable, never its parent directory, under every proc strategy.
|
|
183
196
|
{ type: 'ro-bind', source: process.execPath, dest: process.execPath },
|
|
184
|
-
...
|
|
197
|
+
...devSourceMounts,
|
|
185
198
|
...(privilegedRuntime?.mounts ?? []),
|
|
186
199
|
...(preparation === undefined ? [] : [preparation.mount]),
|
|
187
200
|
],
|
|
@@ -192,6 +205,7 @@ export async function prepareBashSandbox(options: BashSandboxRequest): Promise<P
|
|
|
192
205
|
writable,
|
|
193
206
|
protected: protectedZones,
|
|
194
207
|
}),
|
|
208
|
+
...(options.reveal === undefined ? {} : { reveal: options.reveal }),
|
|
195
209
|
symlinks,
|
|
196
210
|
network: options.network ?? 'inherit',
|
|
197
211
|
cwd: agentDir,
|