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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ToolDefinition } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { WrapSystemToolOptions } from "../agent/plugin-tools.js";
|
|
4
|
+
import { type BudgetState, type ToolResultBudget } from "../agent/tool-result-budget.js";
|
|
5
|
+
import { type evalConfigSchema } from "./config.js";
|
|
6
|
+
export declare const EVAL_PROMPT_HINT: string;
|
|
7
|
+
export declare function registerEvalTool(options: {
|
|
8
|
+
readonly settings: z.infer<typeof evalConfigSchema>;
|
|
9
|
+
readonly tools: ToolDefinition[];
|
|
10
|
+
readonly activeNames: string[];
|
|
11
|
+
readonly getActiveNames: () => readonly string[];
|
|
12
|
+
readonly wrappers: WrapSystemToolOptions;
|
|
13
|
+
readonly budget?: ToolResultBudget;
|
|
14
|
+
readonly budgetState?: BudgetState;
|
|
15
|
+
}): {
|
|
16
|
+
dispose(): Promise<void>;
|
|
17
|
+
} | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HostFrame, KernelFrame } from "./protocol.js";
|
|
2
|
+
export declare const EVAL_LIMITS: {
|
|
3
|
+
readonly codeBytes: number;
|
|
4
|
+
readonly frameBytes: number;
|
|
5
|
+
readonly outputBytes: number;
|
|
6
|
+
readonly outputLines: 1000;
|
|
7
|
+
readonly outputWarnBytes: number;
|
|
8
|
+
readonly timeoutMs: 30000;
|
|
9
|
+
readonly maxTimeoutMs: 60000;
|
|
10
|
+
readonly idleMs: number;
|
|
11
|
+
readonly calls: 128;
|
|
12
|
+
readonly concurrency: 8;
|
|
13
|
+
};
|
|
14
|
+
export declare const FRAME_PREFIX = "@typeclaw-eval ";
|
|
15
|
+
export declare class EvalError extends Error {
|
|
16
|
+
readonly kind: 'protocol' | 'closed' | 'timeout' | 'busy' | 'refused' | 'cell';
|
|
17
|
+
readonly name = "EvalError";
|
|
18
|
+
constructor(kind: 'protocol' | 'closed' | 'timeout' | 'busy' | 'refused' | 'cell', message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare function assertNever(value: never): never;
|
|
21
|
+
export declare function encodeFrame(frame: HostFrame | KernelFrame): string;
|
|
22
|
+
export declare class FrameLines {
|
|
23
|
+
private pending;
|
|
24
|
+
push(chunk: Uint8Array): string[];
|
|
25
|
+
}
|
|
26
|
+
export declare class CellOutput {
|
|
27
|
+
private text;
|
|
28
|
+
private bytes;
|
|
29
|
+
private lines;
|
|
30
|
+
truncated: boolean;
|
|
31
|
+
append(text: string): void;
|
|
32
|
+
render(): string;
|
|
33
|
+
}
|
|
@@ -3,6 +3,8 @@ export type GitIdentity = {
|
|
|
3
3
|
email: string;
|
|
4
4
|
};
|
|
5
5
|
export declare function resolveGitIdentity(cwd: string): Promise<GitIdentity | null>;
|
|
6
|
+
export declare function ensureGitIdentity(cwd: string): Promise<GitIdentity | null>;
|
|
7
|
+
export declare function isFallbackGitIdentity(cwd: string, identity: GitIdentity): Promise<boolean>;
|
|
6
8
|
declare function withoutGitOverrides(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
7
9
|
export declare const _internal: {
|
|
8
10
|
withoutGitOverrides: typeof withoutGitOverrides;
|
|
@@ -6,6 +6,7 @@ export type BuildDockerfileOptions = {
|
|
|
6
6
|
baseImageVersion?: string | null;
|
|
7
7
|
cjkFontsAuto?: boolean;
|
|
8
8
|
buildKit?: boolean;
|
|
9
|
+
typevault?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare const CURL_IMPERSONATE_VERSION = "v1.5.6";
|
|
11
12
|
export declare const CURL_IMPERSONATE_SHA256_AMD64 = "b60344f63b9ed8806f0e9f7fd357d9f6c9a82aca279ed1e9e257d544885dcbde";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GitignoreConfig } from "../config/config.js";
|
|
2
2
|
export declare const GITIGNORE_FILE = ".gitignore";
|
|
3
3
|
export declare const TRULY_IGNORED_PATTERNS: readonly [".gitstore/", ".env", ".env.local", "secrets.json", "auth.json", ".typeclaw/", "node_modules/", "packages/*/node_modules/", "workspace/", "public/", "mounts/", "Dockerfile", ".DS_Store"];
|
|
4
|
-
export declare const SYSTEM_MANAGED_ROOTS: readonly ["sessions/", "memory/", "channels/", "todo/", "cron/"];
|
|
4
|
+
export declare const SYSTEM_MANAGED_ROOTS: readonly ["sessions/", "memory/", "channels/", "todo/", "cron/", ".typevault/"];
|
|
5
5
|
export declare function buildGitignore(config?: GitignoreConfig): string;
|
|
@@ -14,6 +14,7 @@ export declare const CORE_PERMISSIONS: {
|
|
|
14
14
|
readonly fsSeePrivate: "fs.see.private";
|
|
15
15
|
readonly fsSeeSecrets: "fs.see.secrets";
|
|
16
16
|
readonly browserShared: "browser.shared";
|
|
17
|
+
readonly vaultUse: "vault.use";
|
|
17
18
|
};
|
|
18
19
|
export declare const OWNER_SECURITY_WILDCARD = "__BUILTIN_OWNER_SECURITY_WILDCARD__";
|
|
19
20
|
export type BuiltinRoleSpec = {
|
|
@@ -23,6 +23,8 @@ export type ToolLogger = {
|
|
|
23
23
|
export type ToolContext = {
|
|
24
24
|
signal: AbortSignal | undefined;
|
|
25
25
|
sessionId: string;
|
|
26
|
+
readonly origin?: SessionOrigin;
|
|
27
|
+
readonly entryId?: string;
|
|
26
28
|
agentDir: string;
|
|
27
29
|
logger: ToolLogger;
|
|
28
30
|
};
|
|
@@ -49,6 +51,7 @@ export type SubagentContext<P = unknown> = {
|
|
|
49
51
|
};
|
|
50
52
|
export type RunSession = (override?: {
|
|
51
53
|
userPrompt?: string;
|
|
54
|
+
systemPrompt?: string;
|
|
52
55
|
onFinalMessage?: (message: string | null) => void;
|
|
53
56
|
}) => Promise<void>;
|
|
54
57
|
export type Subagent<P = unknown> = SubagentShared<P> & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const BROWSER_PROFILE_RELATIVE_DIR = ".typeclaw/browser-profile";
|
|
2
|
-
export declare const RUNTIME_OWNED_SECRET_DIRS: readonly ["workspace/.agent-messenger", ".typeclaw/home", ".typeclaw/logs", ".typeclaw/browser-profile"];
|
|
2
|
+
export declare const RUNTIME_OWNED_SECRET_DIRS: readonly ["workspace/.agent-messenger", ".typeclaw/home", ".typeclaw/logs", ".typeclaw/browser-profile", ".typeclaw/typevault", ".typevault"];
|
|
3
3
|
export declare const OPERATOR_CLI_CREDENTIAL_DIRS: readonly ["workspace/.config/gws", "workspace/.config/agent-messenger"];
|
|
4
|
-
export declare const CANONICAL_AGENT_SECRET_DIRS: readonly ["workspace/.config/gws", "workspace/.config/agent-messenger", "workspace/.agent-messenger", ".typeclaw/home", ".typeclaw/logs", ".typeclaw/browser-profile"];
|
|
4
|
+
export declare const CANONICAL_AGENT_SECRET_DIRS: readonly ["workspace/.config/gws", "workspace/.config/agent-messenger", "workspace/.agent-messenger", ".typeclaw/home", ".typeclaw/logs", ".typeclaw/browser-profile", ".typeclaw/typevault", ".typevault"];
|
|
5
5
|
export declare const CANONICAL_AGENT_SECRET_FILES: readonly [".env", "secrets.json", "auth.json"];
|
|
6
6
|
export declare const CONTAINER_RUNTIME_HOME = "/home/agent";
|
|
7
7
|
export declare const CANONICAL_HOME_SECRET_DIRS: readonly [".ssh", ".config/gh", ".config/gws", ".config/agent-messenger", ".agent-messenger", ".codex", ".claude"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type SandboxedCommand } from "./build.js";
|
|
2
2
|
import { type SandboxPolicy, type SandboxProcStrategy } from "./policy.js";
|
|
3
3
|
export declare const CODING_SOURCE = "/typeclaw-coding-source";
|
|
4
|
-
export declare const CODING_MASK_DIRS: readonly ["workspace/.config/gws", "workspace/.config/agent-messenger", "workspace/.agent-messenger", ".typeclaw/home", ".typeclaw/logs", ".typeclaw/browser-profile", ...(".ssh" | ".config/gh" | ".config/gws" | ".config/agent-messenger" | ".agent-messenger")[], ".typeclaw"];
|
|
4
|
+
export declare const CODING_MASK_DIRS: readonly ["workspace/.config/gws", "workspace/.config/agent-messenger", "workspace/.agent-messenger", ".typeclaw/home", ".typeclaw/logs", ".typeclaw/browser-profile", ".typeclaw/typevault", ".typevault", ...(".ssh" | ".config/gh" | ".config/gws" | ".config/agent-messenger" | ".agent-messenger")[], ".typeclaw"];
|
|
5
5
|
export declare const CODING_MASK_FILES: readonly [".env", "secrets.json", "auth.json", ".gitconfig", ".claude.json", ".netrc", ".typeclaw/incidents.json", ".typeclaw/coding-agent-tasks.json", ".claude/.credentials.json", ".codex/auth.json"];
|
|
6
6
|
export declare function codingSourceMaskDirs(source: string, taskRoot: string): readonly string[];
|
|
7
7
|
export type CodingSandboxOptions = {
|
|
@@ -15,5 +15,6 @@ export declare function reconcileDependencyBinWrappers(options: {
|
|
|
15
15
|
agentDir: string;
|
|
16
16
|
sessionTmp: string;
|
|
17
17
|
baselineDirs?: readonly string[];
|
|
18
|
+
runtimeBins?: Readonly<Record<string, string>>;
|
|
18
19
|
}): Promise<DependencyBinReconciliation>;
|
|
19
20
|
export declare function dependencyBinUnavailableHint(command: string, reconciliation: DependencyBinReconciliation): string | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { SandboxMount } from "./policy.js";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function resolveDevSourceMounts(agentDir: string, moduleFile?: string): Promise<Extract<SandboxMount, {
|
|
3
3
|
type: 'ro-bind';
|
|
4
|
-
}>
|
|
4
|
+
}>[]>;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
+
export declare const SECRET_ENV_PREFIX = "TYPECLAW_SECRET_";
|
|
1
2
|
export declare function resolveExposableEnvNames(declaredEnv: ReadonlyMap<string, string>, runtimeEnv?: Readonly<Record<string, string | undefined>>): string[];
|
|
3
|
+
export declare function resolveFillableEnvNames(declaredEnv: ReadonlyMap<string, string>, runtimeEnv?: Readonly<Record<string, string | undefined>>): string[];
|
|
@@ -6,6 +6,7 @@ export type HiddenPaths = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function resolveHiddenPaths(permissions: PermissionService, origin: SessionOrigin | undefined, agentDir: string): HiddenPaths;
|
|
8
8
|
export declare function canWriteAgentRootInSandbox(permissions: PermissionService, origin: SessionOrigin | undefined): boolean;
|
|
9
|
+
export declare function canSeePrivateSurface(permissions: PermissionService, origin: SessionOrigin | undefined): boolean;
|
|
9
10
|
export declare function ensureHiddenMaskTargets(hidden: HiddenPaths): Promise<HiddenPaths>;
|
|
10
11
|
export declare function verifyHiddenMaskTargets(hidden: HiddenPaths): Promise<void>;
|
|
11
12
|
export declare function rejectHardlinkAliases(root: string, maxEntries?: number): Promise<void>;
|
|
@@ -2,7 +2,7 @@ export { buildSandboxedCommand, type SandboxedCommand } from "./build.js";
|
|
|
2
2
|
export { CANONICAL_AGENT_SECRET_DIRS, CANONICAL_AGENT_SECRET_FILES, CANONICAL_HOME_SECRET_DIRS, CANONICAL_HOME_SECRET_FILES, CONTAINER_RUNTIME_HOME, OPERATOR_CLI_CREDENTIAL_DIRS, RUNTIME_OWNED_SECRET_DIRS, } from "./canonical-secrets.js";
|
|
3
3
|
export { CANONICAL_AGENT_RUNTIME_PRIVATE_FILES } from "./runtime-private.js";
|
|
4
4
|
export { buildProcBindProbeScript, canBindProcSafely, canMountRealProc, ensureBwrapAvailable, getProcBindSafetyVerdict, PROC_BIND_RETRY_BACKOFF_MS, resolveProcBindSafetyWithRetry, resolveProcSelfExe, type ProcBindSafetyVerdict, _resetBwrapAvailabilityCacheForTests, _resetProcBindProbeCacheForTests, _resetRealProcProbeCacheForTests, } from "./availability.js";
|
|
5
|
-
export { canWriteAgentRootInSandbox, ensureHiddenMaskTargets, resolveHiddenPaths, verifyHiddenMaskTargets, type HiddenPaths, } from "./hidden-paths.js";
|
|
5
|
+
export { canSeePrivateSurface, canWriteAgentRootInSandbox, ensureHiddenMaskTargets, resolveHiddenPaths, verifyHiddenMaskTargets, type HiddenPaths, } from "./hidden-paths.js";
|
|
6
6
|
export { resolveProtectedZones, resolveWritableZones, isGitControlPath, subtractMasked, type ProtectedZones, type WritableZones, } from "./writable-zones.js";
|
|
7
7
|
export { resolveSandboxSymlinks, type SandboxSymlinkSpec } from "./symlinks.js";
|
|
8
8
|
export { commandNeedsRealProc } from "./package-install.js";
|
|
@@ -61,6 +61,9 @@ export type SandboxPolicy = {
|
|
|
61
61
|
masks?: SandboxMaskPolicy;
|
|
62
62
|
writable?: SandboxWritablePolicy;
|
|
63
63
|
protected?: SandboxProtectedPolicy;
|
|
64
|
+
reveal?: Extract<SandboxMount, {
|
|
65
|
+
type: 'ro-bind' | 'tmpfs';
|
|
66
|
+
}>[];
|
|
64
67
|
symlinks?: SandboxSymlinkOp[];
|
|
65
68
|
network?: SandboxNetwork;
|
|
66
69
|
env?: SandboxEnvPolicy;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const TYPEVAULT_SECRETS_MARKER: {
|
|
2
|
+
readonly $comment: "TypeClaw keeps this agent's secrets in its TypeVault vault (.typevault/). Set typevault.enabled to false in typeclaw.json and run \"typeclaw restart\" to restore this file.";
|
|
3
|
+
readonly version: "typevault";
|
|
4
|
+
};
|
|
5
|
+
export declare function typevaultMarkerText(): string;
|
|
6
|
+
export declare function isTypevaultMarker(raw: string): boolean;
|
|
7
|
+
export declare function isTypevaultMarkerFile(secretsPath: string): boolean;
|
|
8
|
+
export declare function readEnvelopeTextSync(agentDir: string, fetch?: (agentDir: string) => string): string;
|
|
9
|
+
export declare function writeEnvelopeTextSync(agentDir: string, text: string): void;
|
|
10
|
+
export declare function entriesStamp(agentDir: string): string;
|
|
11
|
+
export declare function runHelperSync(agentDir: string, op: 'read' | 'write', input?: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type TypevaultReconcileResult = {
|
|
2
|
+
action: 'unchanged';
|
|
3
|
+
} | {
|
|
4
|
+
action: 'enabled';
|
|
5
|
+
} | {
|
|
6
|
+
action: 'resumed';
|
|
7
|
+
} | {
|
|
8
|
+
action: 'restored';
|
|
9
|
+
} | {
|
|
10
|
+
action: 'skipped';
|
|
11
|
+
warning: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function reconcileTypevault(agentDir: string, enabled: boolean): Promise<TypevaultReconcileResult>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Access } from 'typevault';
|
|
2
|
+
import { type AdminClient } from 'typevault/admin';
|
|
3
|
+
export declare const TYPEVAULT_VAULT_RELATIVE_DIR = ".typevault";
|
|
4
|
+
export declare const TYPEVAULT_STATE_RELATIVE_DIR = ".typeclaw/typevault";
|
|
5
|
+
export declare const RUNTIME_TIER = "runtime";
|
|
6
|
+
export declare function typevaultDir(agentDir: string): string;
|
|
7
|
+
export declare function vaultExists(agentDir: string): boolean;
|
|
8
|
+
export declare const TYPEVAULT_HOST_ID = "typeclaw-agent";
|
|
9
|
+
export declare function clearLegacyDaemonClaims(agentDir: string): void;
|
|
10
|
+
export declare function typevaultEnv(agentDir: string, base?: NodeJS.ProcessEnv): Record<string, string>;
|
|
11
|
+
export declare function provisionVault(agentDir: string): Promise<void>;
|
|
12
|
+
export declare function readSecretsEntry(agentDir: string): Promise<string | undefined>;
|
|
13
|
+
export declare function requireSecretsEntry(agentDir: string): Promise<string>;
|
|
14
|
+
export declare function writeSecretsEntry(agentDir: string, text: string): Promise<void>;
|
|
15
|
+
export declare const ROLE_TIER_TOWER: readonly ["owner", "trusted", "member", "guest"];
|
|
16
|
+
export declare function isRoleTier(name: string): boolean;
|
|
17
|
+
export declare function ensureRoleTiers(agentDir: string, roles: readonly string[]): Promise<string[]>;
|
|
18
|
+
export declare function vaultAdmin(agentDir: string, options?: {
|
|
19
|
+
promptPort?: number;
|
|
20
|
+
}): AdminClient;
|
|
21
|
+
export declare function grantAccess(agentDir: string, grant: string): Promise<Access>;
|
|
22
|
+
export declare function agentSocketPath(agentDir: string, configRoot: string): string;
|
|
23
|
+
export declare function runtimeConfigRoot(agentDir: string): string;
|
|
24
|
+
export declare function projectIdentityPath(agentDir: string): string;
|
|
25
|
+
export declare function ensureProjectIdentity(agentDir: string, name: string): Promise<void>;
|
|
26
|
+
export declare function projectMemberName(containerName: string | undefined): string;
|
|
27
|
+
export declare function openVault(agentDir: string): Promise<Access>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"homepage": "https://github.com/typeclaw/typeclaw#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/typeclaw/typeclaw/issues"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"format": "oxfmt --write .",
|
|
44
44
|
"format:check": "oxfmt --check .",
|
|
45
45
|
"check": "bun run typecheck && bun run lint && bun run format:check",
|
|
46
|
-
"test": "bun test
|
|
46
|
+
"test": "bun run scripts/test.ts",
|
|
47
47
|
"dev:docs": "cd docs && bun run dev",
|
|
48
48
|
"generate:schema": "bun run scripts/generate-schema.ts",
|
|
49
49
|
"debug:prompt": "bun run scripts/dump-system-prompt.ts",
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@clack/core": "^1.2.0",
|
|
54
54
|
"@clack/prompts": "^1.2.0",
|
|
55
|
-
"@earendil-works/pi-agent-core": "
|
|
56
|
-
"@earendil-works/pi-ai": "
|
|
57
|
-
"@earendil-works/pi-coding-agent": "
|
|
58
|
-
"@earendil-works/pi-tui": "
|
|
55
|
+
"@earendil-works/pi-agent-core": "1.5.0",
|
|
56
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
57
|
+
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
58
|
+
"@earendil-works/pi-tui": "1.5.0",
|
|
59
59
|
"@huggingface/transformers": "4.2.0",
|
|
60
60
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
61
61
|
"@mozilla/readability": "^0.6.0",
|
|
62
|
-
"agent-messenger": "^2.
|
|
62
|
+
"agent-messenger": "^2.43.0",
|
|
63
63
|
"cheerio": "^1.2.0",
|
|
64
64
|
"citty": "^0.2.2",
|
|
65
65
|
"cron-parser": "^5.5.0",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"tough-cookie": "^6.0.2",
|
|
71
71
|
"turndown": "^7.2.4",
|
|
72
72
|
"typebox": "1.3.27",
|
|
73
|
+
"typevault": "0.5.0",
|
|
73
74
|
"zod": "^4.3.6"
|
|
74
75
|
},
|
|
75
76
|
"devDependencies": {
|
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
|
+
}
|