polygram 0.46.2 → 0.46.3
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 +6 -4
- package/lib/codex/deployment-policy.js +4 -17
- package/lib/codex/diagnostics.js +76 -58
- package/lib/codex/model-catalog.js +1 -1
- package/lib/codex/runtime-controller.js +3 -3
- package/lib/codex/runtime-profile.js +102 -60
- package/lib/handlers/config-ui.js +1 -1
- package/lib/prompt.js +4 -8
- package/lib/runtime-config.js +1 -2
- package/package.json +1 -1
- package/polygram.js +0 -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.46.
|
|
4
|
+
"version": "0.46.3",
|
|
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
|
@@ -117,12 +117,14 @@
|
|
|
117
117
|
},
|
|
118
118
|
|
|
119
119
|
"codex": {
|
|
120
|
-
"_comment": "Optional
|
|
121
|
-
"_comment_access": "
|
|
122
|
-
"_comment_proxy": "
|
|
120
|
+
"_comment": "Optional macOS arm64 or Linux x64 Codex app-server beta. Codex is default-off: a chat/topic must explicitly set codexEnabled:true before pm:'codex' can be selected or dispatched, and exact target-specific startup preflight must succeed; other host targets, including Windows, are rejected. `home` must be a dedicated non-temporary 0700 CODEX_HOME; no native login or credential transfer is required. `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. Every Codex chat has service-user filesystem rights, command network and live web search; 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.",
|
|
121
|
+
"_comment_access": "Required global trusted policy for every enabled Codex scope. No chat-ID admission list. Scoped codexEnabled/backend/model/effort selections are preserved. Owned config changes fail on drift; back up and reprovision deliberately.",
|
|
122
|
+
"_comment_proxy": "Required global CLIProxy Responses route, loopback HTTP /v1 only. Provision clientKeyFile privately (owner or root, no group/other permissions). Native auth is unused; proxy failures never fall back to native inference. Catalog listing alone does not prove provider entitlement.",
|
|
123
123
|
"_comment_hooks": "Optional deployment-wide protected Codex hooks. Omit `hooks` for the existing hooks-off behavior. After installing a reviewed hook artifact version, add `hooks` with exactly: artifactRoot, enabled, operatorUid, runtimeId, runtimeRoot, runtimeSha256, serviceUid, and version. Polygram then discovers and pins the exact hook inventory before Codex admission; set enabled:false with the same receipt to roll back cleanly.",
|
|
124
124
|
"home": "/Users/you/.codex-polygram",
|
|
125
|
-
"binary": "/Users/you/.local/share/codex/versions/0.
|
|
125
|
+
"binary": "/Users/you/.local/share/codex/versions/0.167.2/codex",
|
|
126
|
+
"access": {"mode": "trusted", "commandPath": "/Users/you/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"},
|
|
127
|
+
"proxy": {"baseUrl": "http://127.0.0.1:8318/v1", "clientKeyFile": "/Users/you/.config/polygram/codex-proxy.key"},
|
|
126
128
|
"daemonSecretRoots": [
|
|
127
129
|
"/Users/you/.polygram",
|
|
128
130
|
"/Users/you/.claude",
|
|
@@ -19,30 +19,17 @@ function exactObject(value, keys) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function validateAccess(access) {
|
|
22
|
-
if (access
|
|
23
|
-
if (!exactObject(access, ['mode', 'chatIds', 'commandPath'])
|
|
22
|
+
if (!exactObject(access, ['mode', 'commandPath'])
|
|
24
23
|
|| access.mode !== 'trusted'
|
|
25
|
-
|| !Array.isArray(access.chatIds) || access.chatIds.length === 0
|
|
26
|
-
|| access.chatIds.some((id) => typeof id !== 'string' || !/^[1-9][0-9]*$/.test(id))
|
|
27
24
|
|| typeof access.commandPath !== 'string' || access.commandPath.length > 4096
|
|
28
25
|
|| /[\u0000-\u001f\u007f]/u.test(access.commandPath)
|
|
29
26
|
|| access.commandPath.split(':').some((entry) => !path.isAbsolute(entry))) {
|
|
30
|
-
throw invalid('trusted access
|
|
31
|
-
}
|
|
32
|
-
return { mode: 'trusted', chatIds: [...access.chatIds], commandPath: access.commandPath };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function accessAllowsChat(access, chatId) {
|
|
36
|
-
try {
|
|
37
|
-
const trusted = validateAccess(access);
|
|
38
|
-
return trusted === null || trusted.chatIds.includes(String(chatId));
|
|
39
|
-
} catch {
|
|
40
|
-
return false;
|
|
27
|
+
throw invalid('requires trusted access with an explicit absolute-entry commandPath');
|
|
41
28
|
}
|
|
29
|
+
return { mode: 'trusted', commandPath: access.commandPath };
|
|
42
30
|
}
|
|
43
31
|
|
|
44
32
|
function readProxy(proxy) {
|
|
45
|
-
if (proxy === undefined) return null;
|
|
46
33
|
let endpoint;
|
|
47
34
|
try { endpoint = new URL(proxy?.baseUrl); } catch {}
|
|
48
35
|
if (!exactObject(proxy, ['baseUrl', 'clientKeyFile'])
|
|
@@ -88,4 +75,4 @@ function readProxy(proxy) {
|
|
|
88
75
|
};
|
|
89
76
|
}
|
|
90
77
|
|
|
91
|
-
module.exports = { TRUSTED_PROFILE_ID, validateAccess,
|
|
78
|
+
module.exports = { TRUSTED_PROFILE_ID, validateAccess, readProxy };
|
package/lib/codex/diagnostics.js
CHANGED
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
realpathSync,
|
|
7
7
|
} = require('node:fs');
|
|
8
8
|
const os = require('node:os');
|
|
9
|
+
const { validateAccess, readProxy } = require('./deployment-policy');
|
|
9
10
|
const path = require('node:path');
|
|
10
11
|
|
|
11
12
|
const orchestra = require('@shumkov/orchestra');
|
|
@@ -15,12 +16,16 @@ const {
|
|
|
15
16
|
const { resolveCodexHostIdentity } = require('./host-identity');
|
|
16
17
|
const {
|
|
17
18
|
CODEX_PERMISSION_PROFILE_ID,
|
|
19
|
+
selectCodexWorkspaceHome,
|
|
20
|
+
inspectCodexHomeAnchor,
|
|
18
21
|
resolveCodexTempDirectory,
|
|
19
22
|
} = require('./runtime-profile');
|
|
20
23
|
const {
|
|
21
24
|
runtimeDirectory: resolveIpcRuntimeDirectory,
|
|
22
25
|
} = require('../ipc/runtime-directory');
|
|
23
26
|
|
|
27
|
+
const { resolveCodexRuntimeRequest } = require('../runtime-config');
|
|
28
|
+
|
|
24
29
|
const MAX_DETAIL_BYTES = 256;
|
|
25
30
|
const MAX_CONFIG_BYTES = 64 * 1024;
|
|
26
31
|
const SHA256_RE = /^[a-f0-9]{64}$/;
|
|
@@ -111,6 +116,10 @@ function inspectCodexHome(codexHome, dependencies) {
|
|
|
111
116
|
genericCodexHome: dependencies.genericCodexHome,
|
|
112
117
|
});
|
|
113
118
|
for (const file of ['config.toml', 'auth.json']) {
|
|
119
|
+
if (file === 'auth.json') {
|
|
120
|
+
try { lstatSync(path.join(codexHome, file)); }
|
|
121
|
+
catch (error) { if (error.code === 'ENOENT') continue; throw error; }
|
|
122
|
+
}
|
|
114
123
|
assertOwnedPath(path.join(codexHome, file), {
|
|
115
124
|
directory: false,
|
|
116
125
|
mode: 0o600,
|
|
@@ -127,53 +136,43 @@ function readCodexOwnedConfig(codexHome) {
|
|
|
127
136
|
return readFileSync(configPath, 'utf8');
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
function inspectCodexProfile(raw, profileId) {
|
|
139
|
+
function inspectCodexProfile(raw, profileId, codex) {
|
|
140
|
+
validateAccess(codex.access);
|
|
141
|
+
const { provider } = readProxy(codex.proxy);
|
|
131
142
|
const escapedProfile = profileId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
132
143
|
const required = [
|
|
133
144
|
new RegExp(`^default_permissions\\s*=\\s*"${escapedProfile}"\\s*$`, 'm'),
|
|
134
145
|
/^approval_policy\s*=\s*"never"\s*$/m,
|
|
135
|
-
/^web_search\s*=\s*"
|
|
146
|
+
/^web_search\s*=\s*"live"\s*$/m,
|
|
136
147
|
/^\[features\]\s*\ngoals\s*=\s*false\s*$/m,
|
|
137
148
|
new RegExp(
|
|
138
149
|
`^\\[permissions\\."${escapedProfile}"\\.network\\]\\s*\\n`
|
|
139
|
-
+ 'enabled\\s*=\\s*
|
|
150
|
+
+ 'enabled\\s*=\\s*true\\s*$',
|
|
140
151
|
'm',
|
|
141
152
|
),
|
|
142
153
|
];
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
let inFilesystemSection = false;
|
|
153
|
-
for (const line of lines) {
|
|
154
|
-
const structuralLine = line.trim();
|
|
155
|
-
if (structuralLine.startsWith('[')) {
|
|
156
|
-
inFilesystemSection = structuralLine === filesystemSection;
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (!inFilesystemSection) continue;
|
|
160
|
-
const match = line.match(/^("(?:[^"\\]|\\.)*")\s*=\s*"deny"\s*$/u);
|
|
161
|
-
if (!match) continue;
|
|
162
|
-
let configuredRoot;
|
|
163
|
-
try {
|
|
164
|
-
configuredRoot = JSON.parse(match[1]);
|
|
165
|
-
} catch {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
if (
|
|
169
|
-
typeof configuredRoot === 'string'
|
|
170
|
-
&& path.isAbsolute(configuredRoot)
|
|
171
|
-
&& isWithin(configuredRoot, deniedRoot)
|
|
172
|
-
) {
|
|
173
|
-
return;
|
|
154
|
+
const section = (name) => {
|
|
155
|
+
const header = `[${name}]`;
|
|
156
|
+
const lines = raw.split('\n');
|
|
157
|
+
const start = lines.findIndex((line) => line.trim() === header);
|
|
158
|
+
if (start < 0 || lines.filter((line) => line.trim() === header).length !== 1) return [];
|
|
159
|
+
const body = [];
|
|
160
|
+
for (const line of lines.slice(start + 1)) {
|
|
161
|
+
if (line.trim().startsWith('[')) break;
|
|
162
|
+
if (line.trim() && !line.trim().startsWith('#')) body.push(line.trim());
|
|
174
163
|
}
|
|
164
|
+
return body.sort();
|
|
165
|
+
};
|
|
166
|
+
const equalLines = (actual, expected) => JSON.stringify(actual) === JSON.stringify(expected.sort());
|
|
167
|
+
if (!required.every((pattern) => pattern.test(raw))
|
|
168
|
+
|| !/^model_provider\s*=\s*"cliproxyapi"\s*$/m.test(raw)
|
|
169
|
+
|| !equalLines(section(`permissions.${JSON.stringify(profileId)}.filesystem`), ['":root" = "write"'])
|
|
170
|
+
|| !equalLines(section('memories'), ['generate_memories = false', 'use_memories = false'])
|
|
171
|
+
|| !equalLines(section('model_providers.cliproxyapi'), Object.entries(provider).map(
|
|
172
|
+
([key, value]) => `${key} = ${JSON.stringify(value)}`,
|
|
173
|
+
))) {
|
|
174
|
+
throw new Error('Codex owned profile is unavailable');
|
|
175
175
|
}
|
|
176
|
-
throw new Error('Codex protected root is absent from the owned profile');
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
function configuredWorkspaces(config) {
|
|
@@ -375,16 +374,36 @@ async function collectCodexDoctorChecks({
|
|
|
375
374
|
));
|
|
376
375
|
}
|
|
377
376
|
|
|
377
|
+
const selectedHomes = new Set();
|
|
378
|
+
const anchor = config.codex.home ?? processEnv.POLYGRAM_CODEX_HOME;
|
|
379
|
+
let selectionError = null;
|
|
380
|
+
try {
|
|
381
|
+
validateAccess(config.codex.access);
|
|
382
|
+
readProxy(config.codex.proxy);
|
|
383
|
+
inspectCodexHomeAnchor({ codexHome: anchor, processEnv });
|
|
384
|
+
for (const [chatId, chat] of Object.entries(config.chats ?? {})) {
|
|
385
|
+
for (const threadId of [null, ...Object.keys(chat.topics ?? {})]) {
|
|
386
|
+
const request = resolveCodexRuntimeRequest({ config, chatId, threadId });
|
|
387
|
+
if (request) {
|
|
388
|
+
const options = { codexHome: anchor, workspace: request.cwd, processEnv };
|
|
389
|
+
selectedHomes.add(selectCodexWorkspaceHome(options).codexHome);
|
|
390
|
+
selectCodexWorkspaceHome(options, { requireBinding: true });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
} catch (error) { selectionError = error; }
|
|
395
|
+
|
|
378
396
|
try {
|
|
379
|
-
|
|
397
|
+
if (selectionError) throw selectionError;
|
|
398
|
+
for (const home of selectedHomes) inspectCodexHome(home, dependencies);
|
|
380
399
|
checks.push(check(
|
|
381
400
|
'codex-home',
|
|
382
|
-
'ok',
|
|
383
|
-
'
|
|
401
|
+
selectedHomes.size ? 'ok' : 'warn',
|
|
402
|
+
selectedHomes.size ? 'selected workspace homes are persistent mode-0700 directories'
|
|
403
|
+
: 'no Codex-selected workspace home to inspect',
|
|
384
404
|
{
|
|
385
405
|
runtime: 'codex',
|
|
386
406
|
dedicated: true,
|
|
387
|
-
credentialsPresent: true,
|
|
388
407
|
},
|
|
389
408
|
));
|
|
390
409
|
} catch (error) {
|
|
@@ -430,16 +449,21 @@ async function collectCodexDoctorChecks({
|
|
|
430
449
|
|
|
431
450
|
let ownedConfig;
|
|
432
451
|
try {
|
|
433
|
-
|
|
434
|
-
|
|
452
|
+
if (selectionError) throw selectionError;
|
|
453
|
+
for (const home of selectedHomes) {
|
|
454
|
+
inspectCodexHome(home, dependencies);
|
|
455
|
+
ownedConfig = readCodexOwnedConfig(home);
|
|
456
|
+
inspectCodexProfile(ownedConfig, dependencies.profileId, config.codex);
|
|
457
|
+
}
|
|
435
458
|
checks.push(check(
|
|
436
459
|
'codex-profile',
|
|
437
|
-
'ok',
|
|
438
|
-
'
|
|
460
|
+
selectedHomes.size ? 'ok' : 'warn',
|
|
461
|
+
selectedHomes.size ? 'selected workspace homes have owned trusted CLIProxy profiles'
|
|
462
|
+
: 'no Codex-selected workspace profile; runtime preflight is still required',
|
|
439
463
|
{
|
|
440
464
|
runtime: 'codex',
|
|
441
465
|
profile: dependencies.profileId,
|
|
442
|
-
available:
|
|
466
|
+
available: selectedHomes.size > 0,
|
|
443
467
|
},
|
|
444
468
|
));
|
|
445
469
|
} catch (error) {
|
|
@@ -466,10 +490,10 @@ async function collectCodexDoctorChecks({
|
|
|
466
490
|
checks.push(check(
|
|
467
491
|
'codex-ipc-root',
|
|
468
492
|
'ok',
|
|
469
|
-
'
|
|
493
|
+
'daemon IPC runtime directory has owner-only permissions',
|
|
470
494
|
{
|
|
471
495
|
runtime: 'codex',
|
|
472
|
-
|
|
496
|
+
ownerOnly: true,
|
|
473
497
|
},
|
|
474
498
|
));
|
|
475
499
|
} catch (error) {
|
|
@@ -479,7 +503,7 @@ async function collectCodexDoctorChecks({
|
|
|
479
503
|
'daemon IPC runtime directory is missing, temporary, aliased, or has unsafe permissions',
|
|
480
504
|
{
|
|
481
505
|
runtime: 'codex',
|
|
482
|
-
|
|
506
|
+
ownerOnly: false,
|
|
483
507
|
code: safeErrorCode(error),
|
|
484
508
|
},
|
|
485
509
|
));
|
|
@@ -488,27 +512,21 @@ async function collectCodexDoctorChecks({
|
|
|
488
512
|
try {
|
|
489
513
|
const codexTmp = resolveCodexTempDirectory(processEnv);
|
|
490
514
|
if (
|
|
491
|
-
|
|
492
|
-
|
|
515
|
+
[anchor, ...selectedHomes].some((home) => typeof home !== 'string'
|
|
516
|
+
|| isWithin(home, codexTmp) || isWithin(codexTmp, home))
|
|
493
517
|
|| configuredWorkspaces(config).some((workspace) => (
|
|
494
518
|
isWithin(workspace, codexTmp) || isWithin(codexTmp, workspace)
|
|
495
519
|
))
|
|
496
520
|
) {
|
|
497
521
|
throw new Error('Codex temp root overlaps protected runtime state');
|
|
498
522
|
}
|
|
499
|
-
ownedConfig ??= readCodexOwnedConfig(config.codex.home);
|
|
500
|
-
inspectCodexDenyRoot(
|
|
501
|
-
ownedConfig,
|
|
502
|
-
codexTmp,
|
|
503
|
-
dependencies.profileId,
|
|
504
|
-
);
|
|
505
523
|
checks.push(check(
|
|
506
524
|
'codex-tmpdir',
|
|
507
525
|
'ok',
|
|
508
|
-
'
|
|
526
|
+
'Codex child temp directory has owner-only permissions',
|
|
509
527
|
{
|
|
510
528
|
runtime: 'codex',
|
|
511
|
-
|
|
529
|
+
ownerOnly: true,
|
|
512
530
|
source: processEnv.POLYGRAM_CODEX_TMPDIR
|
|
513
531
|
? 'polygram'
|
|
514
532
|
: 'inherited',
|
|
@@ -521,7 +539,7 @@ async function collectCodexDoctorChecks({
|
|
|
521
539
|
'Codex child temp directory is missing, aliased, overlapping, or has unsafe permissions',
|
|
522
540
|
{
|
|
523
541
|
runtime: 'codex',
|
|
524
|
-
|
|
542
|
+
ownerOnly: false,
|
|
525
543
|
code: safeErrorCode(error),
|
|
526
544
|
},
|
|
527
545
|
));
|
|
@@ -8,7 +8,7 @@ const MAX_EFFORTS = 32;
|
|
|
8
8
|
const SHA256_RE = /^[a-f0-9]{64}$/;
|
|
9
9
|
const PREFLIGHT_ACTIONS = Object.freeze({
|
|
10
10
|
CODEX_AUTH_UNAVAILABLE:
|
|
11
|
-
'Check the
|
|
11
|
+
'Check the required CLIProxy route and private bearer configuration, then rerun preflight.',
|
|
12
12
|
CODEX_MODEL_UNAVAILABLE:
|
|
13
13
|
'Choose a model returned by Codex runtime model preflight.',
|
|
14
14
|
CODEX_EFFORT_UNAVAILABLE:
|
|
@@ -382,7 +382,7 @@ function createCodexRuntimeController({
|
|
|
382
382
|
hooks: configured.hooks ?? null,
|
|
383
383
|
access: validateAccess(configured.access),
|
|
384
384
|
proxy: configured.proxy,
|
|
385
|
-
proxyIdentity: readProxy(configured.proxy)
|
|
385
|
+
proxyIdentity: readProxy(configured.proxy).identity,
|
|
386
386
|
commandEnvironment: {
|
|
387
387
|
HOME: processEnv.HOME,
|
|
388
388
|
TMPDIR: processEnv.TMPDIR,
|
|
@@ -557,8 +557,8 @@ function createCodexRuntimeController({
|
|
|
557
557
|
effort: request.effort,
|
|
558
558
|
processEnv,
|
|
559
559
|
sessionLauncher: configured.sessionLauncher,
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
access: configured.access,
|
|
561
|
+
proxy: configured.proxy,
|
|
562
562
|
...(configured.hooks == null ? {} : { hooks: configured.hooks }),
|
|
563
563
|
});
|
|
564
564
|
if (expectedStaticProfile.hookManifest != null) {
|
|
@@ -36,8 +36,7 @@ const {
|
|
|
36
36
|
readProxy,
|
|
37
37
|
} = require('./deployment-policy');
|
|
38
38
|
|
|
39
|
-
const CODEX_PERMISSION_PROFILE_ID =
|
|
40
|
-
const CONTROLLED_PATH = '/usr/bin:/bin';
|
|
39
|
+
const CODEX_PERMISSION_PROFILE_ID = TRUSTED_PROFILE_ID;
|
|
41
40
|
const MAX_PAGES = 16;
|
|
42
41
|
const MAX_PROFILES = 1_000;
|
|
43
42
|
const MAX_STRING_BYTES = 64 * 1024;
|
|
@@ -304,25 +303,16 @@ function buildOwnedConfig({
|
|
|
304
303
|
access,
|
|
305
304
|
proxy,
|
|
306
305
|
}) {
|
|
307
|
-
const
|
|
308
|
-
const profileId = trusted ? TRUSTED_PROFILE_ID : CODEX_PERMISSION_PROFILE_ID;
|
|
309
|
-
const filesystem = {
|
|
310
|
-
':minimal': 'read',
|
|
311
|
-
[codexHome]: 'deny',
|
|
312
|
-
};
|
|
313
|
-
for (const root of [...daemonSecretRoots].sort()) {
|
|
314
|
-
filesystem[root] = 'deny';
|
|
315
|
-
}
|
|
316
|
-
filesystem[':workspace_roots'] = { '.': 'write' };
|
|
306
|
+
const profileId = TRUSTED_PROFILE_ID;
|
|
317
307
|
return {
|
|
318
308
|
cli_auth_credentials_store: 'file',
|
|
319
|
-
model_provider:
|
|
320
|
-
|
|
309
|
+
model_provider: 'cliproxyapi',
|
|
310
|
+
model_providers: { cliproxyapi: proxy.provider },
|
|
321
311
|
default_permissions: profileId,
|
|
322
312
|
approval_policy: 'never',
|
|
323
313
|
approvals_reviewer: 'user',
|
|
324
|
-
web_search:
|
|
325
|
-
|
|
314
|
+
web_search: 'live',
|
|
315
|
+
memories: { generate_memories: false, use_memories: false },
|
|
326
316
|
allow_login_shell: false,
|
|
327
317
|
features: {
|
|
328
318
|
goals: false,
|
|
@@ -333,13 +323,13 @@ function buildOwnedConfig({
|
|
|
333
323
|
set: {
|
|
334
324
|
HOME: commandHome,
|
|
335
325
|
TMPDIR: commandTmp,
|
|
336
|
-
PATH: access
|
|
326
|
+
PATH: access.commandPath,
|
|
337
327
|
},
|
|
338
328
|
},
|
|
339
329
|
permissions: {
|
|
340
330
|
[profileId]: {
|
|
341
|
-
filesystem:
|
|
342
|
-
network: { enabled:
|
|
331
|
+
filesystem: { ':root': 'write' },
|
|
332
|
+
network: { enabled: true },
|
|
343
333
|
},
|
|
344
334
|
},
|
|
345
335
|
projects: {
|
|
@@ -355,7 +345,6 @@ function renderOwnedConfig(config, {
|
|
|
355
345
|
}) {
|
|
356
346
|
const command = config.shell_environment_policy.set;
|
|
357
347
|
const profileId = config.default_permissions;
|
|
358
|
-
const trusted = profileId === TRUSTED_PROFILE_ID;
|
|
359
348
|
const filesystem = config.permissions[profileId].filesystem;
|
|
360
349
|
const lines = [
|
|
361
350
|
'cli_auth_credentials_store = "file"',
|
|
@@ -379,43 +368,27 @@ function renderOwnedConfig(config, {
|
|
|
379
368
|
`PATH = ${tomlString(command.PATH)}`,
|
|
380
369
|
'',
|
|
381
370
|
`[permissions.${tomlKey(profileId)}.filesystem]`,
|
|
382
|
-
|
|
383
|
-
`${tomlKey(':minimal')} = "read"`,
|
|
384
|
-
`${tomlKey(codexHome)} = "deny"`,
|
|
385
|
-
]),
|
|
386
|
-
];
|
|
387
|
-
for (const root of trusted ? [] : [...daemonSecretRoots].sort()) {
|
|
388
|
-
lines.push(`${tomlKey(root)} = "deny"`);
|
|
389
|
-
}
|
|
390
|
-
lines.push(
|
|
391
|
-
...(trusted ? [] : [`${tomlKey(':workspace_roots')} = { "." = "write" }`]),
|
|
371
|
+
`${tomlKey(':root')} = "write"`,
|
|
392
372
|
'',
|
|
393
373
|
`[permissions.${tomlKey(profileId)}.network]`,
|
|
394
|
-
|
|
374
|
+
'enabled = true',
|
|
395
375
|
'',
|
|
396
376
|
`[projects.${tomlKey(workspace)}]`,
|
|
397
377
|
'trust_level = "untrusted"',
|
|
398
378
|
'',
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
lines.push('');
|
|
379
|
+
'[memories]',
|
|
380
|
+
'generate_memories = false',
|
|
381
|
+
'use_memories = false',
|
|
382
|
+
'',
|
|
383
|
+
'[model_providers.cliproxyapi]',
|
|
384
|
+
];
|
|
385
|
+
for (const [key, value] of Object.entries(config.model_providers.cliproxyapi)) {
|
|
386
|
+
lines.push(`${key} = ${typeof value === 'boolean' ? value : tomlString(value)}`);
|
|
409
387
|
}
|
|
388
|
+
lines.push('');
|
|
410
389
|
const hookTables = renderTrustTables(config);
|
|
411
390
|
if (hookTables) lines.push(...hookTables.split('\n'));
|
|
412
|
-
if (
|
|
413
|
-
!trusted && (
|
|
414
|
-
filesystem[':minimal'] !== 'read'
|
|
415
|
-
|| filesystem[codexHome] !== 'deny'
|
|
416
|
-
|| !isDeepStrictEqual(filesystem[':workspace_roots'], { '.': 'write' })
|
|
417
|
-
)
|
|
418
|
-
) {
|
|
391
|
+
if (!isDeepStrictEqual(filesystem, { ':root': 'write' })) {
|
|
419
392
|
throw new Error('owned config rendering invariant failed');
|
|
420
393
|
}
|
|
421
394
|
return lines.join('\n');
|
|
@@ -606,6 +579,75 @@ function inspectInstructionBinding({ codexHome, workspace, required }, create =
|
|
|
606
579
|
return true;
|
|
607
580
|
}
|
|
608
581
|
|
|
582
|
+
function inspectCodexHomeAnchor(options) {
|
|
583
|
+
assertDedicatedInstructionHome(options);
|
|
584
|
+
const anchor = requiredString(options.codexHome, 'credential home');
|
|
585
|
+
if (!path.isAbsolute(anchor) || path.normalize(anchor) !== anchor
|
|
586
|
+
|| canonicalTemporaryRoots().some((root) => isWithin(root, anchor))) {
|
|
587
|
+
throw fail('Codex home anchor must be canonical and persistent.', 'CODEX_HOME_UNSAFE',
|
|
588
|
+
'Configure an owner-only persistent Codex home anchor.');
|
|
589
|
+
}
|
|
590
|
+
assertSafeParentChain(path.dirname(anchor), 'home anchor');
|
|
591
|
+
if (realpathSync(path.dirname(anchor)) !== path.dirname(anchor)) throw instructionBindingDrift();
|
|
592
|
+
let boundWorkspace = null;
|
|
593
|
+
if (inspectOptionalPath(anchor)) {
|
|
594
|
+
assertOwnedMode(anchor, { code: 'CODEX_HOME_UNSAFE', kind: 'home anchor', expectedMode: 0o700, directory: true });
|
|
595
|
+
assertSafeParentChain(anchor, 'home anchor');
|
|
596
|
+
for (const file of ['auth.json', 'config.toml']) {
|
|
597
|
+
if (inspectOptionalPath(path.join(anchor, file))) {
|
|
598
|
+
assertOwnedMode(path.join(anchor, file), { code: 'CODEX_HOME_UNSAFE', kind: file,
|
|
599
|
+
expectedMode: 0o600, directory: false });
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (inspectOptionalPath(path.join(anchor, 'AGENTS.override.md'))) throw instructionBindingDrift();
|
|
603
|
+
const link = path.join(anchor, 'AGENTS.md');
|
|
604
|
+
if (inspectOptionalPath(link)) {
|
|
605
|
+
const stat = lstatSync(link);
|
|
606
|
+
if (!stat.isSymbolicLink() || stat.uid !== process.getuid?.()) throw instructionBindingDrift();
|
|
607
|
+
const target = path.resolve(anchor, readlinkSync(link));
|
|
608
|
+
if (path.basename(target) !== 'AGENTS.md') throw instructionBindingDrift();
|
|
609
|
+
boundWorkspace = path.dirname(target);
|
|
610
|
+
inspectInstructionBinding({ codexHome: anchor, workspace: boundWorkspace, required: true });
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return Object.freeze({ anchor, boundWorkspace });
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function selectCodexWorkspaceHome(options, { create = false, requireBinding = false } = {}) {
|
|
617
|
+
const { anchor, boundWorkspace } = inspectCodexHomeAnchor(options);
|
|
618
|
+
const workspace = canonicalDirectory(options.workspace, 'workspace');
|
|
619
|
+
let codexHome = anchor;
|
|
620
|
+
if (boundWorkspace !== workspace) {
|
|
621
|
+
const container = `${anchor}.workspaces`;
|
|
622
|
+
if (!inspectOptionalPath(container) && create) {
|
|
623
|
+
try { mkdirSync(container, { mode: 0o700 }); }
|
|
624
|
+
catch (error) {
|
|
625
|
+
if (error.code !== 'EEXIST') {
|
|
626
|
+
throw fail('Codex workspace homes could not be provisioned.', 'CODEX_HOME_UNSAFE',
|
|
627
|
+
'Provision a canonical owner-only workspace-home container.', error);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (inspectOptionalPath(container)) {
|
|
632
|
+
assertOwnedMode(container, { code: 'CODEX_HOME_UNSAFE', kind: 'workspace homes', expectedMode: 0o700, directory: true });
|
|
633
|
+
assertSafeParentChain(container, 'workspace homes');
|
|
634
|
+
if (realpathSync(container) !== container) throw instructionBindingDrift();
|
|
635
|
+
}
|
|
636
|
+
codexHome = path.join(container, digest(workspace));
|
|
637
|
+
}
|
|
638
|
+
assertDedicatedInstructionHome({ ...options, codexHome });
|
|
639
|
+
if (inspectOptionalPath(codexHome)) {
|
|
640
|
+
assertOwnedMode(codexHome, { code: 'CODEX_HOME_UNSAFE', kind: 'workspace home', expectedMode: 0o700, directory: true });
|
|
641
|
+
assertSafeParentChain(codexHome, 'workspace home');
|
|
642
|
+
if (realpathSync(codexHome) !== codexHome) throw instructionBindingDrift();
|
|
643
|
+
}
|
|
644
|
+
if (requireBinding || inspectOptionalPath(path.join(codexHome, 'AGENTS.md'))
|
|
645
|
+
|| inspectOptionalPath(path.join(codexHome, 'AGENTS.override.md'))) {
|
|
646
|
+
inspectInstructionBinding({ codexHome, workspace, required: true });
|
|
647
|
+
}
|
|
648
|
+
return Object.freeze({ codexHome, anchor, boundWorkspace });
|
|
649
|
+
}
|
|
650
|
+
|
|
609
651
|
function provisionRuntimeFiles(options, temporaryRoots) {
|
|
610
652
|
const access = validateAccess(options.access);
|
|
611
653
|
const proxy = readProxy(options.proxy);
|
|
@@ -662,13 +704,7 @@ function provisionRuntimeFiles(options, temporaryRoots) {
|
|
|
662
704
|
assertSafeParentChain(codexHome, 'credential home');
|
|
663
705
|
assertRootSeparation(codexHome, workspace, daemonSecretRoots);
|
|
664
706
|
|
|
665
|
-
const commandHome =
|
|
666
|
-
? canonicalDirectory((options.processEnv ?? process.env).HOME, 'command HOME')
|
|
667
|
-
: ensurePrivateDirectory(
|
|
668
|
-
path.join(workspace, '.codex-command-home'),
|
|
669
|
-
'CODEX_COMMAND_DIR_UNSAFE',
|
|
670
|
-
'command HOME',
|
|
671
|
-
);
|
|
707
|
+
const commandHome = canonicalDirectory((options.processEnv ?? process.env).HOME, 'command HOME');
|
|
672
708
|
const commandTmp = ensurePrivateDirectory(
|
|
673
709
|
path.join(workspace, '.codex-command-tmp'),
|
|
674
710
|
'CODEX_COMMAND_DIR_UNSAFE',
|
|
@@ -1199,8 +1235,9 @@ function createCodexRuntimeProfileBuilder({
|
|
|
1199
1235
|
'Restore the exact root-owned session launcher before enabling Codex.',
|
|
1200
1236
|
);
|
|
1201
1237
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1238
|
+
const homeSelection = selectCodexWorkspaceHome(options, { create: true });
|
|
1239
|
+
const selectionOptions = { codexHome: options.codexHome, workspace: options.workspace, processEnv: options.processEnv };
|
|
1240
|
+
let materialized = provisionRuntimeFiles({ ...options, codexHome: homeSelection.codexHome }, temporaryRoots);
|
|
1204
1241
|
let hookMaterial = null;
|
|
1205
1242
|
if (options.hooks == null) {
|
|
1206
1243
|
provisionBaseConfig(materialized);
|
|
@@ -1256,7 +1293,8 @@ function createCodexRuntimeProfileBuilder({
|
|
|
1256
1293
|
clientFactory,
|
|
1257
1294
|
hookManifest: materialized.hookManifest ?? null,
|
|
1258
1295
|
});
|
|
1259
|
-
if (
|
|
1296
|
+
if (!isDeepStrictEqual(selectCodexWorkspaceHome(selectionOptions), homeSelection)
|
|
1297
|
+
|| inspectInstructionBinding(instructionBinding) !== instructionsPresent) {
|
|
1260
1298
|
throw instructionBindingDrift();
|
|
1261
1299
|
}
|
|
1262
1300
|
const model = requiredString(options.model, 'model');
|
|
@@ -1290,7 +1328,7 @@ function createCodexRuntimeProfileBuilder({
|
|
|
1290
1328
|
hookArtifactsSha256: materialized.hookArtifactsSha256,
|
|
1291
1329
|
}),
|
|
1292
1330
|
});
|
|
1293
|
-
instructionProfiles.set(profile, { ...instructionBinding, present: instructionsPresent });
|
|
1331
|
+
instructionProfiles.set(profile, { ...instructionBinding, present: instructionsPresent, homeSelection, selectionOptions });
|
|
1294
1332
|
if (hookMaterial != null) {
|
|
1295
1333
|
hookProfiles.set(profile, Object.freeze({
|
|
1296
1334
|
hookOptions: Object.freeze({ ...options.hooks }),
|
|
@@ -1302,7 +1340,9 @@ function createCodexRuntimeProfileBuilder({
|
|
|
1302
1340
|
},
|
|
1303
1341
|
reattest(profile) {
|
|
1304
1342
|
const instructions = instructionProfiles.get(profile);
|
|
1305
|
-
if (!instructions ||
|
|
1343
|
+
if (!instructions || !isDeepStrictEqual(
|
|
1344
|
+
selectCodexWorkspaceHome(instructions.selectionOptions), instructions.homeSelection,
|
|
1345
|
+
) || profile.cwd !== instructions.workspace
|
|
1306
1346
|
|| profile.codexHome !== instructions.codexHome
|
|
1307
1347
|
|| inspectInstructionBinding(instructions) !== instructions.present) {
|
|
1308
1348
|
throw instructionBindingDrift();
|
|
@@ -1333,6 +1373,8 @@ async function prepareCodexRuntimeProfile(options) {
|
|
|
1333
1373
|
|
|
1334
1374
|
module.exports = {
|
|
1335
1375
|
CODEX_PERMISSION_PROFILE_ID,
|
|
1376
|
+
selectCodexWorkspaceHome,
|
|
1377
|
+
inspectCodexHomeAnchor,
|
|
1336
1378
|
CodexRuntimeProfileError,
|
|
1337
1379
|
createCodexRuntimeProfileBuilder,
|
|
1338
1380
|
normalizeDeniedRoots,
|
|
@@ -384,7 +384,7 @@ function createFormatConfigInfoText({
|
|
|
384
384
|
// button to live on.
|
|
385
385
|
let body = '⚙️ Settings';
|
|
386
386
|
if (codex) {
|
|
387
|
-
body += '\n\n_Codex
|
|
387
|
+
body += '\n\n_Codex uses CLIProxy with service-user filesystem access, command network and web search. No product MCP tools '
|
|
388
388
|
+ 'or interactive approvals. Detached/background servers are unsupported '
|
|
389
389
|
+ 'and may survive hard runtime loss. '
|
|
390
390
|
+ 'Native goals are currently disabled._';
|
package/lib/prompt.js
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* Telegram payload → polygram DB → unresolvable marker.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const { validateAccess } = require('./codex/deployment-policy');
|
|
9
|
-
|
|
10
8
|
const {
|
|
11
9
|
requireCodexEnabled,
|
|
12
10
|
resolveRuntimeDescriptor,
|
|
@@ -37,11 +35,9 @@ function resolvePromptBackend({ config, chatId, threadId = null }) {
|
|
|
37
35
|
*
|
|
38
36
|
* @param {{ stickerEmojis?: string[], backend?: 'sdk'|'cli'|'codex' }} [opts]
|
|
39
37
|
*/
|
|
40
|
-
function polygramInfo({ stickerEmojis = [], backend = 'sdk'
|
|
38
|
+
function polygramInfo({ stickerEmojis = [], backend = 'sdk' } = {}) {
|
|
41
39
|
const hasStickers = stickerEmojis.length > 0;
|
|
42
|
-
const codexPolicy =
|
|
43
|
-
? 'This trusted Codex profile has the service user’s filesystem rights, including access to credentials; command network and model-native web search are enabled.'
|
|
44
|
-
: 'This is a native Codex beta: command network and model-native web search are disabled.';
|
|
40
|
+
const codexPolicy = 'This Codex profile uses CLIProxy and has the service user’s filesystem rights, including access to credentials; command network and model-native web search are enabled.';
|
|
45
41
|
const deliveryContract = backend === 'cli'
|
|
46
42
|
? `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.`
|
|
47
43
|
: backend === 'codex'
|
|
@@ -223,7 +219,7 @@ function buildVoiceTags(attachments) {
|
|
|
223
219
|
* @param {Object} params.replyTo - input for buildReplyToBlock (optional)
|
|
224
220
|
* @param {'sdk'|'cli'|'codex'} params.backend - delivery contract for the selected process backend
|
|
225
221
|
*/
|
|
226
|
-
function buildPrompt({ msg, topicName = '', sessionCtx = '', attachments = [], replyTo = null, polygramHistory = '', stickerEmojis = [], backend = 'sdk'
|
|
222
|
+
function buildPrompt({ msg, topicName = '', sessionCtx = '', attachments = [], replyTo = null, polygramHistory = '', stickerEmojis = [], backend = 'sdk' }) {
|
|
227
223
|
const chatId = msg.chat.id.toString();
|
|
228
224
|
const msgId = msg.message_id.toString();
|
|
229
225
|
const user = msg.from?.first_name || msg.from?.username || 'Unknown';
|
|
@@ -247,7 +243,7 @@ function buildPrompt({ msg, topicName = '', sessionCtx = '', attachments = [], r
|
|
|
247
243
|
if (polygramHistory) {
|
|
248
244
|
prompt += polygramHistory + '\n\n';
|
|
249
245
|
}
|
|
250
|
-
prompt += `<polygram-info>${polygramInfo({ stickerEmojis, backend
|
|
246
|
+
prompt += `<polygram-info>${polygramInfo({ stickerEmojis, backend })}</polygram-info>\n\n`;
|
|
251
247
|
|
|
252
248
|
const replyBlock = buildReplyToBlock(replyTo);
|
|
253
249
|
const attachmentTags = buildAttachmentTags(attachments);
|
package/lib/runtime-config.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
const { createHash } = require('crypto');
|
|
14
14
|
const { pickBackend } = require('@shumkov/orchestra');
|
|
15
15
|
const { resolveBoolOverride } = require('./config-override');
|
|
16
|
-
const { accessAllowsChat } = require('./codex/deployment-policy');
|
|
17
16
|
|
|
18
17
|
const PM_DESCRIPTORS = Object.freeze({
|
|
19
18
|
sdk: Object.freeze({
|
|
@@ -96,7 +95,7 @@ class RuntimeConfigError extends Error {
|
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
function resolveCodexEnabled(config, chatId, threadId = null) {
|
|
99
|
-
return
|
|
98
|
+
return resolveBoolOverride(
|
|
100
99
|
config,
|
|
101
100
|
'codexEnabled',
|
|
102
101
|
chatId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polygram",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.3",
|
|
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": {
|
package/polygram.js
CHANGED
|
@@ -623,7 +623,6 @@ function formatPrompt(msg, sessionCtx, attachments = [], { sessionKey = null } =
|
|
|
623
623
|
replyTo: resolveReplyTo(msg),
|
|
624
624
|
polygramHistory: polygramHistory + (notificationService?.context(sessionKey, msg.reply_to_message?.message_id) || '') + (notificationService?.instructions(sessionKey) || '') + (mailboxService?.instructions(sessionKey) || ''),
|
|
625
625
|
backend: resolvePromptBackend({ config, chatId, threadId }),
|
|
626
|
-
codexAccess: config.codex?.access,
|
|
627
626
|
// Only advertise stickers this bot actually has — empty for a bot with no
|
|
628
627
|
// sticker set, so its prompt never mentions stickers.
|
|
629
628
|
stickerEmojis: Object.keys(emojiToSticker),
|