@theokit/sdk 4.19.4 → 4.21.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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * M53 — bubblewrap argv + honest detection, faithful to Codex's Linux sandbox
3
+ * (`codex-rs/linux-sandbox/src/bwrap.rs` + `codex-rs/sandboxing/src/bwrap.rs`).
4
+ *
5
+ * HONEST SCOPE: filesystem confinement + network isolation via bwrap, PLUS the second stage —
6
+ * a cBPF seccomp syscall filter (`agents/sandbox/seccomp.ts`), wired in `agents/sandbox/backend.ts`
7
+ * via `restrictedSeccompPath()`. Portado no M63; este bloco afirmava o contrário até o M67 e
8
+ * SUBDECLARAVA a postura de segurança real. Limite honesto que permanece: o filtro é **x86_64**
9
+ * (guarda de arquitetura recusa instalar em outra arch, com WARN, e o confinamento de FS/rede do
10
+ * bwrap segue valendo) **e** só é instalado quando a rede está restrita (`backend.ts:87`, fiel a
11
+ * `landlock.rs:96-117`): com rede ligada não há filtro de syscall, apenas o confinamento de FS do
12
+ * bwrap. `danger-full-access` pula o bwrap por completo, espelhando `bwrap.rs:245-252`.
13
+ * Deltas versus o Codex seguem documentados em docs/CODEX-PARITY.md.
14
+ */
15
+ /**
16
+ * Os tres modos canonicos do Codex. Definidos AQUI porque sao vocabulario do sandbox, nao da
17
+ * configuracao do consumidor: `danger-full-access` significa "nao embrulhe", e essa e uma decisao do
18
+ * subsistema de confinamento.
19
+ */
20
+ export type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
21
+ export interface BwrapArgvOptions {
22
+ /** Workspace root — the single RW bind under `workspace-write` (protocol.rs:1189-1200). */
23
+ cwd: string;
24
+ /** `true` removes `--unshare-net` (policy `network_access`, default false). */
25
+ network?: boolean;
26
+ /** Injectable for tests; defaults to a real `existsSync` check on `<cwd>/.git`. */
27
+ gitDirExists?: boolean;
28
+ /**
29
+ * When present, emit `--clearenv` and re-inject ONLY these vars (Codex env_clear model,
30
+ * `exec_env.rs:25-31`). Closes the denylist gap: a secret in an oddly-named var never reaches the
31
+ * sandboxed child. Omitted ⇒ inherit the parent env (backward-compatible; SDK scrub still applies).
32
+ */
33
+ env?: Record<string, string>;
34
+ }
35
+ /**
36
+ * Pure argv builder. Returns the bwrap flags ending in `--` (caller appends `/bin/sh -c <cmd>`),
37
+ * or `null` when the policy skips the sandbox entirely (`danger-full-access`).
38
+ */
39
+ export declare function buildBwrapArgv(mode: SandboxMode, opts: BwrapArgvOptions): string[] | null;
40
+ /** Injectable probes — each mirrors one Codex availability check. */
41
+ export interface BwrapProbes {
42
+ /** `which bwrap` outside the cwd (anti-hijack, sandboxing/src/bwrap.rs:168-191). */
43
+ which: () => string | null;
44
+ /** `bwrap --help` text — must advertise `--perms` (launcher.rs:108-124). */
45
+ helpText: (bin: string) => string | null;
46
+ /** Active user-namespace probe with timeout (sandboxing/src/bwrap.rs:74-136). */
47
+ userns: (bin: string) => boolean;
48
+ }
49
+ export type BwrapDetection = {
50
+ ok: true;
51
+ bin: string;
52
+ } | {
53
+ ok: false;
54
+ reason: string;
55
+ };
56
+ /** Honest detection — fail-closed on every probe; NEVER throws (callers WARN + fall back). */
57
+ export declare function detectBwrap(probes?: BwrapProbes): BwrapDetection;
58
+ /** Quantas sondagens reais rodaram. Seam de TESTE — o gate de performance conta isto. */
59
+ export declare function realProbeCount(): number;
60
+ /** Real probes used in production. */
61
+ export declare const realProbes: BwrapProbes;
62
+ /**
63
+ * `detectBwrap` com memoização — o que a produção deve chamar.
64
+ *
65
+ * Note que `detectBwrap` em si **não** memoiza, de propósito: ele aceita probes injetados, e memoizar
66
+ * ali faria um teste com probes falsos envenenar o cache do processo para todos os outros.
67
+ *
68
+ * A revalidação do positivo NÃO é uma re-sondagem: `detectBwrap` gasta três probes (subprocesso
69
+ * `which` + `--help` + namespace de usuário). Aqui só se confirma que o binário validado continua no
70
+ * lugar. Se sumiu, o memo é rebaixado a negativo com o motivo dito — nunca promovido a positivo, que
71
+ * exigiria a sondagem cara de volta.
72
+ */
73
+ export declare function detectBwrapMemoizado(probes?: BwrapProbes): BwrapDetection;
74
+ /** Seam de TESTE — limpa o memo. Produção nunca chama (ver m71-custo-por-turn#ADR-1). */
75
+ export declare function resetBwrapMemo(): void;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * M53 — bubblewrap argv + honest detection, faithful to Codex's Linux sandbox
3
+ * (`codex-rs/linux-sandbox/src/bwrap.rs` + `codex-rs/sandboxing/src/bwrap.rs`).
4
+ *
5
+ * HONEST SCOPE: filesystem confinement + network isolation via bwrap, PLUS the second stage —
6
+ * a cBPF seccomp syscall filter (`agents/sandbox/seccomp.ts`), wired in `agents/sandbox/backend.ts`
7
+ * via `restrictedSeccompPath()`. Portado no M63; este bloco afirmava o contrário até o M67 e
8
+ * SUBDECLARAVA a postura de segurança real. Limite honesto que permanece: o filtro é **x86_64**
9
+ * (guarda de arquitetura recusa instalar em outra arch, com WARN, e o confinamento de FS/rede do
10
+ * bwrap segue valendo) **e** só é instalado quando a rede está restrita (`backend.ts:87`, fiel a
11
+ * `landlock.rs:96-117`): com rede ligada não há filtro de syscall, apenas o confinamento de FS do
12
+ * bwrap. `danger-full-access` pula o bwrap por completo, espelhando `bwrap.rs:245-252`.
13
+ * Deltas versus o Codex seguem documentados em docs/CODEX-PARITY.md.
14
+ */
15
+ /**
16
+ * Os tres modos canonicos do Codex. Definidos AQUI porque sao vocabulario do sandbox, nao da
17
+ * configuracao do consumidor: `danger-full-access` significa "nao embrulhe", e essa e uma decisao do
18
+ * subsistema de confinamento.
19
+ */
20
+ export type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
21
+ export interface BwrapArgvOptions {
22
+ /** Workspace root — the single RW bind under `workspace-write` (protocol.rs:1189-1200). */
23
+ cwd: string;
24
+ /** `true` removes `--unshare-net` (policy `network_access`, default false). */
25
+ network?: boolean;
26
+ /** Injectable for tests; defaults to a real `existsSync` check on `<cwd>/.git`. */
27
+ gitDirExists?: boolean;
28
+ /**
29
+ * When present, emit `--clearenv` and re-inject ONLY these vars (Codex env_clear model,
30
+ * `exec_env.rs:25-31`). Closes the denylist gap: a secret in an oddly-named var never reaches the
31
+ * sandboxed child. Omitted ⇒ inherit the parent env (backward-compatible; SDK scrub still applies).
32
+ */
33
+ env?: Record<string, string>;
34
+ }
35
+ /**
36
+ * Pure argv builder. Returns the bwrap flags ending in `--` (caller appends `/bin/sh -c <cmd>`),
37
+ * or `null` when the policy skips the sandbox entirely (`danger-full-access`).
38
+ */
39
+ export declare function buildBwrapArgv(mode: SandboxMode, opts: BwrapArgvOptions): string[] | null;
40
+ /** Injectable probes — each mirrors one Codex availability check. */
41
+ export interface BwrapProbes {
42
+ /** `which bwrap` outside the cwd (anti-hijack, sandboxing/src/bwrap.rs:168-191). */
43
+ which: () => string | null;
44
+ /** `bwrap --help` text — must advertise `--perms` (launcher.rs:108-124). */
45
+ helpText: (bin: string) => string | null;
46
+ /** Active user-namespace probe with timeout (sandboxing/src/bwrap.rs:74-136). */
47
+ userns: (bin: string) => boolean;
48
+ }
49
+ export type BwrapDetection = {
50
+ ok: true;
51
+ bin: string;
52
+ } | {
53
+ ok: false;
54
+ reason: string;
55
+ };
56
+ /** Honest detection — fail-closed on every probe; NEVER throws (callers WARN + fall back). */
57
+ export declare function detectBwrap(probes?: BwrapProbes): BwrapDetection;
58
+ /** Quantas sondagens reais rodaram. Seam de TESTE — o gate de performance conta isto. */
59
+ export declare function realProbeCount(): number;
60
+ /** Real probes used in production. */
61
+ export declare const realProbes: BwrapProbes;
62
+ /**
63
+ * `detectBwrap` com memoização — o que a produção deve chamar.
64
+ *
65
+ * Note que `detectBwrap` em si **não** memoiza, de propósito: ele aceita probes injetados, e memoizar
66
+ * ali faria um teste com probes falsos envenenar o cache do processo para todos os outros.
67
+ *
68
+ * A revalidação do positivo NÃO é uma re-sondagem: `detectBwrap` gasta três probes (subprocesso
69
+ * `which` + `--help` + namespace de usuário). Aqui só se confirma que o binário validado continua no
70
+ * lugar. Se sumiu, o memo é rebaixado a negativo com o motivo dito — nunca promovido a positivo, que
71
+ * exigiria a sondagem cara de volta.
72
+ */
73
+ export declare function detectBwrapMemoizado(probes?: BwrapProbes): BwrapDetection;
74
+ /** Seam de TESTE — limpa o memo. Produção nunca chama (ver m71-custo-por-turn#ADR-1). */
75
+ export declare function resetBwrapMemo(): void;