polygram 0.27.1 → 0.28.1
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/.claude-plugin/plugin.json +1 -1
- package/config.example.json +2 -2
- package/lib/codex/binary.js +60 -41
- package/lib/codex/diagnostics.js +115 -16
- package/lib/codex/host-identity.js +66 -4
- package/lib/codex/runtime-profile.js +121 -33
- package/lib/handlers/config-ui.js +1 -1
- package/lib/process/claude-environment.js +29 -0
- package/lib/prompt.js +1 -1
- package/ops/README.md +52 -8
- package/package.json +2 -2
- package/polygram.js +5 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "polygram",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.1",
|
|
5
5
|
"description": "Telegram integration for Claude Code that preserves the OpenClaw per-chat session model. Migration target for OpenClaw users. Multi-bot, multi-chat, per-topic isolation; SQLite transcripts; inline-keyboard approvals. Bundles /polygram:status|logs|pair-code|approvals admin commands plus history (transcript queries) and polygram-send (out-of-turn IPC sends with file-upload validation) skills.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"telegram",
|
package/config.example.json
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
"codex": {
|
|
67
|
-
"_comment": "Optional native macOS Codex app-server beta. Codex stays disabled unless a chat/topic explicitly sets pm:'codex' and exact startup preflight succeeds
|
|
67
|
+
"_comment": "Optional native macOS arm64 or Linux x64 Codex app-server beta. Codex stays disabled unless a chat/topic explicitly sets pm:'codex' and exact target-specific startup preflight succeeds; other host targets, including Windows, are rejected. `home` must be a dedicated non-temporary 0700 CODEX_HOME already authenticated with ChatGPT; polygram never copies or reads credential contents. `binary` must be the canonical immutable path to the reviewed target's pinned Codex CLI, not a PATH symlink. On Linux set POLYGRAM_CODEX_TMPDIR to an owner-only 0700 runtime directory; otherwise Codex inherits the daemon TMPDIR after the same safety checks. Every directory containing daemon credentials or control data must be listed in daemonSecretRoots and must not overlap a Codex workspace or CODEX_HOME. Command network and model-native web search are disabled; product MCP tools and interactive approvals are unavailable. Keep long-running commands in the foreground. Detached/background servers are unsupported and may survive hard runtime loss.",
|
|
68
68
|
"home": "/Users/you/.codex-polygram",
|
|
69
69
|
"binary": "/Users/you/.local/share/codex/versions/0.145.0/codex",
|
|
70
70
|
"daemonSecretRoots": [
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"987654321": {
|
|
92
92
|
"name": "Codex beta DM",
|
|
93
93
|
"bot": "admin-bot",
|
|
94
|
-
"_comment_pm": "Codex uses the pinned app-server SDK surface directly (no tmux). Native macOS beta
|
|
94
|
+
"_comment_pm": "Codex uses the pinned app-server SDK surface directly (no tmux). Native macOS arm64 and Linux x64 beta: command network and model-native web search are disabled; product MCP tools and interactive approvals are unavailable; long-running commands must stay in the foreground; detached/background servers are unsupported and may survive hard runtime loss. The model and effort are accepted only when returned by this deployment's authenticated ChatGPT-backed model catalog.",
|
|
95
95
|
"pm": "codex",
|
|
96
96
|
"codexModel": "gpt-5.6-sol",
|
|
97
97
|
"codexEffort": "xhigh",
|
package/lib/codex/binary.js
CHANGED
|
@@ -11,9 +11,8 @@ const {
|
|
|
11
11
|
const path = require('node:path');
|
|
12
12
|
const { promisify } = require('node:util');
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
'1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590';
|
|
14
|
+
const { resolveCodexTargetPin } = require('@shumkov/orchestra');
|
|
15
|
+
|
|
17
16
|
const CONTROLLED_PATH = '/usr/bin:/bin';
|
|
18
17
|
const SHA256_RE = /^[a-f0-9]{64}$/;
|
|
19
18
|
const VERSION_PROBE_TIMEOUT_MS = 10_000;
|
|
@@ -36,7 +35,7 @@ function deepFreeze(value) {
|
|
|
36
35
|
return Object.freeze(value);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
function binaryAction(version
|
|
38
|
+
function binaryAction(version) {
|
|
40
39
|
return (
|
|
41
40
|
`Install ${version} as an immutable versioned executable and set `
|
|
42
41
|
+ 'POLYGRAM_CODEX_BIN to its canonical absolute path.'
|
|
@@ -52,12 +51,13 @@ function fail(message, code, version, cause) {
|
|
|
52
51
|
);
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
function fingerprint(binary) {
|
|
54
|
+
function fingerprint(binary, cliVersion) {
|
|
56
55
|
const stat = statSync(binary, { bigint: true });
|
|
57
56
|
if (!stat.isFile()) {
|
|
58
57
|
throw fail(
|
|
59
58
|
'Pinned Codex binary is not a regular file.',
|
|
60
59
|
'CODEX_BINARY_MISMATCH',
|
|
60
|
+
cliVersion,
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
return {
|
|
@@ -87,14 +87,16 @@ async function hashFile(binary) {
|
|
|
87
87
|
return hash.digest('hex');
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
function validatePin(cliVersion, binarySha256) {
|
|
90
|
+
function validatePin({ target, cliVersion, binarySha256 }) {
|
|
91
91
|
if (
|
|
92
|
-
typeof
|
|
92
|
+
typeof target !== 'string'
|
|
93
|
+
|| target.length === 0
|
|
94
|
+
|| typeof cliVersion !== 'string'
|
|
93
95
|
|| cliVersion.length === 0
|
|
94
96
|
|| !SHA256_RE.test(binarySha256)
|
|
95
97
|
) {
|
|
96
98
|
throw new TypeError(
|
|
97
|
-
'Pinned Codex resolver requires an exact version and lowercase SHA-256.',
|
|
99
|
+
'Pinned Codex resolver requires an exact target, version, and lowercase SHA-256.',
|
|
98
100
|
);
|
|
99
101
|
}
|
|
100
102
|
}
|
|
@@ -102,40 +104,61 @@ function validatePin(cliVersion, binarySha256) {
|
|
|
102
104
|
function createPinnedCodexBinaryResolver({
|
|
103
105
|
cliVersion,
|
|
104
106
|
binarySha256,
|
|
107
|
+
resolveTargetPin = resolveCodexTargetPin,
|
|
105
108
|
execFileFn = promisify(execFile),
|
|
106
109
|
platform = process.platform,
|
|
110
|
+
arch = process.arch,
|
|
107
111
|
getuid = process.getuid?.bind(process),
|
|
108
112
|
} = {}) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
if ((cliVersion === undefined) !== (binarySha256 === undefined)) {
|
|
114
|
+
throw new TypeError(
|
|
115
|
+
'Pinned Codex resolver fixture version and SHA-256 must be supplied together.',
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (typeof resolveTargetPin !== 'function' || typeof execFileFn !== 'function') {
|
|
119
|
+
throw new TypeError(
|
|
120
|
+
'Pinned Codex resolver requires target and process resolver functions.',
|
|
121
|
+
);
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
return async function resolve({
|
|
115
125
|
binaryPath,
|
|
116
126
|
env = process.env,
|
|
117
127
|
} = {}) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
let reviewedPin;
|
|
129
|
+
try {
|
|
130
|
+
reviewedPin = resolveTargetPin(platform, arch);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error?.code === 'CODEX_UNSUPPORTED_PLATFORM') {
|
|
133
|
+
throw new CodexBinaryError(
|
|
134
|
+
'The native Codex beta does not support this host target.',
|
|
135
|
+
'CODEX_BINARY_PLATFORM_UNSUPPORTED',
|
|
136
|
+
'Use a reviewed macOS arm64 or Linux x64 host.',
|
|
137
|
+
{ cause: error },
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
124
141
|
}
|
|
142
|
+
const pin = {
|
|
143
|
+
target: reviewedPin?.target,
|
|
144
|
+
cliVersion: cliVersion ?? reviewedPin?.cliVersion,
|
|
145
|
+
binarySha256: binarySha256 ?? reviewedPin?.binarySha256,
|
|
146
|
+
};
|
|
147
|
+
validatePin(pin);
|
|
125
148
|
|
|
126
149
|
const configured = binaryPath ?? env?.POLYGRAM_CODEX_BIN;
|
|
127
150
|
if (typeof configured !== 'string' || configured.length === 0) {
|
|
128
151
|
throw new CodexBinaryError(
|
|
129
152
|
'Pinned Codex binary is not configured.',
|
|
130
153
|
'CODEX_BINARY_NOT_CONFIGURED',
|
|
131
|
-
binaryAction(cliVersion),
|
|
154
|
+
binaryAction(pin.cliVersion),
|
|
132
155
|
);
|
|
133
156
|
}
|
|
134
157
|
if (!path.isAbsolute(configured)) {
|
|
135
158
|
throw fail(
|
|
136
159
|
'Pinned Codex binary must be an absolute path; PATH lookup is disabled.',
|
|
137
160
|
'CODEX_BINARY_NOT_ABSOLUTE',
|
|
138
|
-
cliVersion,
|
|
161
|
+
pin.cliVersion,
|
|
139
162
|
);
|
|
140
163
|
}
|
|
141
164
|
|
|
@@ -147,14 +170,14 @@ function createPinnedCodexBinaryResolver({
|
|
|
147
170
|
throw fail(
|
|
148
171
|
'Pinned Codex binary is missing.',
|
|
149
172
|
'CODEX_BINARY_MISSING',
|
|
150
|
-
cliVersion,
|
|
173
|
+
pin.cliVersion,
|
|
151
174
|
error,
|
|
152
175
|
);
|
|
153
176
|
}
|
|
154
177
|
throw fail(
|
|
155
178
|
'Pinned Codex binary could not be resolved safely.',
|
|
156
179
|
'CODEX_BINARY_MISMATCH',
|
|
157
|
-
cliVersion,
|
|
180
|
+
pin.cliVersion,
|
|
158
181
|
error,
|
|
159
182
|
);
|
|
160
183
|
}
|
|
@@ -162,7 +185,7 @@ function createPinnedCodexBinaryResolver({
|
|
|
162
185
|
throw fail(
|
|
163
186
|
'Pinned Codex binary path must be canonical and must not be a symlink.',
|
|
164
187
|
'CODEX_BINARY_MISMATCH',
|
|
165
|
-
cliVersion,
|
|
188
|
+
pin.cliVersion,
|
|
166
189
|
);
|
|
167
190
|
}
|
|
168
191
|
|
|
@@ -182,12 +205,12 @@ function createPinnedCodexBinaryResolver({
|
|
|
182
205
|
throw fail(
|
|
183
206
|
'Pinned Codex binary path ownership or mode is unsafe.',
|
|
184
207
|
'CODEX_BINARY_MISMATCH',
|
|
185
|
-
cliVersion,
|
|
208
|
+
pin.cliVersion,
|
|
186
209
|
);
|
|
187
210
|
}
|
|
188
211
|
}
|
|
189
212
|
|
|
190
|
-
const before = fingerprint(canonical);
|
|
213
|
+
const before = fingerprint(canonical, pin.cliVersion);
|
|
191
214
|
if (
|
|
192
215
|
(before.mode & 0o022) !== 0
|
|
193
216
|
|| (before.mode & 0o111) === 0
|
|
@@ -197,16 +220,16 @@ function createPinnedCodexBinaryResolver({
|
|
|
197
220
|
throw fail(
|
|
198
221
|
'Pinned Codex binary ownership or mode is unsafe.',
|
|
199
222
|
'CODEX_BINARY_MISMATCH',
|
|
200
|
-
cliVersion,
|
|
223
|
+
pin.cliVersion,
|
|
201
224
|
);
|
|
202
225
|
}
|
|
203
226
|
|
|
204
227
|
const actualSha256 = await hashFile(canonical);
|
|
205
|
-
if (actualSha256 !== binarySha256) {
|
|
228
|
+
if (actualSha256 !== pin.binarySha256) {
|
|
206
229
|
throw fail(
|
|
207
230
|
'Pinned Codex binary checksum does not match the reviewed runtime.',
|
|
208
231
|
'CODEX_BINARY_MISMATCH',
|
|
209
|
-
cliVersion,
|
|
232
|
+
pin.cliVersion,
|
|
210
233
|
);
|
|
211
234
|
}
|
|
212
235
|
|
|
@@ -222,32 +245,33 @@ function createPinnedCodexBinaryResolver({
|
|
|
222
245
|
throw fail(
|
|
223
246
|
'Pinned Codex binary version probe failed.',
|
|
224
247
|
'CODEX_BINARY_MISMATCH',
|
|
225
|
-
cliVersion,
|
|
248
|
+
pin.cliVersion,
|
|
226
249
|
error,
|
|
227
250
|
);
|
|
228
251
|
}
|
|
229
|
-
if (typeof stdout !== 'string' || stdout.trim() !== cliVersion) {
|
|
252
|
+
if (typeof stdout !== 'string' || stdout.trim() !== pin.cliVersion) {
|
|
230
253
|
throw fail(
|
|
231
254
|
'Pinned Codex binary version does not match the reviewed runtime.',
|
|
232
255
|
'CODEX_BINARY_MISMATCH',
|
|
233
|
-
cliVersion,
|
|
256
|
+
pin.cliVersion,
|
|
234
257
|
);
|
|
235
258
|
}
|
|
236
259
|
|
|
237
260
|
if (
|
|
238
261
|
realpathSync(canonical) !== canonical
|
|
239
|
-
|| !sameFingerprint(before, fingerprint(canonical))
|
|
262
|
+
|| !sameFingerprint(before, fingerprint(canonical, pin.cliVersion))
|
|
240
263
|
) {
|
|
241
264
|
throw fail(
|
|
242
265
|
'Pinned Codex binary changed during verification.',
|
|
243
266
|
'CODEX_BINARY_MISMATCH',
|
|
244
|
-
cliVersion,
|
|
267
|
+
pin.cliVersion,
|
|
245
268
|
);
|
|
246
269
|
}
|
|
247
270
|
|
|
248
271
|
return deepFreeze({
|
|
249
272
|
path: canonical,
|
|
250
|
-
|
|
273
|
+
target: pin.target,
|
|
274
|
+
version: pin.cliVersion,
|
|
251
275
|
sha256: actualSha256,
|
|
252
276
|
fingerprint: before,
|
|
253
277
|
});
|
|
@@ -257,14 +281,14 @@ function createPinnedCodexBinaryResolver({
|
|
|
257
281
|
throw fail(
|
|
258
282
|
'Pinned Codex binary disappeared during verification.',
|
|
259
283
|
'CODEX_BINARY_MISSING',
|
|
260
|
-
cliVersion,
|
|
284
|
+
pin.cliVersion,
|
|
261
285
|
error,
|
|
262
286
|
);
|
|
263
287
|
}
|
|
264
288
|
throw fail(
|
|
265
289
|
'Pinned Codex binary failed ownership and integrity verification.',
|
|
266
290
|
'CODEX_BINARY_MISMATCH',
|
|
267
|
-
cliVersion,
|
|
291
|
+
pin.cliVersion,
|
|
268
292
|
error,
|
|
269
293
|
);
|
|
270
294
|
}
|
|
@@ -273,14 +297,9 @@ function createPinnedCodexBinaryResolver({
|
|
|
273
297
|
|
|
274
298
|
// Application code uses this fixed resolver. The factory exists so a pin
|
|
275
299
|
// upgrade can verify its candidate fixture before changing the production pin.
|
|
276
|
-
const resolvePinnedCodexBinary = createPinnedCodexBinaryResolver(
|
|
277
|
-
cliVersion: CODEX_CLI_PINNED_VERSION,
|
|
278
|
-
binarySha256: CODEX_BINARY_SHA256,
|
|
279
|
-
});
|
|
300
|
+
const resolvePinnedCodexBinary = createPinnedCodexBinaryResolver();
|
|
280
301
|
|
|
281
302
|
module.exports = {
|
|
282
|
-
CODEX_BINARY_SHA256,
|
|
283
|
-
CODEX_CLI_PINNED_VERSION,
|
|
284
303
|
CodexBinaryError,
|
|
285
304
|
createPinnedCodexBinaryResolver,
|
|
286
305
|
resolvePinnedCodexBinary,
|
package/lib/codex/diagnostics.js
CHANGED
|
@@ -10,13 +10,12 @@ const path = require('node:path');
|
|
|
10
10
|
|
|
11
11
|
const orchestra = require('@shumkov/orchestra');
|
|
12
12
|
const {
|
|
13
|
-
CODEX_BINARY_SHA256,
|
|
14
|
-
CODEX_CLI_PINNED_VERSION,
|
|
15
13
|
resolvePinnedCodexBinary,
|
|
16
14
|
} = require('./binary');
|
|
17
15
|
const { resolveCodexHostIdentity } = require('./host-identity');
|
|
18
16
|
const {
|
|
19
17
|
CODEX_PERMISSION_PROFILE_ID,
|
|
18
|
+
resolveCodexTempDirectory,
|
|
20
19
|
} = require('./runtime-profile');
|
|
21
20
|
const {
|
|
22
21
|
runtimeDirectory: resolveIpcRuntimeDirectory,
|
|
@@ -119,13 +118,16 @@ function inspectCodexHome(codexHome, dependencies) {
|
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
function
|
|
121
|
+
function readCodexOwnedConfig(codexHome) {
|
|
123
122
|
const configPath = path.join(codexHome, 'config.toml');
|
|
124
123
|
const stat = lstatSync(configPath);
|
|
125
124
|
if (stat.size > MAX_CONFIG_BYTES) {
|
|
126
125
|
throw new Error('Codex owned config exceeded the inspection bound');
|
|
127
126
|
}
|
|
128
|
-
|
|
127
|
+
return readFileSync(configPath, 'utf8');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function inspectCodexProfile(raw, profileId) {
|
|
129
131
|
const escapedProfile = profileId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
130
132
|
const required = [
|
|
131
133
|
new RegExp(`^default_permissions\\s*=\\s*"${escapedProfile}"\\s*$`, 'm'),
|
|
@@ -142,6 +144,53 @@ function inspectCodexProfile(codexHome, profileId) {
|
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
|
|
147
|
+
function inspectCodexDenyRoot(raw, deniedRoot, profileId) {
|
|
148
|
+
const lines = raw.split('\n');
|
|
149
|
+
const filesystemSection =
|
|
150
|
+
`[permissions.${JSON.stringify(profileId)}.filesystem]`;
|
|
151
|
+
let inFilesystemSection = false;
|
|
152
|
+
for (const line of lines) {
|
|
153
|
+
const structuralLine = line.trim();
|
|
154
|
+
if (structuralLine.startsWith('[')) {
|
|
155
|
+
inFilesystemSection = structuralLine === filesystemSection;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!inFilesystemSection) continue;
|
|
159
|
+
const match = line.match(/^("(?:[^"\\]|\\.)*")\s*=\s*"deny"\s*$/u);
|
|
160
|
+
if (!match) continue;
|
|
161
|
+
let configuredRoot;
|
|
162
|
+
try {
|
|
163
|
+
configuredRoot = JSON.parse(match[1]);
|
|
164
|
+
} catch {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (
|
|
168
|
+
typeof configuredRoot === 'string'
|
|
169
|
+
&& path.isAbsolute(configuredRoot)
|
|
170
|
+
&& isWithin(configuredRoot, deniedRoot)
|
|
171
|
+
) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
throw new Error('Codex protected root is absent from the owned profile');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function configuredWorkspaces(config) {
|
|
179
|
+
const workspaces = new Set();
|
|
180
|
+
const defaultCwd = config?.defaults?.cwd;
|
|
181
|
+
for (const chat of Object.values(config?.chats ?? {})) {
|
|
182
|
+
if (!chat || typeof chat !== 'object') continue;
|
|
183
|
+
const chatCwd = chat.cwd ?? defaultCwd;
|
|
184
|
+
if (typeof chatCwd === 'string') workspaces.add(chatCwd);
|
|
185
|
+
for (const topic of Object.values(chat.topics ?? {})) {
|
|
186
|
+
if (!topic || typeof topic !== 'object') continue;
|
|
187
|
+
const topicCwd = topic.cwd ?? chatCwd;
|
|
188
|
+
if (typeof topicCwd === 'string') workspaces.add(topicCwd);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return [...workspaces];
|
|
192
|
+
}
|
|
193
|
+
|
|
145
194
|
function readLease(db) {
|
|
146
195
|
if (!db || typeof db.prepare !== 'function') return undefined;
|
|
147
196
|
return db.prepare(`
|
|
@@ -249,10 +298,8 @@ function dependenciesWithDefaults(input = {}) {
|
|
|
249
298
|
input.resolveHostIdentity ?? resolveCodexHostIdentity,
|
|
250
299
|
protocolSchema:
|
|
251
300
|
input.protocolSchema ?? orchestra.codexProtocolSchema,
|
|
252
|
-
|
|
253
|
-
input.
|
|
254
|
-
pinnedBinarySha256:
|
|
255
|
-
input.pinnedBinarySha256 ?? CODEX_BINARY_SHA256,
|
|
301
|
+
resolveTargetPin:
|
|
302
|
+
input.resolveTargetPin ?? orchestra.resolveCodexTargetPin,
|
|
256
303
|
profileId:
|
|
257
304
|
input.profileId ?? CODEX_PERMISSION_PROFILE_ID,
|
|
258
305
|
temporaryRoots:
|
|
@@ -270,6 +317,7 @@ async function collectCodexDoctorChecks({
|
|
|
270
317
|
config,
|
|
271
318
|
db,
|
|
272
319
|
dependencies: dependencyOverrides,
|
|
320
|
+
processEnv = process.env,
|
|
273
321
|
} = {}) {
|
|
274
322
|
if (
|
|
275
323
|
!config?.codex
|
|
@@ -286,25 +334,29 @@ async function collectCodexDoctorChecks({
|
|
|
286
334
|
|
|
287
335
|
const dependencies = dependenciesWithDefaults(dependencyOverrides);
|
|
288
336
|
const checks = [];
|
|
337
|
+
let targetPin;
|
|
289
338
|
try {
|
|
339
|
+
targetPin = dependencies.resolveTargetPin();
|
|
290
340
|
const receipt = await dependencies.resolveBinary({
|
|
291
341
|
binaryPath: config.codex.binary,
|
|
292
342
|
env: { POLYGRAM_CODEX_BIN: config.codex.binary },
|
|
293
343
|
});
|
|
294
344
|
if (
|
|
295
|
-
receipt?.
|
|
296
|
-
|| receipt?.
|
|
345
|
+
receipt?.target !== targetPin?.target
|
|
346
|
+
|| receipt?.version !== targetPin?.cliVersion
|
|
347
|
+
|| receipt?.sha256 !== targetPin?.binarySha256
|
|
297
348
|
) {
|
|
298
349
|
throw new Error('pinned Codex binary receipt mismatch');
|
|
299
350
|
}
|
|
300
351
|
checks.push(check(
|
|
301
352
|
'codex-binary',
|
|
302
353
|
'ok',
|
|
303
|
-
`pinned runtime verified (${
|
|
354
|
+
`pinned runtime verified (${targetPin.cliVersion})`,
|
|
304
355
|
{
|
|
305
356
|
runtime: 'codex',
|
|
306
357
|
pinned: true,
|
|
307
|
-
|
|
358
|
+
target: targetPin.target,
|
|
359
|
+
version: targetPin.cliVersion,
|
|
308
360
|
},
|
|
309
361
|
));
|
|
310
362
|
} catch (error) {
|
|
@@ -347,8 +399,10 @@ async function collectCodexDoctorChecks({
|
|
|
347
399
|
|
|
348
400
|
const schema = dependencies.protocolSchema;
|
|
349
401
|
if (
|
|
350
|
-
|
|
351
|
-
&& schema?.
|
|
402
|
+
typeof targetPin?.target === 'string'
|
|
403
|
+
&& schema?.cliVersion === targetPin.cliVersion
|
|
404
|
+
&& schema?.binarySha256ByTarget?.[targetPin.target]
|
|
405
|
+
=== targetPin.binarySha256
|
|
352
406
|
&& SHA256_RE.test(schema?.generatedProtocolV2CanonicalSha256)
|
|
353
407
|
) {
|
|
354
408
|
checks.push(check(
|
|
@@ -357,7 +411,8 @@ async function collectCodexDoctorChecks({
|
|
|
357
411
|
'installed protocol schema matches the pinned runtime',
|
|
358
412
|
{
|
|
359
413
|
runtime: 'codex',
|
|
360
|
-
|
|
414
|
+
target: targetPin.target,
|
|
415
|
+
version: targetPin.cliVersion,
|
|
361
416
|
schemaPinned: true,
|
|
362
417
|
},
|
|
363
418
|
));
|
|
@@ -370,8 +425,10 @@ async function collectCodexDoctorChecks({
|
|
|
370
425
|
));
|
|
371
426
|
}
|
|
372
427
|
|
|
428
|
+
let ownedConfig;
|
|
373
429
|
try {
|
|
374
|
-
|
|
430
|
+
ownedConfig = readCodexOwnedConfig(config.codex.home);
|
|
431
|
+
inspectCodexProfile(ownedConfig, dependencies.profileId);
|
|
375
432
|
checks.push(check(
|
|
376
433
|
'codex-profile',
|
|
377
434
|
'ok',
|
|
@@ -425,6 +482,48 @@ async function collectCodexDoctorChecks({
|
|
|
425
482
|
));
|
|
426
483
|
}
|
|
427
484
|
|
|
485
|
+
try {
|
|
486
|
+
const codexTmp = resolveCodexTempDirectory(processEnv);
|
|
487
|
+
if (
|
|
488
|
+
isWithin(config.codex.home, codexTmp)
|
|
489
|
+
|| isWithin(codexTmp, config.codex.home)
|
|
490
|
+
|| configuredWorkspaces(config).some((workspace) => (
|
|
491
|
+
isWithin(workspace, codexTmp) || isWithin(codexTmp, workspace)
|
|
492
|
+
))
|
|
493
|
+
) {
|
|
494
|
+
throw new Error('Codex temp root overlaps protected runtime state');
|
|
495
|
+
}
|
|
496
|
+
ownedConfig ??= readCodexOwnedConfig(config.codex.home);
|
|
497
|
+
inspectCodexDenyRoot(
|
|
498
|
+
ownedConfig,
|
|
499
|
+
codexTmp,
|
|
500
|
+
dependencies.profileId,
|
|
501
|
+
);
|
|
502
|
+
checks.push(check(
|
|
503
|
+
'codex-tmpdir',
|
|
504
|
+
'ok',
|
|
505
|
+
'owner-only Codex child temp directory is protected from commands',
|
|
506
|
+
{
|
|
507
|
+
runtime: 'codex',
|
|
508
|
+
protected: true,
|
|
509
|
+
source: processEnv.POLYGRAM_CODEX_TMPDIR
|
|
510
|
+
? 'polygram'
|
|
511
|
+
: 'inherited',
|
|
512
|
+
},
|
|
513
|
+
));
|
|
514
|
+
} catch (error) {
|
|
515
|
+
checks.push(check(
|
|
516
|
+
'codex-tmpdir',
|
|
517
|
+
'fail',
|
|
518
|
+
'Codex child temp directory is missing, aliased, overlapping, or has unsafe permissions',
|
|
519
|
+
{
|
|
520
|
+
runtime: 'codex',
|
|
521
|
+
protected: false,
|
|
522
|
+
code: safeErrorCode(error),
|
|
523
|
+
},
|
|
524
|
+
));
|
|
525
|
+
}
|
|
526
|
+
|
|
428
527
|
checks.push(check(
|
|
429
528
|
'codex-model-catalog',
|
|
430
529
|
'warn',
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { execFileSync: defaultExecFileSync } = require('node:child_process');
|
|
4
|
-
const { createHash } = require('node:crypto');
|
|
4
|
+
const { createHash, createHmac } = require('node:crypto');
|
|
5
|
+
const { readFileSync: defaultReadFileSync } = require('node:fs');
|
|
5
6
|
|
|
6
7
|
const MAC_HOST_RE = /"IOPlatformUUID"\s*=\s*"([0-9A-Fa-f-]{36})"/;
|
|
7
8
|
const MAC_BOOT_RE = /\{\s*sec\s*=\s*(\d+),\s*usec\s*=\s*(\d+)\s*\}/;
|
|
9
|
+
const LINUX_MACHINE_ID_RE = /^[0-9a-f]{32}$/;
|
|
10
|
+
const LINUX_BOOT_ID_RE =
|
|
11
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
8
12
|
|
|
9
13
|
class CodexHostIdentityError extends Error {
|
|
10
14
|
constructor(message, code, options) {
|
|
@@ -36,6 +40,12 @@ function digest(domain, ...parts) {
|
|
|
36
40
|
return hash.digest('hex');
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
function hmacDigest(key, ...parts) {
|
|
44
|
+
const hmac = createHmac('sha256', key);
|
|
45
|
+
for (const part of parts) hmac.update(part);
|
|
46
|
+
return hmac.digest('hex');
|
|
47
|
+
}
|
|
48
|
+
|
|
39
49
|
function readDarwinIdentity(execFileSync) {
|
|
40
50
|
const hostOutput = rendered(execFileSync(
|
|
41
51
|
'/usr/sbin/ioreg',
|
|
@@ -59,20 +69,58 @@ function readDarwinIdentity(execFileSync) {
|
|
|
59
69
|
};
|
|
60
70
|
}
|
|
61
71
|
|
|
72
|
+
function canonicalLinuxSource(value, pattern, maxBytes) {
|
|
73
|
+
const raw = rendered(value);
|
|
74
|
+
if (
|
|
75
|
+
Buffer.byteLength(raw, 'utf8') > maxBytes
|
|
76
|
+
|| (raw.includes('\n') && !raw.endsWith('\n'))
|
|
77
|
+
) {
|
|
78
|
+
throw new Error('Linux identity source is malformed');
|
|
79
|
+
}
|
|
80
|
+
const normalized = raw.endsWith('\n') ? raw.slice(0, -1) : raw;
|
|
81
|
+
if (!pattern.test(normalized)) {
|
|
82
|
+
throw new Error('Linux identity source is malformed');
|
|
83
|
+
}
|
|
84
|
+
return normalized;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function readLinuxIdentity(readFileSync) {
|
|
88
|
+
const machineId = canonicalLinuxSource(
|
|
89
|
+
readFileSync('/etc/machine-id', 'utf8'),
|
|
90
|
+
LINUX_MACHINE_ID_RE,
|
|
91
|
+
33,
|
|
92
|
+
);
|
|
93
|
+
if (/^0{32}$/.test(machineId)) {
|
|
94
|
+
throw new Error('Linux machine identity is uninitialized');
|
|
95
|
+
}
|
|
96
|
+
const bootId = canonicalLinuxSource(
|
|
97
|
+
readFileSync('/proc/sys/kernel/random/boot_id', 'utf8'),
|
|
98
|
+
LINUX_BOOT_ID_RE,
|
|
99
|
+
37,
|
|
100
|
+
);
|
|
101
|
+
return {
|
|
102
|
+
machineBytes: Buffer.from(machineId, 'hex'),
|
|
103
|
+
bootBytes: Buffer.from(bootId.replaceAll('-', ''), 'hex'),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
62
107
|
function resolveCodexHostIdentity({
|
|
63
108
|
platform = process.platform,
|
|
64
109
|
execFileSync = defaultExecFileSync,
|
|
110
|
+
readFileSync = defaultReadFileSync,
|
|
65
111
|
} = {}) {
|
|
66
|
-
if (
|
|
112
|
+
if (!['darwin', 'linux'].includes(platform)) {
|
|
67
113
|
throw identityError(
|
|
68
|
-
`Codex native
|
|
114
|
+
`Codex native beta is unsupported on ${platform}`,
|
|
69
115
|
'CODEX_HOST_PLATFORM_UNSUPPORTED',
|
|
70
116
|
);
|
|
71
117
|
}
|
|
72
118
|
|
|
73
119
|
let source;
|
|
74
120
|
try {
|
|
75
|
-
source =
|
|
121
|
+
source = platform === 'darwin'
|
|
122
|
+
? readDarwinIdentity(execFileSync)
|
|
123
|
+
: readLinuxIdentity(readFileSync);
|
|
76
124
|
} catch (cause) {
|
|
77
125
|
throw identityError(
|
|
78
126
|
'Codex stable host or kernel boot identity could not be verified',
|
|
@@ -81,6 +129,20 @@ function resolveCodexHostIdentity({
|
|
|
81
129
|
);
|
|
82
130
|
}
|
|
83
131
|
|
|
132
|
+
if (platform === 'linux') {
|
|
133
|
+
return Object.freeze({
|
|
134
|
+
stableHostId: `host:${hmacDigest(
|
|
135
|
+
'polygram/codex/stable-host/linux/v1',
|
|
136
|
+
source.machineBytes,
|
|
137
|
+
)}`,
|
|
138
|
+
bootSessionId: `boot:${hmacDigest(
|
|
139
|
+
'polygram/codex/boot-session/linux/v1',
|
|
140
|
+
source.machineBytes,
|
|
141
|
+
source.bootBytes,
|
|
142
|
+
)}`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
84
146
|
const stableDigest = digest(
|
|
85
147
|
'polygram/codex/stable-host/v1',
|
|
86
148
|
platform,
|
|
@@ -15,13 +15,11 @@ const path = require('node:path');
|
|
|
15
15
|
const { isDeepStrictEqual } = require('node:util');
|
|
16
16
|
|
|
17
17
|
const {
|
|
18
|
+
buildCodexAppServerEnv,
|
|
18
19
|
CodexAppServerClient,
|
|
19
20
|
codexProtocolSchema,
|
|
21
|
+
resolveCodexTargetPin,
|
|
20
22
|
} = require('@shumkov/orchestra');
|
|
21
|
-
const {
|
|
22
|
-
CODEX_BINARY_SHA256,
|
|
23
|
-
CODEX_CLI_PINNED_VERSION,
|
|
24
|
-
} = require('./binary');
|
|
25
23
|
|
|
26
24
|
const CODEX_PERMISSION_PROFILE_ID = 'polygram-session';
|
|
27
25
|
const CONTROLLED_PATH = '/usr/bin:/bin';
|
|
@@ -106,6 +104,19 @@ function isWithin(root, candidate) {
|
|
|
106
104
|
|| (!relative.startsWith('..') && !path.isAbsolute(relative));
|
|
107
105
|
}
|
|
108
106
|
|
|
107
|
+
function normalizeDeniedRoots(roots) {
|
|
108
|
+
const bySpecificity = [...new Set(roots)].sort(
|
|
109
|
+
(left, right) => left.length - right.length || left.localeCompare(right),
|
|
110
|
+
);
|
|
111
|
+
const normalized = [];
|
|
112
|
+
for (const root of bySpecificity) {
|
|
113
|
+
if (!normalized.some((parent) => isWithin(parent, root))) {
|
|
114
|
+
normalized.push(root);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return normalized.sort();
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
function canonicalTemporaryRoots() {
|
|
110
121
|
const roots = new Set();
|
|
111
122
|
for (const candidate of [
|
|
@@ -160,22 +171,30 @@ function assertOwnedMode(target, {
|
|
|
160
171
|
return stat;
|
|
161
172
|
}
|
|
162
173
|
|
|
163
|
-
function assertSafeParentChain(target, kind
|
|
174
|
+
function assertSafeParentChain(target, kind, {
|
|
175
|
+
code = 'CODEX_HOME_UNSAFE',
|
|
176
|
+
remediation = `Move the Codex ${kind} under an owner-controlled path.`,
|
|
177
|
+
allowRootOwnedSymlinks = false,
|
|
178
|
+
} = {}) {
|
|
164
179
|
const root = path.parse(target).root;
|
|
165
180
|
let component = root;
|
|
166
181
|
for (const part of target.slice(root.length).split('/').filter(Boolean)) {
|
|
167
182
|
component = path.join(component, part);
|
|
168
183
|
const stat = lstatSync(component);
|
|
169
184
|
const uid = process.getuid?.();
|
|
170
|
-
|
|
185
|
+
const safeSystemSymlink =
|
|
171
186
|
stat.isSymbolicLink()
|
|
187
|
+
&& allowRootOwnedSymlinks
|
|
188
|
+
&& stat.uid === 0;
|
|
189
|
+
if (
|
|
190
|
+
(stat.isSymbolicLink() && !safeSystemSymlink)
|
|
172
191
|
|| (uid !== undefined && ![0, uid].includes(stat.uid))
|
|
173
|
-
|| (stat.mode & 0o022) !== 0
|
|
192
|
+
|| (!stat.isSymbolicLink() && (stat.mode & 0o022) !== 0)
|
|
174
193
|
) {
|
|
175
194
|
throw fail(
|
|
176
195
|
`Codex ${kind} path ownership or mode is unsafe.`,
|
|
177
|
-
|
|
178
|
-
|
|
196
|
+
code,
|
|
197
|
+
remediation,
|
|
179
198
|
);
|
|
180
199
|
}
|
|
181
200
|
}
|
|
@@ -359,36 +378,90 @@ function renderOwnedConfig(config, {
|
|
|
359
378
|
return lines.join('\n');
|
|
360
379
|
}
|
|
361
380
|
|
|
362
|
-
function
|
|
381
|
+
function resolveCodexTempDirectory(processEnv) {
|
|
382
|
+
const usesExplicitSelector = processEnv?.POLYGRAM_CODEX_TMPDIR !== undefined;
|
|
383
|
+
const configured = requiredString(
|
|
384
|
+
processEnv?.POLYGRAM_CODEX_TMPDIR ?? processEnv?.TMPDIR,
|
|
385
|
+
'app-server TMPDIR',
|
|
386
|
+
);
|
|
387
|
+
if (
|
|
388
|
+
!path.isAbsolute(configured)
|
|
389
|
+
|| (usesExplicitSelector && path.normalize(configured) !== configured)
|
|
390
|
+
) {
|
|
391
|
+
throw fail(
|
|
392
|
+
'Codex app-server TMPDIR must be a normalized absolute path.',
|
|
393
|
+
'CODEX_TMPDIR_UNSAFE',
|
|
394
|
+
'Configure a canonical owner-only Codex temp directory.',
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
let canonicalPath;
|
|
398
|
+
try {
|
|
399
|
+
canonicalPath = realpathSync(configured);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
throw fail(
|
|
402
|
+
'Codex app-server TMPDIR could not be resolved.',
|
|
403
|
+
'CODEX_TMPDIR_UNSAFE',
|
|
404
|
+
'Provision a canonical owner-only mode-0700 Codex temp directory.',
|
|
405
|
+
error,
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
if (usesExplicitSelector && canonicalPath !== configured) {
|
|
409
|
+
throw fail(
|
|
410
|
+
'Codex app-server TMPDIR must not be a path alias.',
|
|
411
|
+
'CODEX_TMPDIR_UNSAFE',
|
|
412
|
+
'Replace it with a canonical owner-only mode-0700 directory.',
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
if (!usesExplicitSelector) {
|
|
416
|
+
assertSafeParentChain(configured, 'inherited app-server TMPDIR', {
|
|
417
|
+
code: 'CODEX_TMPDIR_UNSAFE',
|
|
418
|
+
remediation: 'Use an inherited temp path with only owner-controlled or root-controlled components.',
|
|
419
|
+
allowRootOwnedSymlinks: true,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
assertOwnedMode(canonicalPath, {
|
|
423
|
+
code: 'CODEX_TMPDIR_UNSAFE',
|
|
424
|
+
kind: 'app-server TMPDIR',
|
|
425
|
+
expectedMode: 0o700,
|
|
426
|
+
directory: true,
|
|
427
|
+
});
|
|
428
|
+
assertSafeParentChain(canonicalPath, 'app-server TMPDIR', {
|
|
429
|
+
code: 'CODEX_TMPDIR_UNSAFE',
|
|
430
|
+
remediation: 'Move the Codex app-server TMPDIR under an owner-controlled path.',
|
|
431
|
+
});
|
|
432
|
+
return canonicalPath;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function buildControlledEnv(codexHome, processEnv, appServerTmp) {
|
|
363
436
|
const home = requiredString(processEnv?.HOME, 'app-server HOME');
|
|
364
|
-
|
|
365
|
-
if (!path.isAbsolute(home) || !path.isAbsolute(tmpdir)) {
|
|
437
|
+
if (!path.isAbsolute(home)) {
|
|
366
438
|
throw fail(
|
|
367
|
-
'Codex app-server HOME
|
|
439
|
+
'Codex app-server HOME must be absolute.',
|
|
368
440
|
'CODEX_RUNTIME_PROFILE_INVALID',
|
|
369
|
-
'Configure explicit absolute service HOME
|
|
441
|
+
'Configure an explicit absolute service HOME.',
|
|
370
442
|
);
|
|
371
443
|
}
|
|
372
|
-
return
|
|
444
|
+
return buildCodexAppServerEnv(codexHome, {
|
|
373
445
|
HOME: home,
|
|
374
|
-
|
|
375
|
-
TMPDIR: tmpdir,
|
|
446
|
+
TMPDIR: appServerTmp,
|
|
376
447
|
LANG: processEnv?.LANG,
|
|
377
448
|
LC_ALL: processEnv?.LC_ALL,
|
|
378
|
-
|
|
379
|
-
}).filter(([, value]) => value !== undefined));
|
|
449
|
+
});
|
|
380
450
|
}
|
|
381
451
|
|
|
382
|
-
function validateBinaryReceipt(receipt, schema) {
|
|
452
|
+
function validateBinaryReceipt(receipt, schema, targetPin) {
|
|
383
453
|
if (
|
|
384
454
|
!receipt
|
|
385
455
|
|| typeof receipt !== 'object'
|
|
386
456
|
|| !Object.isFrozen(receipt)
|
|
387
457
|
|| !path.isAbsolute(receipt.path ?? '')
|
|
388
|
-
||
|
|
389
|
-
|| receipt.
|
|
390
|
-
||
|
|
391
|
-
||
|
|
458
|
+
|| typeof targetPin?.target !== 'string'
|
|
459
|
+
|| receipt.target !== targetPin.target
|
|
460
|
+
|| receipt.version !== targetPin.cliVersion
|
|
461
|
+
|| receipt.sha256 !== targetPin.binarySha256
|
|
462
|
+
|| schema?.cliVersion !== targetPin.cliVersion
|
|
463
|
+
|| schema?.binarySha256ByTarget?.[targetPin.target]
|
|
464
|
+
!== targetPin.binarySha256
|
|
392
465
|
|| !SHA256_RE.test(schema?.generatedProtocolV2CanonicalSha256)
|
|
393
466
|
) {
|
|
394
467
|
throw fail(
|
|
@@ -425,18 +498,23 @@ function assertRootSeparation(codexHome, workspace, daemonSecretRoots) {
|
|
|
425
498
|
|
|
426
499
|
function provisionRuntimeFiles(options, temporaryRoots) {
|
|
427
500
|
const workspace = canonicalDirectory(options.workspace, 'workspace');
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
501
|
+
const appServerTmp = resolveCodexTempDirectory(
|
|
502
|
+
options.processEnv ?? process.env,
|
|
503
|
+
);
|
|
504
|
+
const explicitDaemonSecretRoots = (options.daemonSecretRoots ?? []).map(
|
|
505
|
+
(root) => canonicalDirectory(root, 'daemon-secret root'),
|
|
506
|
+
);
|
|
507
|
+
if (explicitDaemonSecretRoots.length === 0) {
|
|
434
508
|
throw fail(
|
|
435
509
|
'Codex requires at least one explicit daemon-secret root.',
|
|
436
510
|
'CODEX_RUNTIME_PROFILE_INVALID',
|
|
437
511
|
'Configure every daemon-secret root before enabling Codex.',
|
|
438
512
|
);
|
|
439
513
|
}
|
|
514
|
+
const daemonSecretRoots = normalizeDeniedRoots([
|
|
515
|
+
...explicitDaemonSecretRoots,
|
|
516
|
+
appServerTmp,
|
|
517
|
+
]);
|
|
440
518
|
|
|
441
519
|
const configuredHome = requiredString(options.codexHome, 'credential home');
|
|
442
520
|
if (!path.isAbsolute(configuredHome) || path.normalize(configuredHome) !== configuredHome) {
|
|
@@ -506,7 +584,7 @@ function provisionRuntimeFiles(options, temporaryRoots) {
|
|
|
506
584
|
throw fail(
|
|
507
585
|
'Codex owned config.toml differs from the native-beta policy.',
|
|
508
586
|
'CODEX_OWNED_CONFIG_DRIFT',
|
|
509
|
-
'
|
|
587
|
+
'Back up config.toml outside CODEX_HOME, then remove or move the original and rerun startup to reprovision the exact owned config; Polygram never migrates or overwrites it automatically.',
|
|
510
588
|
);
|
|
511
589
|
}
|
|
512
590
|
} else {
|
|
@@ -542,7 +620,11 @@ function provisionRuntimeFiles(options, temporaryRoots) {
|
|
|
542
620
|
ownedConfig,
|
|
543
621
|
rawConfig,
|
|
544
622
|
ownedConfigSha256: digest(rawConfig),
|
|
545
|
-
env: buildControlledEnv(
|
|
623
|
+
env: buildControlledEnv(
|
|
624
|
+
codexHome,
|
|
625
|
+
options.processEnv ?? process.env,
|
|
626
|
+
appServerTmp,
|
|
627
|
+
),
|
|
546
628
|
};
|
|
547
629
|
}
|
|
548
630
|
|
|
@@ -832,17 +914,20 @@ function createCodexRuntimeProfileBuilder({
|
|
|
832
914
|
temporaryRoots = canonicalTemporaryRoots(),
|
|
833
915
|
clientFactory = (options) => new CodexAppServerClient(options),
|
|
834
916
|
protocolSchema = codexProtocolSchema,
|
|
917
|
+
resolveTargetPin = resolveCodexTargetPin,
|
|
835
918
|
} = {}) {
|
|
836
919
|
if (
|
|
837
920
|
!Array.isArray(temporaryRoots)
|
|
838
921
|
|| typeof clientFactory !== 'function'
|
|
922
|
+
|| typeof resolveTargetPin !== 'function'
|
|
839
923
|
) {
|
|
840
924
|
throw new TypeError('Codex runtime profile builder options are invalid');
|
|
841
925
|
}
|
|
842
926
|
|
|
843
927
|
return Object.freeze({
|
|
844
928
|
async prepare(options = {}) {
|
|
845
|
-
|
|
929
|
+
const targetPin = resolveTargetPin();
|
|
930
|
+
validateBinaryReceipt(options.binaryReceipt, protocolSchema, targetPin);
|
|
846
931
|
const materialized = provisionRuntimeFiles(options, temporaryRoots);
|
|
847
932
|
const characterized = await characterizeRuntime(materialized, {
|
|
848
933
|
binaryReceipt: options.binaryReceipt,
|
|
@@ -853,6 +938,7 @@ function createCodexRuntimeProfileBuilder({
|
|
|
853
938
|
return deepFreeze({
|
|
854
939
|
runtime: 'codex',
|
|
855
940
|
binary: options.binaryReceipt.path,
|
|
941
|
+
target: targetPin.target,
|
|
856
942
|
binarySha256: options.binaryReceipt.sha256,
|
|
857
943
|
cliVersion: options.binaryReceipt.version,
|
|
858
944
|
protocolSchemaSha256:
|
|
@@ -886,5 +972,7 @@ module.exports = {
|
|
|
886
972
|
CODEX_PERMISSION_PROFILE_ID,
|
|
887
973
|
CodexRuntimeProfileError,
|
|
888
974
|
createCodexRuntimeProfileBuilder,
|
|
975
|
+
normalizeDeniedRoots,
|
|
889
976
|
prepareCodexRuntimeProfile,
|
|
977
|
+
resolveCodexTempDirectory,
|
|
890
978
|
};
|
|
@@ -457,7 +457,7 @@ function createFormatConfigInfoText({
|
|
|
457
457
|
|
|
458
458
|
let body = head;
|
|
459
459
|
if (codex) {
|
|
460
|
-
body += '\n\nNative
|
|
460
|
+
body += '\n\nNative Codex beta: command network and web search are disabled. '
|
|
461
461
|
+ 'Product MCP tools and interactive approvals are unavailable. '
|
|
462
462
|
+ 'Detached/background servers are unsupported and may survive hard runtime loss.';
|
|
463
463
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CODEX_TEMP_SELECTOR = 'POLYGRAM_CODEX_TMPDIR';
|
|
4
|
+
const ENV_BIN = '/usr/bin/env';
|
|
5
|
+
|
|
6
|
+
function createClaudeTmuxRunner(runner) {
|
|
7
|
+
if (!runner || typeof runner.spawn !== 'function') {
|
|
8
|
+
throw new TypeError('Claude tmux runner requires spawn()');
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
...runner,
|
|
12
|
+
spawn(options) {
|
|
13
|
+
return runner.spawn({
|
|
14
|
+
...options,
|
|
15
|
+
command: ENV_BIN,
|
|
16
|
+
args: [
|
|
17
|
+
'-u',
|
|
18
|
+
CODEX_TEMP_SELECTOR,
|
|
19
|
+
options.command,
|
|
20
|
+
...(options.args ?? []),
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
createClaudeTmuxRunner,
|
|
29
|
+
};
|
package/lib/prompt.js
CHANGED
|
@@ -33,7 +33,7 @@ function polygramInfo({ stickerEmojis = [], backend = 'sdk' } = {}) {
|
|
|
33
33
|
const deliveryContract = backend === 'cli'
|
|
34
34
|
? `You are connected via a Telegram daemon (polygram) in channels mode. Inline final text is invisible to the Telegram user. For every user-visible response, you MUST call \`mcp__polygram-bridge__reply\` within this turn. Only a successful reply-tool receipt proves delivery. Do not claim something was already sent or posted above based only on the transcript; transcript content is not a delivery receipt. If delivery is uncertain, send it now with the reply tool.`
|
|
35
35
|
: backend === 'codex'
|
|
36
|
-
? `You are connected to Telegram through polygram's Codex app-server runtime. Reply with inline text — polygram streams and delivers your final response automatically. Do NOT use Telegram MCP tools. This is a native
|
|
36
|
+
? `You are connected to Telegram through polygram's Codex app-server runtime. Reply with inline text — polygram streams and delivers your final response automatically. Do NOT use Telegram MCP tools. This is a native Codex beta: command network and model-native web search are disabled, and product MCP tools and interactive approvals are unavailable. Keep long-running commands in the foreground. Do not start detached or background servers; they are unsupported and may survive hard runtime loss.`
|
|
37
37
|
: `You are connected via a Telegram daemon (polygram). Just reply with text — polygram delivers your response automatically. Do NOT use Telegram MCP tools.`;
|
|
38
38
|
const emojiLine = hasStickers
|
|
39
39
|
? `Single emoji reply = auto-converted: ${stickerEmojis.join('')} become your stickers, any other emoji (🔥👍💪❤️) becomes a reaction on the user's message.`
|
package/ops/README.md
CHANGED
|
@@ -118,9 +118,11 @@ should surface, not silently log to a DB the bot isn't watching.
|
|
|
118
118
|
|
|
119
119
|
## Native Codex beta diagnostics
|
|
120
120
|
|
|
121
|
-
Codex is an opt-in native beta
|
|
121
|
+
Codex is an opt-in native beta supported on Darwin arm64 and Linux x64.
|
|
122
|
+
Before selecting `pm: "codex"`, configure:
|
|
122
123
|
|
|
123
|
-
- `codex.binary` as the canonical immutable executable for the pinned
|
|
124
|
+
- `codex.binary` as the canonical immutable executable for the pinned
|
|
125
|
+
target-specific version and checksum;
|
|
124
126
|
- `codex.home` as a dedicated, persistent, non-temporary `CODEX_HOME` with
|
|
125
127
|
mode `0700`;
|
|
126
128
|
- owner-only `config.toml` and `auth.json` files with mode `0600`; and
|
|
@@ -131,6 +133,44 @@ List every other daemon credential or control tree in
|
|
|
131
133
|
`codex.daemonSecretRoots`, including the interactive `~/.codex` tree when it
|
|
132
134
|
exists; the dedicated deployment home is separate and must not be reused.
|
|
133
135
|
|
|
136
|
+
On Linux, `POLYGRAM_CODEX_TMPDIR` is mandatory. Set it to a canonical,
|
|
137
|
+
service-owned directory with mode `0700`; do not use `/tmp`, a symlink, or a
|
|
138
|
+
shared writable parent. A systemd unit can provision it without a reboot:
|
|
139
|
+
|
|
140
|
+
```ini
|
|
141
|
+
[Service]
|
|
142
|
+
RuntimeDirectory=polygram-codex
|
|
143
|
+
RuntimeDirectoryMode=0700
|
|
144
|
+
Environment=POLYGRAM_CODEX_TMPDIR=/run/polygram-codex
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Polygram passes this selector only to the Codex app-server child as `TMPDIR`.
|
|
148
|
+
The exact generated `config.toml` includes the selected directory, or a
|
|
149
|
+
normalized parent that covers it, as a `deny` root. Claude SDK and CLI child
|
|
150
|
+
environments retain their existing `TMPDIR` and do not receive the selector.
|
|
151
|
+
|
|
152
|
+
Existing generated `config.toml` files from before the Codex temp-root policy
|
|
153
|
+
will fail with `CODEX_OWNED_CONFIG_DRIFT`. This is deliberate: Polygram never
|
|
154
|
+
migrates or overwrites an owned config automatically. With the daemon stopped:
|
|
155
|
+
|
|
156
|
+
1. Choose an owner-only backup directory outside `CODEX_HOME` that is already
|
|
157
|
+
listed in `codex.daemonSecretRoots`.
|
|
158
|
+
2. Back up by moving the old file there, preserving it for inspection:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
codex_config=/path/to/codex-home/config.toml
|
|
162
|
+
codex_backup_dir=/path/to/denied-daemon-secret-root/codex-config-backups
|
|
163
|
+
install -d -m 0700 "$codex_backup_dir"
|
|
164
|
+
mv "$codex_config" "$codex_backup_dir/config.toml.before-tmpdir-deny"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
3. Start Polygram again so it provisions the new exact owner-only
|
|
168
|
+
`config.toml`, then rerun doctor and retain the backup until the deployment
|
|
169
|
+
is verified.
|
|
170
|
+
|
|
171
|
+
Do not edit the generated file in place or copy the old file back. This clean
|
|
172
|
+
configuration migration and normal Linux canary setup require no reboot.
|
|
173
|
+
|
|
134
174
|
Run the existing doctor against the intended config and database:
|
|
135
175
|
|
|
136
176
|
```bash
|
|
@@ -139,8 +179,11 @@ node scripts/doctor.js --bot my-bot --config /path/to/config.json --db /path/to/
|
|
|
139
179
|
|
|
140
180
|
The Codex checks are local and content-free. They verify the binary pin,
|
|
141
181
|
dedicated home, installed protocol schema, owned profile, protected IPC runtime
|
|
142
|
-
directory,
|
|
143
|
-
|
|
182
|
+
directory, selected app-server temp directory (`codex-tmpdir`), stable host and
|
|
183
|
+
kernel boot-session identity, and the daemon-wide lease. `codex-tmpdir`
|
|
184
|
+
requires a canonical owner-only mode-`0700` directory that does not overlap
|
|
185
|
+
runtime state or a configured workspace and is covered by the owned profile's
|
|
186
|
+
deny roots. The checks do not print
|
|
144
187
|
paths, credential contents, raw host/boot identities, generation IDs, prompts,
|
|
145
188
|
command output, or raw failure text. They do not start app-server or perform
|
|
146
189
|
authenticated model discovery. `codex-model-catalog` therefore remains a
|
|
@@ -161,7 +204,8 @@ This lease does not fence Claude, another Polygram daemon, or an
|
|
|
161
204
|
uninstrumented host process.
|
|
162
205
|
|
|
163
206
|
Detached and background development servers are unsupported in the native
|
|
164
|
-
|
|
165
|
-
cleanup was accepted, and a fresh registry page was
|
|
166
|
-
arbitrary descendants died. After transport or
|
|
167
|
-
process may survive until the required host
|
|
207
|
+
Codex beta on both supported targets. Healthy stop proves the exact Codex turn
|
|
208
|
+
settled, tracked-terminal cleanup was accepted, and a fresh registry page was
|
|
209
|
+
empty; it does not prove arbitrary descendants died. After transport or
|
|
210
|
+
app-server hard loss, such a process may survive until the required host
|
|
211
|
+
reboot.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polygram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "Telegram daemon for Claude Code that preserves the OpenClaw per-chat session model. Migration path for OpenClaw users moving to Claude Code.",
|
|
5
5
|
"main": "lib/ipc/client.js",
|
|
6
6
|
"bin": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@anthropic-ai/claude-agent-sdk": "0.2.123",
|
|
65
65
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
66
|
-
"@shumkov/orchestra": "0.
|
|
66
|
+
"@shumkov/orchestra": "0.10.1",
|
|
67
67
|
"better-sqlite3": "^12.9.0",
|
|
68
68
|
"grammy": "^1.42.0",
|
|
69
69
|
"markdown-it": "^14.1.1",
|
package/polygram.js
CHANGED
|
@@ -56,6 +56,9 @@ const { extractAssistantText } = require('@shumkov/orchestra');
|
|
|
56
56
|
const {
|
|
57
57
|
createChannelsToolDispatcher, buildAllowedRoots,
|
|
58
58
|
} = require('./lib/process/channels-tool-dispatcher');
|
|
59
|
+
const {
|
|
60
|
+
createClaudeTmuxRunner,
|
|
61
|
+
} = require('./lib/process/claude-environment');
|
|
59
62
|
const { createTmuxRunner } = require('@shumkov/orchestra');
|
|
60
63
|
const { sweepTmuxOrphans } = require('@shumkov/orchestra').orphanSweep;
|
|
61
64
|
// rc.42: autosteer-buffer module deleted. Native SDK priority push
|
|
@@ -3622,6 +3625,7 @@ async function main() {
|
|
|
3622
3625
|
requireExistingServer,
|
|
3623
3626
|
socketName: tmuxSocketName,
|
|
3624
3627
|
});
|
|
3628
|
+
const claudeTmuxRunner = createClaudeTmuxRunner(tmuxRunner);
|
|
3625
3629
|
// Verify the pinned claude CLI binary is present. The tmux
|
|
3626
3630
|
// backend spawns this exact binary by absolute path (see
|
|
3627
3631
|
// lib/claude-bin.js + TmuxProcess.start) — it never resolves
|
|
@@ -3757,7 +3761,7 @@ async function main() {
|
|
|
3757
3761
|
spawnFn: buildSdkOptions,
|
|
3758
3762
|
db,
|
|
3759
3763
|
logger: console,
|
|
3760
|
-
tmuxRunner,
|
|
3764
|
+
tmuxRunner: claudeTmuxRunner,
|
|
3761
3765
|
sessionLauncher,
|
|
3762
3766
|
botName: BOT_NAME,
|
|
3763
3767
|
// channels backend
|