apex-code 0.0.6 → 0.1.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/CHANGELOG.md +26 -0
- package/README.md +7 -8
- package/dist/cli/args.d.ts +0 -12
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +2 -32
- package/dist/cli/args.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -130
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +0 -8
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/delegation/agents.d.ts.map +1 -1
- package/dist/core/delegation/agents.js +2 -1
- package/dist/core/delegation/agents.js.map +1 -1
- package/dist/core/delegation/runtime.d.ts +6 -14
- package/dist/core/delegation/runtime.d.ts.map +1 -1
- package/dist/core/delegation/runtime.js +1 -2
- package/dist/core/delegation/runtime.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -4
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/source-runtime.d.ts +4 -5
- package/dist/core/extensions/source-runtime.d.ts.map +1 -1
- package/dist/core/extensions/source-runtime.js +4 -5
- package/dist/core/extensions/source-runtime.js.map +1 -1
- package/dist/core/formatter-lifecycle.d.ts +2 -1
- package/dist/core/formatter-lifecycle.d.ts.map +1 -1
- package/dist/core/formatter-lifecycle.js +2 -1
- package/dist/core/formatter-lifecycle.js.map +1 -1
- package/dist/core/hooks/types.d.ts +2 -3
- package/dist/core/hooks/types.d.ts.map +1 -1
- package/dist/core/hooks/types.js +2 -3
- package/dist/core/hooks/types.js.map +1 -1
- package/dist/core/http-idle-timeout.d.ts +3 -5
- package/dist/core/http-idle-timeout.d.ts.map +1 -1
- package/dist/core/http-idle-timeout.js +3 -5
- package/dist/core/http-idle-timeout.js.map +1 -1
- package/dist/core/mcp/config.d.ts +18 -1
- package/dist/core/mcp/config.d.ts.map +1 -1
- package/dist/core/mcp/config.js +24 -7
- package/dist/core/mcp/config.js.map +1 -1
- package/dist/core/mcp/connector.d.ts +2 -3
- package/dist/core/mcp/connector.d.ts.map +1 -1
- package/dist/core/mcp/connector.js.map +1 -1
- package/dist/core/mcp/oauth/authorize.d.ts +2 -0
- package/dist/core/mcp/oauth/authorize.d.ts.map +1 -1
- package/dist/core/mcp/oauth/authorize.js +5 -2
- package/dist/core/mcp/oauth/authorize.js.map +1 -1
- package/dist/core/mcp/oauth/mcp-token.d.ts +4 -6
- package/dist/core/mcp/oauth/mcp-token.d.ts.map +1 -1
- package/dist/core/mcp/oauth/mcp-token.js +5 -7
- package/dist/core/mcp/oauth/mcp-token.js.map +1 -1
- package/dist/core/mcp/runtime.d.ts +1 -0
- package/dist/core/mcp/runtime.d.ts.map +1 -1
- package/dist/core/mcp/runtime.js +2 -1
- package/dist/core/mcp/runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +0 -15
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permissions/store.d.ts +6 -11
- package/dist/core/permissions/store.d.ts.map +1 -1
- package/dist/core/permissions/store.js +23 -51
- package/dist/core/permissions/store.js.map +1 -1
- package/dist/core/project-resources.d.ts +62 -0
- package/dist/core/project-resources.d.ts.map +1 -0
- package/dist/core/project-resources.js +42 -0
- package/dist/core/project-resources.js.map +1 -0
- package/dist/core/sdk.d.ts +1 -9
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +10 -35
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-share.d.ts +6 -8
- package/dist/core/session-share.d.ts.map +1 -1
- package/dist/core/session-share.js +9 -12
- package/dist/core/session-share.js.map +1 -1
- package/dist/core/settings-manager.d.ts +0 -21
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +4 -12
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +0 -47
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/web-fetch.d.ts.map +1 -1
- package/dist/core/tools/web-fetch.js +4 -8
- package/dist/core/tools/web-fetch.js.map +1 -1
- package/dist/core/tools/web-search-exa.d.ts +3 -6
- package/dist/core/tools/web-search-exa.d.ts.map +1 -1
- package/dist/core/tools/web-search-exa.js +5 -8
- package/dist/core/tools/web-search-exa.js.map +1 -1
- package/dist/core/trust-manager.d.ts +6 -5
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +42 -19
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/web-search-provider.d.ts +0 -10
- package/dist/core/web-search-provider.d.ts.map +1 -1
- package/dist/core/web-search-provider.js +2 -16
- package/dist/core/web-search-provider.js.map +1 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +0 -29
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +1 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +0 -25
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -52
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +0 -2
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +0 -2
- package/dist/utils/version-check.js.map +1 -1
- package/docs/settings.md +2 -7
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
- package/dist/core/sandbox/bwrap-arguments.d.ts +0 -41
- package/dist/core/sandbox/bwrap-arguments.d.ts.map +0 -1
- package/dist/core/sandbox/bwrap-arguments.js +0 -136
- package/dist/core/sandbox/bwrap-arguments.js.map +0 -1
- package/dist/core/sandbox/child-entry.d.ts +0 -2
- package/dist/core/sandbox/child-entry.d.ts.map +0 -1
- package/dist/core/sandbox/child-entry.js +0 -24
- package/dist/core/sandbox/child-entry.js.map +0 -1
- package/dist/core/sandbox/cli-launch.d.ts +0 -162
- package/dist/core/sandbox/cli-launch.d.ts.map +0 -1
- package/dist/core/sandbox/cli-launch.js +0 -366
- package/dist/core/sandbox/cli-launch.js.map +0 -1
- package/dist/core/sandbox/cli-supervisor.d.ts +0 -31
- package/dist/core/sandbox/cli-supervisor.d.ts.map +0 -1
- package/dist/core/sandbox/cli-supervisor.js +0 -147
- package/dist/core/sandbox/cli-supervisor.js.map +0 -1
- package/dist/core/sandbox/default-hosts.d.ts +0 -28
- package/dist/core/sandbox/default-hosts.d.ts.map +0 -1
- package/dist/core/sandbox/default-hosts.js +0 -69
- package/dist/core/sandbox/default-hosts.js.map +0 -1
- package/dist/core/sandbox/full-access.d.ts +0 -28
- package/dist/core/sandbox/full-access.d.ts.map +0 -1
- package/dist/core/sandbox/full-access.js +0 -63
- package/dist/core/sandbox/full-access.js.map +0 -1
- package/dist/core/sandbox/git-identity.d.ts +0 -57
- package/dist/core/sandbox/git-identity.d.ts.map +0 -1
- package/dist/core/sandbox/git-identity.js +0 -78
- package/dist/core/sandbox/git-identity.js.map +0 -1
- package/dist/core/sandbox/host-approval.d.ts +0 -42
- package/dist/core/sandbox/host-approval.d.ts.map +0 -1
- package/dist/core/sandbox/host-approval.js +0 -99
- package/dist/core/sandbox/host-approval.js.map +0 -1
- package/dist/core/sandbox/linux-backend.d.ts +0 -48
- package/dist/core/sandbox/linux-backend.d.ts.map +0 -1
- package/dist/core/sandbox/linux-backend.js +0 -328
- package/dist/core/sandbox/linux-backend.js.map +0 -1
- package/dist/core/sandbox/macos-backend.d.ts +0 -30
- package/dist/core/sandbox/macos-backend.d.ts.map +0 -1
- package/dist/core/sandbox/macos-backend.js +0 -385
- package/dist/core/sandbox/macos-backend.js.map +0 -1
- package/dist/core/sandbox/network-proxy.d.ts +0 -38
- package/dist/core/sandbox/network-proxy.d.ts.map +0 -1
- package/dist/core/sandbox/network-proxy.js +0 -153
- package/dist/core/sandbox/network-proxy.js.map +0 -1
- package/dist/core/sandbox/network-refusal.d.ts +0 -24
- package/dist/core/sandbox/network-refusal.d.ts.map +0 -1
- package/dist/core/sandbox/network-refusal.js +0 -72
- package/dist/core/sandbox/network-refusal.js.map +0 -1
- package/dist/core/sandbox/policy.d.ts +0 -40
- package/dist/core/sandbox/policy.d.ts.map +0 -1
- package/dist/core/sandbox/policy.js +0 -55
- package/dist/core/sandbox/policy.js.map +0 -1
- package/dist/core/sandbox/profiles.d.ts +0 -25
- package/dist/core/sandbox/profiles.d.ts.map +0 -1
- package/dist/core/sandbox/profiles.js +0 -23
- package/dist/core/sandbox/profiles.js.map +0 -1
- package/dist/core/sandbox/rpc/command-client.d.ts +0 -28
- package/dist/core/sandbox/rpc/command-client.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/command-client.js +0 -86
- package/dist/core/sandbox/rpc/command-client.js.map +0 -1
- package/dist/core/sandbox/rpc/command-proxy.d.ts +0 -48
- package/dist/core/sandbox/rpc/command-proxy.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/command-proxy.js +0 -120
- package/dist/core/sandbox/rpc/command-proxy.js.map +0 -1
- package/dist/core/sandbox/rpc/credential-client.d.ts +0 -20
- package/dist/core/sandbox/rpc/credential-client.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/credential-client.js +0 -170
- package/dist/core/sandbox/rpc/credential-client.js.map +0 -1
- package/dist/core/sandbox/rpc/credential-proxy.d.ts +0 -44
- package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/credential-proxy.js +0 -287
- package/dist/core/sandbox/rpc/credential-proxy.js.map +0 -1
- package/dist/core/sandbox/rpc/framing.d.ts +0 -35
- package/dist/core/sandbox/rpc/framing.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/framing.js +0 -114
- package/dist/core/sandbox/rpc/framing.js.map +0 -1
- package/dist/core/sandbox/rpc/git-credential-helper.d.ts +0 -47
- package/dist/core/sandbox/rpc/git-credential-helper.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/git-credential-helper.js +0 -222
- package/dist/core/sandbox/rpc/git-credential-helper.js.map +0 -1
- package/dist/core/sandbox/rpc/git-credential-proxy.d.ts +0 -66
- package/dist/core/sandbox/rpc/git-credential-proxy.d.ts.map +0 -1
- package/dist/core/sandbox/rpc/git-credential-proxy.js +0 -209
- package/dist/core/sandbox/rpc/git-credential-proxy.js.map +0 -1
- package/dist/core/sandbox/supervisor-temp.d.ts +0 -18
- package/dist/core/sandbox/supervisor-temp.d.ts.map +0 -1
- package/dist/core/sandbox/supervisor-temp.js +0 -21
- package/dist/core/sandbox/supervisor-temp.js.map +0 -1
- package/dist/core/sandbox/supervisor.d.ts +0 -62
- package/dist/core/sandbox/supervisor.d.ts.map +0 -1
- package/dist/core/sandbox/supervisor.js +0 -32
- package/dist/core/sandbox/supervisor.js.map +0 -1
- package/dist/core/sandbox/terminal-handoff.d.ts +0 -68
- package/dist/core/sandbox/terminal-handoff.d.ts.map +0 -1
- package/dist/core/sandbox/terminal-handoff.js +0 -221
- package/dist/core/sandbox/terminal-handoff.js.map +0 -1
- package/dist/core/sandbox/terminal-size.d.ts +0 -53
- package/dist/core/sandbox/terminal-size.d.ts.map +0 -1
- package/dist/core/sandbox/terminal-size.js +0 -126
- package/dist/core/sandbox/terminal-size.js.map +0 -1
- package/dist/core/sandbox/violations.d.ts +0 -23
- package/dist/core/sandbox/violations.d.ts.map +0 -1
- package/dist/core/sandbox/violations.js +0 -30
- package/dist/core/sandbox/violations.js.map +0 -1
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { closeSync, constants, openSync, readFileSync, watch, writeFileSync } from "node:fs";
|
|
2
|
-
/**
|
|
3
|
-
* Carries the host terminal's size across the sandbox boundary.
|
|
4
|
-
*
|
|
5
|
-
* The sandboxed child runs under `bwrap --new-session`, so it has no
|
|
6
|
-
* controlling terminal: the kernel never sends it SIGWINCH, and the window size
|
|
7
|
-
* its stdout reports is frozen at whatever it was when the sandbox was created.
|
|
8
|
-
* Everything downstream reads `process.stdout.columns`, so a resize left the TUI
|
|
9
|
-
* rendering to a width the terminal no longer had.
|
|
10
|
-
*
|
|
11
|
-
* The supervisor owns a real TTY and does get the resize event. It publishes the
|
|
12
|
-
* new size to a file inside the workspace, which is already bind-mounted into
|
|
13
|
-
* the sandbox; the child watches that file and republishes it as a `resize` on
|
|
14
|
-
* its own stdout. Signals are deliberately not used as the transport: bwrap sits
|
|
15
|
-
* between the two processes as PID 1 and does not forward SIGWINCH.
|
|
16
|
-
*/
|
|
17
|
-
/** Env var naming the file both sides agree on. */
|
|
18
|
-
export const TERMINAL_SIZE_PATH_VARIABLE = "APEX_TERMINAL_SIZE_PATH";
|
|
19
|
-
/**
|
|
20
|
-
* Write without following a symlink at the final path component.
|
|
21
|
-
*
|
|
22
|
-
* Shared with `terminal-handoff.ts`, which took its transport from this file and inherits
|
|
23
|
-
* the same exposure: every file here is written by the supervisor, on the host, at a path
|
|
24
|
-
* the contained side may be able to create an entry at. A link planted there would
|
|
25
|
-
* redirect a host write the child could not otherwise make -- the audit demonstrated this
|
|
26
|
-
* against the workspace state directory. `O_NOFOLLOW` refuses instead.
|
|
27
|
-
*
|
|
28
|
-
* Node exposes no `openat`, so this guards the final component only; the containing
|
|
29
|
-
* directory must be one the child cannot write for the guarantee to be complete.
|
|
30
|
-
*/
|
|
31
|
-
export function writeWithoutFollowingLinks(path, contents) {
|
|
32
|
-
const descriptor = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC | constants.O_NOFOLLOW, 0o600);
|
|
33
|
-
try {
|
|
34
|
-
writeFileSync(descriptor, contents);
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
closeSync(descriptor);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function formatSize(size) {
|
|
41
|
-
return `${size.columns} ${size.rows}\n`;
|
|
42
|
-
}
|
|
43
|
-
export function parseTerminalSize(contents) {
|
|
44
|
-
const [columns, rows] = contents.trim().split(/\s+/).map(Number);
|
|
45
|
-
if (!Number.isInteger(columns) || !Number.isInteger(rows))
|
|
46
|
-
return undefined;
|
|
47
|
-
if (columns <= 0 || rows <= 0)
|
|
48
|
-
return undefined;
|
|
49
|
-
return { columns, rows };
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Host side. Publishes the current size, then republishes on every resize.
|
|
53
|
-
* Returns a stop function; the caller must run it on every launch exit path.
|
|
54
|
-
*/
|
|
55
|
-
export function publishTerminalSize(path, stdout = process.stdout) {
|
|
56
|
-
if (!stdout.isTTY)
|
|
57
|
-
return () => { };
|
|
58
|
-
const write = () => {
|
|
59
|
-
const columns = stdout.columns;
|
|
60
|
-
const rows = stdout.rows;
|
|
61
|
-
if (!Number.isInteger(columns) || !Number.isInteger(rows))
|
|
62
|
-
return;
|
|
63
|
-
try {
|
|
64
|
-
writeWithoutFollowingLinks(path, formatSize({ columns, rows }));
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// A size we cannot publish is not worth failing a launch over.
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
write();
|
|
71
|
-
stdout.on("resize", write);
|
|
72
|
-
return () => {
|
|
73
|
-
stdout.off("resize", write);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Child side. Applies the published size to `process.stdout` and keeps applying
|
|
78
|
-
* it as the file changes.
|
|
79
|
-
*
|
|
80
|
-
* `columns` and `rows` are redefined as getters because Node recomputes them
|
|
81
|
-
* from the sandbox's own console on SIGWINCH, which is exactly the stale value
|
|
82
|
-
* this exists to override. The setters swallow those writes rather than throwing.
|
|
83
|
-
*/
|
|
84
|
-
export function applyTerminalSize(path, stdout = process.stdout) {
|
|
85
|
-
let current;
|
|
86
|
-
const refresh = () => {
|
|
87
|
-
let size;
|
|
88
|
-
try {
|
|
89
|
-
size = parseTerminalSize(readFileSync(path, "utf8"));
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (!size)
|
|
95
|
-
return;
|
|
96
|
-
if (current && current.columns === size.columns && current.rows === size.rows)
|
|
97
|
-
return;
|
|
98
|
-
current = size;
|
|
99
|
-
Object.defineProperty(stdout, "columns", {
|
|
100
|
-
configurable: true,
|
|
101
|
-
get: () => current?.columns,
|
|
102
|
-
set: () => { },
|
|
103
|
-
});
|
|
104
|
-
Object.defineProperty(stdout, "rows", {
|
|
105
|
-
configurable: true,
|
|
106
|
-
get: () => current?.rows,
|
|
107
|
-
set: () => { },
|
|
108
|
-
});
|
|
109
|
-
stdout.emit("resize");
|
|
110
|
-
};
|
|
111
|
-
refresh();
|
|
112
|
-
let watcher;
|
|
113
|
-
try {
|
|
114
|
-
watcher = watch(path, refresh);
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
// Without a watcher the initial size still applies; only live resize is lost.
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
refresh,
|
|
121
|
-
stop: () => {
|
|
122
|
-
watcher?.close();
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=terminal-size.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-size.js","sourceRoot":"","sources":["../../../src/core/sandbox/terminal-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAkB,QAAQ,EAAE,YAAY,EAAE,KAA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ACf,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE;YACxC,YAAY,EAAE,IAAI;YAClB,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO;YAC3B,GAAG,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;SACb,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE;YACrC,YAAY,EAAE,IAAI;YAClB,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI;YACxB,GAAG,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;SACb,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAAA,CACtB,CAAC;IAEF,OAAO,EAAE,CAAC;IAEV,IAAI,OAA8B,CAAC;IACnC,IAAI,CAAC;QACJ,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACR,8EAA8E;IAC/E,CAAC;IAED,OAAO;QACN,OAAO;QACP,IAAI,EAAE,GAAG,EAAE,CAAC;YACX,OAAO,EAAE,KAAK,EAAE,CAAC;QAAA,CACjB;KACD,CAAC;AAAA,CACF","sourcesContent":["import { closeSync, constants, type FSWatcher, openSync, readFileSync, watch, writeFileSync } from \"node:fs\";\n\n/**\n * Carries the host terminal's size across the sandbox boundary.\n *\n * The sandboxed child runs under `bwrap --new-session`, so it has no\n * controlling terminal: the kernel never sends it SIGWINCH, and the window size\n * its stdout reports is frozen at whatever it was when the sandbox was created.\n * Everything downstream reads `process.stdout.columns`, so a resize left the TUI\n * rendering to a width the terminal no longer had.\n *\n * The supervisor owns a real TTY and does get the resize event. It publishes the\n * new size to a file inside the workspace, which is already bind-mounted into\n * the sandbox; the child watches that file and republishes it as a `resize` on\n * its own stdout. Signals are deliberately not used as the transport: bwrap sits\n * between the two processes as PID 1 and does not forward SIGWINCH.\n */\n\n/** Env var naming the file both sides agree on. */\nexport const TERMINAL_SIZE_PATH_VARIABLE = \"APEX_TERMINAL_SIZE_PATH\";\n\n/**\n * Write without following a symlink at the final path component.\n *\n * Shared with `terminal-handoff.ts`, which took its transport from this file and inherits\n * the same exposure: every file here is written by the supervisor, on the host, at a path\n * the contained side may be able to create an entry at. A link planted there would\n * redirect a host write the child could not otherwise make -- the audit demonstrated this\n * against the workspace state directory. `O_NOFOLLOW` refuses instead.\n *\n * Node exposes no `openat`, so this guards the final component only; the containing\n * directory must be one the child cannot write for the guarantee to be complete.\n */\nexport function writeWithoutFollowingLinks(path: string, contents: string): void {\n\tconst descriptor = openSync(\n\t\tpath,\n\t\tconstants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC | constants.O_NOFOLLOW,\n\t\t0o600,\n\t);\n\ttry {\n\t\twriteFileSync(descriptor, contents);\n\t} finally {\n\t\tcloseSync(descriptor);\n\t}\n}\n\nexport interface TerminalSize {\n\tcolumns: number;\n\trows: number;\n}\n\nfunction formatSize(size: TerminalSize): string {\n\treturn `${size.columns} ${size.rows}\\n`;\n}\n\nexport function parseTerminalSize(contents: string): TerminalSize | undefined {\n\tconst [columns, rows] = contents.trim().split(/\\s+/).map(Number);\n\tif (!Number.isInteger(columns) || !Number.isInteger(rows)) return undefined;\n\tif (columns <= 0 || rows <= 0) return undefined;\n\treturn { columns, rows };\n}\n\n/**\n * Host side. Publishes the current size, then republishes on every resize.\n * Returns a stop function; the caller must run it on every launch exit path.\n */\nexport function publishTerminalSize(path: string, stdout: NodeJS.WriteStream = process.stdout): () => void {\n\tif (!stdout.isTTY) return () => {};\n\n\tconst write = () => {\n\t\tconst columns = stdout.columns;\n\t\tconst rows = stdout.rows;\n\t\tif (!Number.isInteger(columns) || !Number.isInteger(rows)) return;\n\t\ttry {\n\t\t\twriteWithoutFollowingLinks(path, formatSize({ columns, rows }));\n\t\t} catch {\n\t\t\t// A size we cannot publish is not worth failing a launch over.\n\t\t}\n\t};\n\n\twrite();\n\tstdout.on(\"resize\", write);\n\treturn () => {\n\t\tstdout.off(\"resize\", write);\n\t};\n}\n\n/**\n * Child side. Applies the published size to `process.stdout` and keeps applying\n * it as the file changes.\n *\n * `columns` and `rows` are redefined as getters because Node recomputes them\n * from the sandbox's own console on SIGWINCH, which is exactly the stale value\n * this exists to override. The setters swallow those writes rather than throwing.\n */\nexport function applyTerminalSize(\n\tpath: string,\n\tstdout: NodeJS.WriteStream = process.stdout,\n): { stop: () => void; refresh: () => void } {\n\tlet current: TerminalSize | undefined;\n\n\tconst refresh = () => {\n\t\tlet size: TerminalSize | undefined;\n\t\ttry {\n\t\t\tsize = parseTerminalSize(readFileSync(path, \"utf8\"));\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!size) return;\n\t\tif (current && current.columns === size.columns && current.rows === size.rows) return;\n\t\tcurrent = size;\n\t\tObject.defineProperty(stdout, \"columns\", {\n\t\t\tconfigurable: true,\n\t\t\tget: () => current?.columns,\n\t\t\tset: () => {},\n\t\t});\n\t\tObject.defineProperty(stdout, \"rows\", {\n\t\t\tconfigurable: true,\n\t\t\tget: () => current?.rows,\n\t\t\tset: () => {},\n\t\t});\n\t\tstdout.emit(\"resize\");\n\t};\n\n\trefresh();\n\n\tlet watcher: FSWatcher | undefined;\n\ttry {\n\t\twatcher = watch(path, refresh);\n\t} catch {\n\t\t// Without a watcher the initial size still applies; only live resize is lost.\n\t}\n\n\treturn {\n\t\trefresh,\n\t\tstop: () => {\n\t\t\twatcher?.close();\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type SandboxViolationKind = "filesystem" | "network" | "unknown";
|
|
2
|
-
export interface SandboxViolation {
|
|
3
|
-
readonly kind: SandboxViolationKind;
|
|
4
|
-
readonly command: string;
|
|
5
|
-
readonly detail: string;
|
|
6
|
-
readonly timestamp: Date;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Apex-owned bounded violation tail. It intentionally does not depend on a platform
|
|
10
|
-
* runtime's monitor, because Linux does not provide that monitor consistently.
|
|
11
|
-
*/
|
|
12
|
-
export declare class SandboxViolationStore {
|
|
13
|
-
private readonly capacity;
|
|
14
|
-
private readonly violations;
|
|
15
|
-
private _totalCount;
|
|
16
|
-
constructor(options?: {
|
|
17
|
-
capacity?: number;
|
|
18
|
-
});
|
|
19
|
-
get totalCount(): number;
|
|
20
|
-
add(violation: SandboxViolation): void;
|
|
21
|
-
list(): readonly SandboxViolation[];
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=violations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"violations.d.ts","sourceRoot":"","sources":["../../../src/core/sandbox/violations.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CACzB;AAED;;;GAGG;AACH,qBAAa,qBAAqB;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IACrD,OAAO,CAAC,WAAW,CAAK;IAExB,YAAY,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAM1C;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,GAAG,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAMrC;IAED,IAAI,IAAI,SAAS,gBAAgB,EAAE,CAElC;CACD","sourcesContent":["export type SandboxViolationKind = \"filesystem\" | \"network\" | \"unknown\";\n\nexport interface SandboxViolation {\n\treadonly kind: SandboxViolationKind;\n\treadonly command: string;\n\treadonly detail: string;\n\treadonly timestamp: Date;\n}\n\n/**\n * Apex-owned bounded violation tail. It intentionally does not depend on a platform\n * runtime's monitor, because Linux does not provide that monitor consistently.\n */\nexport class SandboxViolationStore {\n\tprivate readonly capacity: number;\n\tprivate readonly violations: SandboxViolation[] = [];\n\tprivate _totalCount = 0;\n\n\tconstructor(options?: { capacity?: number }) {\n\t\tconst capacity = options?.capacity ?? 100;\n\t\tif (!Number.isSafeInteger(capacity) || capacity < 1) {\n\t\t\tthrow new Error(\"Sandbox violation capacity must be a positive safe integer.\");\n\t\t}\n\t\tthis.capacity = capacity;\n\t}\n\n\tget totalCount(): number {\n\t\treturn this._totalCount;\n\t}\n\n\tadd(violation: SandboxViolation): void {\n\t\tthis._totalCount += 1;\n\t\tthis.violations.push(violation);\n\t\tif (this.violations.length > this.capacity) {\n\t\t\tthis.violations.splice(0, this.violations.length - this.capacity);\n\t\t}\n\t}\n\n\tlist(): readonly SandboxViolation[] {\n\t\treturn [...this.violations];\n\t}\n}\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Apex-owned bounded violation tail. It intentionally does not depend on a platform
|
|
3
|
-
* runtime's monitor, because Linux does not provide that monitor consistently.
|
|
4
|
-
*/
|
|
5
|
-
export class SandboxViolationStore {
|
|
6
|
-
capacity;
|
|
7
|
-
violations = [];
|
|
8
|
-
_totalCount = 0;
|
|
9
|
-
constructor(options) {
|
|
10
|
-
const capacity = options?.capacity ?? 100;
|
|
11
|
-
if (!Number.isSafeInteger(capacity) || capacity < 1) {
|
|
12
|
-
throw new Error("Sandbox violation capacity must be a positive safe integer.");
|
|
13
|
-
}
|
|
14
|
-
this.capacity = capacity;
|
|
15
|
-
}
|
|
16
|
-
get totalCount() {
|
|
17
|
-
return this._totalCount;
|
|
18
|
-
}
|
|
19
|
-
add(violation) {
|
|
20
|
-
this._totalCount += 1;
|
|
21
|
-
this.violations.push(violation);
|
|
22
|
-
if (this.violations.length > this.capacity) {
|
|
23
|
-
this.violations.splice(0, this.violations.length - this.capacity);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
list() {
|
|
27
|
-
return [...this.violations];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=violations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"violations.js","sourceRoot":"","sources":["../../../src/core/sandbox/violations.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAChB,QAAQ,CAAS;IACjB,UAAU,GAAuB,EAAE,CAAC;IAC7C,WAAW,GAAG,CAAC,CAAC;IAExB,YAAY,OAA+B,EAAE;QAC5C,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,GAAG,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAAA,CACzB;IAED,IAAI,UAAU,GAAW;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC;IAAA,CACxB;IAED,GAAG,CAAC,SAA2B,EAAQ;QACtC,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnE,CAAC;IAAA,CACD;IAED,IAAI,GAAgC;QACnC,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAAA,CAC5B;CACD","sourcesContent":["export type SandboxViolationKind = \"filesystem\" | \"network\" | \"unknown\";\n\nexport interface SandboxViolation {\n\treadonly kind: SandboxViolationKind;\n\treadonly command: string;\n\treadonly detail: string;\n\treadonly timestamp: Date;\n}\n\n/**\n * Apex-owned bounded violation tail. It intentionally does not depend on a platform\n * runtime's monitor, because Linux does not provide that monitor consistently.\n */\nexport class SandboxViolationStore {\n\tprivate readonly capacity: number;\n\tprivate readonly violations: SandboxViolation[] = [];\n\tprivate _totalCount = 0;\n\n\tconstructor(options?: { capacity?: number }) {\n\t\tconst capacity = options?.capacity ?? 100;\n\t\tif (!Number.isSafeInteger(capacity) || capacity < 1) {\n\t\t\tthrow new Error(\"Sandbox violation capacity must be a positive safe integer.\");\n\t\t}\n\t\tthis.capacity = capacity;\n\t}\n\n\tget totalCount(): number {\n\t\treturn this._totalCount;\n\t}\n\n\tadd(violation: SandboxViolation): void {\n\t\tthis._totalCount += 1;\n\t\tthis.violations.push(violation);\n\t\tif (this.violations.length > this.capacity) {\n\t\t\tthis.violations.splice(0, this.violations.length - this.capacity);\n\t\t}\n\t}\n\n\tlist(): readonly SandboxViolation[] {\n\t\treturn [...this.violations];\n\t}\n}\n"]}
|