@flinbein/pappai-runner-codex 0.1.5 → 0.1.7
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/README.md +11 -1
- package/package.json +2 -1
- package/scripts/upgrade-thread-tools.mjs +73 -0
- package/src/policy.mjs +7 -4
- package/src/tools.mjs +3 -2
package/README.md
CHANGED
|
@@ -22,6 +22,14 @@ The runner requires a pappai controller that supports PROFILE nodes and administ
|
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## Updating an existing registration
|
|
26
|
+
|
|
27
|
+
Find the installed entry point with `$.runners.get({})` on the workspace. Wait for active Codex turns to finish, then use the administrator terminal to install the desired package version under the same npm prefix as the registered entry point. For example, for an entry point under `/run/pappai/private/runners/node_modules/`, use `npm install --prefix /run/pappai/private/runners --omit=dev --ignore-scripts --save-exact @flinbein/pappai-runner-codex@VERSION`. Replace `VERSION` with the release number.
|
|
28
|
+
|
|
29
|
+
Call `$.runners.restart({"name":"codex"})` on the workspace to load the installed package with its saved configuration. Restart affects all active Codex workers. Use the same procedure with the previous package version to roll back.
|
|
30
|
+
|
|
31
|
+
When upgrading a persistent session from the `pappai_dir` tool on Codex CLI 0.170.0, stop the controller, back up the runner state directory and run `node <installed-package>/scripts/upgrade-thread-tools.mjs <app-state>` for each persistent APP state directory before starting the new controller. Codex stores dynamic tool definitions at thread creation. The script updates the discovery name and help signature in stored rollout metadata and the SQLite index. It replaces each rollout atomically, preserving all conversation records after the header. A repeated invocation reports zero updates. Restore the backup if rolling back both packages. Fresh installations and one-shot APPs can skip this step.
|
|
32
|
+
|
|
25
33
|
## First call
|
|
26
34
|
|
|
27
35
|
1. Call `$.profile.create` on the workspace or a TEAM with a name and permissions. Save the returned ID.
|
|
@@ -38,7 +46,9 @@ A persistent APP can also declare `agent.getHistory` and `agent.interrupt` under
|
|
|
38
46
|
|
|
39
47
|
## Executor permissions
|
|
40
48
|
|
|
41
|
-
The executor runs in an isolated directory. Its connection to the model is a service channel. For workspace operations, the model receives the `
|
|
49
|
+
The executor runs in an isolated directory. Its connection to the model is a service channel. For workspace operations, the model receives the `pappai_discover`, `pappai_help`, `pappai_call` and `pappai_publish` tools. Use `pappai_help({node, features:true})` to list the full catalog. Omit `features` for the top level, or select names and request `doc:true` and `schema:true` for details. Each entry has a type and version. The controller authorizes calls as the assigned APP using its effective permissions. The PROFILE supplies the model credentials, and its scope controls which APPs may use them.
|
|
50
|
+
|
|
51
|
+
Workers support Code Mode. For example, `functions.exec` can run `text(await tools.pappai_discover({}))`. Keep the native `bin/codex-code-mode-host` beside `bin/codex` in the trusted CLI distribution. The runner mounts that helper read-only for APP workers. The separate credential refresh process keeps Code Mode disabled. The helper shares the app-server's network namespace. The JavaScript environment exposes the selected tools, and nested pappai calls undergo the usual controller permission checks.
|
|
42
52
|
|
|
43
53
|
Shell, native Codex file tools and user configuration from the working directory are disabled. Use `run.settings` to select the model, reasoning effort and developer instructions. The administrator sets the CLI and storage paths when registering the runner.
|
|
44
54
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flinbein/pappai-runner-codex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Codex app-server runner for pappai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"src/",
|
|
12
|
+
"scripts/upgrade-thread-tools.mjs",
|
|
12
13
|
"examples/",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Offline upgrade for the rollout headers and optional tool index of Codex CLI 0.170.0.
|
|
2
|
+
import { createReadStream } from 'node:fs'
|
|
3
|
+
import { lstat, open, readdir, rename, rm } from 'node:fs/promises'
|
|
4
|
+
import { randomUUID } from 'node:crypto'
|
|
5
|
+
import { dirname, join, resolve } from 'node:path'
|
|
6
|
+
import { pipeline } from 'node:stream/promises'
|
|
7
|
+
import { DatabaseSync } from 'node:sqlite'
|
|
8
|
+
import { pathToFileURL } from 'node:url'
|
|
9
|
+
import { dynamicTools } from '../src/tools.mjs'
|
|
10
|
+
|
|
11
|
+
const replacements = new Map(['pappai_discover','pappai_help'].map(name => [
|
|
12
|
+
name === 'pappai_discover' ? 'pappai_dir' : name, dynamicTools.find(tool => tool.name === name),
|
|
13
|
+
]))
|
|
14
|
+
|
|
15
|
+
async function upgradeRollout(file) {
|
|
16
|
+
// Preserve the conversation byte for byte after the session metadata line.
|
|
17
|
+
let header = Buffer.alloc(0)
|
|
18
|
+
const chunk = Buffer.alloc(16384)
|
|
19
|
+
const input = await open(file,'r')
|
|
20
|
+
let end
|
|
21
|
+
try {
|
|
22
|
+
while ((end = header.indexOf(10)) < 0) {
|
|
23
|
+
const {bytesRead} = await input.read(chunk)
|
|
24
|
+
if (!bytesRead || header.length > 4 * 1024 * 1024) throw Error('Invalid rollout metadata')
|
|
25
|
+
header = Buffer.concat([header,chunk.subarray(0,bytesRead)])
|
|
26
|
+
}
|
|
27
|
+
} finally { await input.close() }
|
|
28
|
+
const record = JSON.parse(header.subarray(0,end))
|
|
29
|
+
const tools = record.payload?.dynamic_tools
|
|
30
|
+
if (record.type !== 'session_meta') throw Error('Expected session metadata')
|
|
31
|
+
if (!tools?.some(tool => tool.name === 'pappai_dir' && !tool.namespace)) return 0
|
|
32
|
+
for (const [name, replacement] of replacements) {
|
|
33
|
+
const tool = tools.find(tool => tool.name === name && !tool.namespace)
|
|
34
|
+
if (!tool) throw Error('Incomplete thread tool catalog')
|
|
35
|
+
Object.assign(tool,replacement)
|
|
36
|
+
}
|
|
37
|
+
const temporary = join(dirname(file),'.upgrade-' + randomUUID())
|
|
38
|
+
const target = await open(temporary,'wx',0o600)
|
|
39
|
+
try {
|
|
40
|
+
await target.writeFile(JSON.stringify(record) + '\n')
|
|
41
|
+
await pipeline(createReadStream(file,{start:end+1}),target.createWriteStream())
|
|
42
|
+
await rename(temporary,file)
|
|
43
|
+
} finally { await target.close(); await rm(temporary,{force:true}) }
|
|
44
|
+
return 1
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function upgradeThreadTools(state) {
|
|
48
|
+
const sessions = join(state,'sessions')
|
|
49
|
+
let updated = 0
|
|
50
|
+
for (const item of await readdir(sessions,{recursive:true,withFileTypes:true})) {
|
|
51
|
+
if (item.isFile() && /^rollout-.*\.jsonl$/.test(item.name))
|
|
52
|
+
updated += await upgradeRollout(join(item.parentPath,item.name))
|
|
53
|
+
}
|
|
54
|
+
const file = join(state,'sqlite','state_5.sqlite')
|
|
55
|
+
if (!(await lstat(file)).isFile()) throw Error('Expected an existing Codex state database')
|
|
56
|
+
const db = new DatabaseSync(file)
|
|
57
|
+
try {
|
|
58
|
+
db.exec('BEGIN IMMEDIATE')
|
|
59
|
+
const legacy = db.prepare("SELECT thread_id FROM thread_dynamic_tools WHERE name='pappai_dir' AND namespace IS NULL").all()
|
|
60
|
+
const update = db.prepare('UPDATE thread_dynamic_tools SET name=?, description=?, input_schema=? WHERE thread_id=? AND name=? AND namespace IS NULL')
|
|
61
|
+
for (const {thread_id} of legacy) {
|
|
62
|
+
for (const [oldName, tool] of replacements) {
|
|
63
|
+
if (update.run(tool.name,tool.description,JSON.stringify(tool.inputSchema),thread_id,oldName).changes !== 1)
|
|
64
|
+
throw Error('Unexpected persistent thread tool catalog')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
db.exec('COMMIT')
|
|
68
|
+
return updated
|
|
69
|
+
} finally { db.close() }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href)
|
|
73
|
+
console.log('Updated persistent tool catalogs:', await upgradeThreadTools(process.argv[2]))
|
package/src/policy.mjs
CHANGED
|
@@ -35,7 +35,7 @@ async function privateDir(path) {
|
|
|
35
35
|
return path;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function configToml(modelBaseUrl) {
|
|
38
|
+
function configToml(modelBaseUrl, codeMode) {
|
|
39
39
|
const lines = [
|
|
40
40
|
'approval_policy="never"', 'default_permissions="pappai"', 'web_search="disabled"',
|
|
41
41
|
'cli_auth_credentials_store="file"', 'mcp_oauth_credentials_store="file"',
|
|
@@ -54,7 +54,8 @@ function configToml(modelBaseUrl) {
|
|
|
54
54
|
return [...lines,
|
|
55
55
|
'[permissions.pappai.filesystem]', '"/work"="read"', '"/state"="deny"', '"/proc"="deny"',
|
|
56
56
|
'[permissions.pappai.network]', 'enabled=false',
|
|
57
|
-
'[features]',
|
|
57
|
+
'[features]', `code_mode=${codeMode}`, `code_mode_host=${codeMode}`,
|
|
58
|
+
...['apps','browser_use','browser_use_external',
|
|
58
59
|
'computer_use','goals','hooks','image_generation','in_app_browser','memories','multi_agent_v2',
|
|
59
60
|
'plugins','remote_plugin','shell_snapshot','shell_tool','skill_search','unified_exec','view_image',
|
|
60
61
|
'workspace_dependencies'].map(key => `${key}=false`),
|
|
@@ -68,19 +69,20 @@ function configToml(modelBaseUrl) {
|
|
|
68
69
|
async function namespace(config, state, profileOwner, mcp) {
|
|
69
70
|
const binary = await canonicalFile(config.codexExecutablePath, 'Codex executable');
|
|
70
71
|
const bwrap = await canonicalFile(join(dirname(dirname(binary)), 'codex-resources', 'bwrap'), 'bundled Codex bubblewrap');
|
|
72
|
+
const codeModeHost = profileOwner ? null : await canonicalFile(join(dirname(binary), 'codex-code-mode-host'), 'bundled Codex Code Mode host');
|
|
71
73
|
const mounts = (await readFile('/proc/self/mountinfo', 'utf8')).trim().split('\n').map(line => {
|
|
72
74
|
const fields = line.split(' ');
|
|
73
75
|
const target = fields[4].replace(/\\([0-7]{3})/g, (_, octal) => String.fromCharCode(parseInt(octal, 8)));
|
|
74
76
|
return {target, readonly:fields[5].split(',').includes('ro')};
|
|
75
77
|
});
|
|
76
|
-
if (![binary,bwrap].every(path => protectedBinary(path,mounts))) {
|
|
78
|
+
if (![binary,bwrap,...(codeModeHost ? [codeModeHost] : [])].every(path => protectedBinary(path,mounts))) {
|
|
77
79
|
throw Error('Codex distribution must be on a read-only mount or below /run/pappai/private');
|
|
78
80
|
}
|
|
79
81
|
if (typeof config.stateDir !== 'string' || !config.stateDir.startsWith('/run/pappai/private/')) {
|
|
80
82
|
throw new Error('Runner state must be below /run/pappai/private');
|
|
81
83
|
}
|
|
82
84
|
const root = await privateDir(config.stateDir);
|
|
83
|
-
const toml = configToml(config.modelBaseUrl);
|
|
85
|
+
const toml = configToml(config.modelBaseUrl, codeModeHost !== null);
|
|
84
86
|
const run = await mkdtemp(join(root, 'run-'));
|
|
85
87
|
const cleanup = () => rm(run, { recursive: true, force: true });
|
|
86
88
|
try {
|
|
@@ -96,6 +98,7 @@ async function namespace(config, state, profileOwner, mcp) {
|
|
|
96
98
|
'--die-with-parent', '--new-session', '--dev', '/dev', '--proc', '/proc', '--tmpfs', '/tmp',
|
|
97
99
|
'--dir', work, '--tmpfs', '/state', '--dir', home, '--dir', '/state/home', '--ro-bind', binary, cliPath,
|
|
98
100
|
'--ro-bind', bwrap, '/opt/codex/bin/bwrap'];
|
|
101
|
+
if (codeModeHost) args.push('--ro-bind', codeModeHost, '/opt/codex/bin/codex-code-mode-host');
|
|
99
102
|
if (profileOwner) args.push('--bind', dirname(profileOwner.authPath), home);
|
|
100
103
|
args.push('--ro-bind', configFile, home + '/config.toml', '--ro-bind', requirements, '/etc/codex/requirements.toml');
|
|
101
104
|
for (const path of ['/etc/resolv.conf','/etc/hosts','/etc/ssl/certs/ca-certificates.crt']) {
|
package/src/tools.mjs
CHANGED
|
@@ -2,8 +2,9 @@ const string = {type:'string'}
|
|
|
2
2
|
const filter = {anyOf:[string,{type:'array',items:string}]}
|
|
3
3
|
const timeoutMs = {type:'integer',minimum:1,maximum:86400000}
|
|
4
4
|
const definitions = [
|
|
5
|
-
['
|
|
6
|
-
['help','Read the public contract of a visible node.',{node:string,
|
|
5
|
+
['discover','List workspace nodes visible to this APP.',{},[]],
|
|
6
|
+
['help','Read the public contract of a visible node.',{node:string,
|
|
7
|
+
features:{anyOf:[...filter.anyOf,{const:true}]}, description:{type:'boolean'}, schema:{type:'boolean'}, doc:{type:'boolean'}},['node']],
|
|
7
8
|
['call','Call a permitted method on a pappai node.',{node:string,method:string,data:{},version:string,timeoutMs},['node','method']],
|
|
8
9
|
['publish','Publish a declared event as this APP.',{event:string,data:{},version:string,to:filter,
|
|
9
10
|
delivery:{enum:['none','status']},timeoutMs},['event']],
|