@commonlyai/cli 0.1.290 → 0.1.292
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/package.json +1 -1
- package/src/commands/agent.js +12 -6
- package/src/commands/dev.js +13 -517
- package/src/lib/adapters/claude.js +13 -10
- package/src/lib/adapters/codex.js +11 -4
- package/src/lib/adapters/goose.js +11 -5
- package/src/lib/adapters/opencode.js +5 -5
- package/src/lib/adapters/pi-mcp-client.mjs +2 -2
- package/src/lib/adapters/pi.js +14 -10
- package/src/lib/adapters/qwen.js +20 -11
- package/src/lib/memory-bridge.js +15 -10
- package/src/lib/public-withheld-tools.js +16 -1
- package/src/lib/spawn-credential.js +33 -6
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -29,6 +29,7 @@ import { createClient } from '../lib/api.js';
|
|
|
29
29
|
import {
|
|
30
30
|
buildSpawnId,
|
|
31
31
|
createSpawnCredentialLease,
|
|
32
|
+
turnEventIds,
|
|
32
33
|
readSpawnPolicy,
|
|
33
34
|
resolveSpawnTtlSeconds,
|
|
34
35
|
revokeOrphanedSpawnCredentials,
|
|
@@ -2829,12 +2830,13 @@ export const performRun = ({
|
|
|
2829
2830
|
// The adapter also denies the memory tools for it (memoryWithheld).
|
|
2830
2831
|
const memoryWithheld = Boolean(placement.reason);
|
|
2831
2832
|
const memoryLongTerm = memoryWithheld ? undefined : await readLongTerm(client, { onError });
|
|
2832
|
-
// F118: a public seat reads its memory
|
|
2833
|
-
// its own output, which a stranger in the pod can
|
|
2834
|
-
//
|
|
2835
|
-
//
|
|
2836
|
-
|
|
2837
|
-
|
|
2833
|
+
// F118: a public seat reads its memory, and its summary is never synced
|
|
2834
|
+
// back: that summary is its own output, which a stranger in the pod can
|
|
2835
|
+
// steer. Its memory tools are withheld unless the kernel says the owner woke
|
|
2836
|
+
// this turn (F145). A workspace seat's public turn is covered by
|
|
2837
|
+
// memoryWithheld too, and never gets them.
|
|
2838
|
+
const publicSeat = effectiveSandboxTrust(placement.environment?.sandbox?.trust) === 'public';
|
|
2839
|
+
const memoryWriteWithheld = memoryWithheld || publicSeat;
|
|
2838
2840
|
|
|
2839
2841
|
// TASK-129: focus is a turn-start read, not an enqueue-time
|
|
2840
2842
|
// snapshot. Read through the authorized runtime context route immediately
|
|
@@ -2924,6 +2926,9 @@ export const performRun = ({
|
|
|
2924
2926
|
spawnId: buildSpawnId({ agentName, eventId: event?._id || event?.payload?.batchEventIds || null }),
|
|
2925
2927
|
desiredTtlSeconds: spawnCredentialTtlSeconds,
|
|
2926
2928
|
policy: spawnPolicyOrNull === null ? null : await spawnPolicyOrNull,
|
|
2929
|
+
// F145: the kernel decides from these rows whether the owner woke the
|
|
2930
|
+
// turn. No events means no: a turn that withholds memory asks for nothing.
|
|
2931
|
+
...(publicSeat ? { publicSeat: true, eventIds: memoryWithheld ? [] : turnEventIds(event) } : {}),
|
|
2927
2932
|
log,
|
|
2928
2933
|
});
|
|
2929
2934
|
let opened;
|
|
@@ -3020,6 +3025,7 @@ export const performRun = ({
|
|
|
3020
3025
|
environment: placement.environment,
|
|
3021
3026
|
// Only when set, so every other spawn context stays as it was.
|
|
3022
3027
|
...(hostUnconfined === true ? { hostUnconfined: true } : {}),
|
|
3028
|
+
...(publicSeat && !memoryWithheld && opened.ownerWoken === true ? { ownerWoken: true } : {}),
|
|
3023
3029
|
onSkillsLinked: ({ mounted, conflicted }) => {
|
|
3024
3030
|
skillMount = {
|
|
3025
3031
|
mounted: [...new Set([...serverSkills.mounted, ...mounted.map(reportedSkillName)])],
|
package/src/commands/dev.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* commonly dev <subcommand>
|
|
3
3
|
*
|
|
4
4
|
* up — start local Commonly instance (wraps ./dev.sh up)
|
|
5
|
-
* clawdbot —
|
|
5
|
+
* clawdbot — refuses: the local OpenClaw gateway was retired (ADR-021 Part B)
|
|
6
6
|
* down — stop local instance
|
|
7
7
|
* logs — tail local instance logs
|
|
8
8
|
* test — run backend tests
|
|
@@ -10,46 +10,11 @@
|
|
|
10
10
|
* Sets --instance http://localhost:5000 automatically after `dev up`.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { randomBytes } from 'crypto';
|
|
14
13
|
import { spawnSync, spawn } from 'child_process';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
existsSync,
|
|
18
|
-
mkdirSync,
|
|
19
|
-
readFileSync,
|
|
20
|
-
writeFileSync,
|
|
21
|
-
} from 'fs';
|
|
22
|
-
import { dirname, isAbsolute, join } from 'path';
|
|
14
|
+
import { existsSync } from 'fs';
|
|
15
|
+
import { join } from 'path';
|
|
23
16
|
import { saveInstance, getToken, LOCAL_URL } from '../lib/config.js';
|
|
24
|
-
import { createClient
|
|
25
|
-
|
|
26
|
-
const CLAWDBOT_AGENT_NAME = 'openclaw';
|
|
27
|
-
const CLAWDBOT_DEFAULT_INSTANCE_ID = 'local';
|
|
28
|
-
const CLAWDBOT_DEFAULT_DISPLAY_NAME = 'Local OpenClaw';
|
|
29
|
-
const CLAWDBOT_DEFAULT_POD_NAME = 'Local OpenClaw Sandbox';
|
|
30
|
-
const CLAWDBOT_CONFIG_RELATIVE_PATH = join('external', 'clawdbot-state', 'config', 'moltbot.json');
|
|
31
|
-
const LOCAL_ENV_FILE = '.env';
|
|
32
|
-
const LOCAL_ENV_EXAMPLE_FILE = '.env.example';
|
|
33
|
-
const LOCAL_LOGIN_DEFAULTS = {
|
|
34
|
-
email: 'dev@commonly.local',
|
|
35
|
-
password: 'password123',
|
|
36
|
-
username: 'localdev',
|
|
37
|
-
};
|
|
38
|
-
const CLAWDBOT_INSTALL_SCOPES = [
|
|
39
|
-
'context:read',
|
|
40
|
-
'messages:read',
|
|
41
|
-
'messages:write',
|
|
42
|
-
'memory:read',
|
|
43
|
-
'memory:write',
|
|
44
|
-
];
|
|
45
|
-
const CLAWDBOT_USER_TOKEN_SCOPES = [
|
|
46
|
-
'agent:events:read',
|
|
47
|
-
'agent:events:ack',
|
|
48
|
-
'agent:context:read',
|
|
49
|
-
'agent:messages:read',
|
|
50
|
-
'agent:messages:write',
|
|
51
|
-
];
|
|
52
|
-
const TRUTHY_ENV_VALUES = new Set(['1', 'true', 'yes', 'on']);
|
|
17
|
+
import { createClient } from '../lib/api.js';
|
|
53
18
|
|
|
54
19
|
const findDevSh = (startDir = process.cwd()) => {
|
|
55
20
|
let dir = startDir;
|
|
@@ -63,11 +28,6 @@ const findDevSh = (startDir = process.cwd()) => {
|
|
|
63
28
|
return null;
|
|
64
29
|
};
|
|
65
30
|
|
|
66
|
-
const findRepoRoot = (startDir = process.cwd()) => {
|
|
67
|
-
const devSh = findDevSh(startDir);
|
|
68
|
-
return devSh ? dirname(devSh) : null;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
31
|
const runDevSh = (args, opts = {}) => {
|
|
72
32
|
const devSh = findDevSh();
|
|
73
33
|
if (!devSh) {
|
|
@@ -87,83 +47,6 @@ const runDevSh = (args, opts = {}) => {
|
|
|
87
47
|
return spawnSync('bash', [devSh, ...args], spawnOpts);
|
|
88
48
|
};
|
|
89
49
|
|
|
90
|
-
export const isTruthyEnvValue = (value) => TRUTHY_ENV_VALUES.has(String(value || '').trim().toLowerCase());
|
|
91
|
-
|
|
92
|
-
const normalizeEnvValue = (rawValue) => {
|
|
93
|
-
const trimmed = String(rawValue || '').trim();
|
|
94
|
-
if (!trimmed) return '';
|
|
95
|
-
if ((trimmed.startsWith('"') && trimmed.endsWith('"'))
|
|
96
|
-
|| (trimmed.startsWith('\'') && trimmed.endsWith('\''))) {
|
|
97
|
-
return trimmed.slice(1, -1);
|
|
98
|
-
}
|
|
99
|
-
return trimmed.replace(/\s+#.*$/, '').trim();
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const ENV_ASSIGNMENT_RE = /^\s*([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
|
|
103
|
-
|
|
104
|
-
const parseEnvEntries = (content = '') => {
|
|
105
|
-
const entries = new Map();
|
|
106
|
-
content.split(/\r?\n/).forEach((line, index) => {
|
|
107
|
-
const match = line.match(ENV_ASSIGNMENT_RE);
|
|
108
|
-
if (!match) return;
|
|
109
|
-
entries.set(match[1], {
|
|
110
|
-
index,
|
|
111
|
-
value: normalizeEnvValue(match[2]),
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
return entries;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const upsertEnvFileValues = (content = '', updates = {}) => {
|
|
118
|
-
const lines = content ? content.split(/\r?\n/) : [];
|
|
119
|
-
const entries = parseEnvEntries(content);
|
|
120
|
-
|
|
121
|
-
Object.entries(updates).forEach(([key, value]) => {
|
|
122
|
-
const rendered = `${key}=${value}`;
|
|
123
|
-
if (entries.has(key)) {
|
|
124
|
-
lines[entries.get(key).index] = rendered;
|
|
125
|
-
} else {
|
|
126
|
-
lines.push(rendered);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const compacted = lines
|
|
131
|
-
.join('\n')
|
|
132
|
-
.replace(/\n{3,}/g, '\n\n')
|
|
133
|
-
.replace(/\n*$/, '\n');
|
|
134
|
-
|
|
135
|
-
return compacted || '\n';
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const ensureRepoEnvFile = (repoRoot) => {
|
|
139
|
-
const envPath = join(repoRoot, LOCAL_ENV_FILE);
|
|
140
|
-
if (existsSync(envPath)) return envPath;
|
|
141
|
-
|
|
142
|
-
const examplePath = join(repoRoot, LOCAL_ENV_EXAMPLE_FILE);
|
|
143
|
-
if (existsSync(examplePath)) {
|
|
144
|
-
copyFileSync(examplePath, envPath);
|
|
145
|
-
return envPath;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
writeFileSync(envPath, '', 'utf8');
|
|
149
|
-
return envPath;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const readEnvValue = (repoRoot, key) => {
|
|
153
|
-
const envPath = join(repoRoot, LOCAL_ENV_FILE);
|
|
154
|
-
if (!existsSync(envPath)) return '';
|
|
155
|
-
const entries = parseEnvEntries(readFileSync(envPath, 'utf8'));
|
|
156
|
-
return entries.get(key)?.value || '';
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const writeEnvValues = (repoRoot, updates) => {
|
|
160
|
-
const envPath = ensureRepoEnvFile(repoRoot);
|
|
161
|
-
const current = existsSync(envPath) ? readFileSync(envPath, 'utf8') : '';
|
|
162
|
-
const next = upsertEnvFileValues(current, updates);
|
|
163
|
-
writeFileSync(envPath, next, 'utf8');
|
|
164
|
-
return envPath;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
50
|
const ensureLocalInstanceConfig = () => {
|
|
168
51
|
saveInstance({
|
|
169
52
|
key: 'local',
|
|
@@ -174,339 +57,12 @@ const ensureLocalInstanceConfig = () => {
|
|
|
174
57
|
});
|
|
175
58
|
};
|
|
176
59
|
|
|
177
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
178
|
-
|
|
179
|
-
const waitForLocalHealth = async ({ timeoutMs = 90000, intervalMs = 3000 } = {}) => {
|
|
180
|
-
const deadline = Date.now() + timeoutMs;
|
|
181
|
-
let lastError = null;
|
|
182
|
-
|
|
183
|
-
while (Date.now() < deadline) {
|
|
184
|
-
try {
|
|
185
|
-
const res = await fetch(`${LOCAL_URL}/api/health`);
|
|
186
|
-
if (res.ok) return;
|
|
187
|
-
lastError = new Error(`HTTP ${res.status}`);
|
|
188
|
-
} catch (error) {
|
|
189
|
-
lastError = error;
|
|
190
|
-
}
|
|
191
|
-
await sleep(intervalMs);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
throw new Error(
|
|
195
|
-
`Local backend did not become healthy at ${LOCAL_URL} within ${Math.round(timeoutMs / 1000)}s`
|
|
196
|
-
+ (lastError ? `: ${lastError.message}` : ''),
|
|
197
|
-
);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const resolveLocalLoginSettings = (repoRoot) => ({
|
|
201
|
-
email: process.env.LOCAL_DEV_LOGIN_EMAIL
|
|
202
|
-
|| readEnvValue(repoRoot, 'LOCAL_DEV_LOGIN_EMAIL')
|
|
203
|
-
|| LOCAL_LOGIN_DEFAULTS.email,
|
|
204
|
-
password: process.env.LOCAL_DEV_LOGIN_PASSWORD
|
|
205
|
-
|| readEnvValue(repoRoot, 'LOCAL_DEV_LOGIN_PASSWORD')
|
|
206
|
-
|| LOCAL_LOGIN_DEFAULTS.password,
|
|
207
|
-
username: process.env.LOCAL_DEV_LOGIN_USERNAME
|
|
208
|
-
|| readEnvValue(repoRoot, 'LOCAL_DEV_LOGIN_USERNAME')
|
|
209
|
-
|| LOCAL_LOGIN_DEFAULTS.username,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
const persistLocalLogin = (loginResult) => {
|
|
213
|
-
const token = loginResult.token;
|
|
214
|
-
const userId = loginResult.user?._id || loginResult.user?.id || null;
|
|
215
|
-
const username = loginResult.user?.username || null;
|
|
216
|
-
saveInstance({
|
|
217
|
-
key: 'local',
|
|
218
|
-
url: LOCAL_URL,
|
|
219
|
-
token,
|
|
220
|
-
userId,
|
|
221
|
-
username,
|
|
222
|
-
});
|
|
223
|
-
return token;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const ensureLocalAuth = async (repoRoot) => {
|
|
227
|
-
ensureLocalInstanceConfig();
|
|
228
|
-
|
|
229
|
-
const existingToken = getToken('local');
|
|
230
|
-
if (existingToken) {
|
|
231
|
-
const probeClient = createClient({ instance: LOCAL_URL, token: existingToken });
|
|
232
|
-
try {
|
|
233
|
-
await probeClient.get('/api/pods');
|
|
234
|
-
return existingToken;
|
|
235
|
-
} catch (error) {
|
|
236
|
-
if (error.status && ![401, 403].includes(error.status)) {
|
|
237
|
-
throw error;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const credentials = resolveLocalLoginSettings(repoRoot);
|
|
243
|
-
const result = await apiLogin(LOCAL_URL, credentials.email, credentials.password);
|
|
244
|
-
return persistLocalLogin(result);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const listPods = async (client) => {
|
|
248
|
-
const data = await client.get('/api/pods');
|
|
249
|
-
return Array.isArray(data) ? data : data.pods || [];
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const resolveOrCreatePod = async (client, { podId = null, podName = CLAWDBOT_DEFAULT_POD_NAME } = {}) => {
|
|
253
|
-
if (podId) return { podId, created: false, name: null };
|
|
254
|
-
|
|
255
|
-
const existingPods = await listPods(client);
|
|
256
|
-
const existing = existingPods.find((pod) => pod?.name === podName);
|
|
257
|
-
if (existing?._id) {
|
|
258
|
-
return { podId: existing._id, created: false, name: existing.name || podName };
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const created = await client.post('/api/pods', {
|
|
262
|
-
name: podName,
|
|
263
|
-
type: 'chat',
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
return {
|
|
267
|
-
podId: created._id || created.id,
|
|
268
|
-
created: true,
|
|
269
|
-
name: created.name || podName,
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const listInstalledAgents = async (client, podId) => {
|
|
274
|
-
const data = await client.get(`/api/registry/pods/${podId}/agents`);
|
|
275
|
-
return Array.isArray(data) ? data : data.agents || [];
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
const ensureOpenClawInstallation = async (client, { podId, instanceId, displayName }) => {
|
|
279
|
-
const agents = await listInstalledAgents(client, podId);
|
|
280
|
-
const existing = agents.find(
|
|
281
|
-
(agent) => agent?.agentName === CLAWDBOT_AGENT_NAME && (agent?.instanceId || 'default') === instanceId,
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
if (existing) {
|
|
285
|
-
return { installation: existing, created: false };
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const result = await client.post('/api/registry/install', {
|
|
289
|
-
agentName: CLAWDBOT_AGENT_NAME,
|
|
290
|
-
podId,
|
|
291
|
-
instanceId,
|
|
292
|
-
displayName,
|
|
293
|
-
version: '1.0.0',
|
|
294
|
-
config: {
|
|
295
|
-
runtime: {
|
|
296
|
-
runtimeType: 'moltbot',
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
scopes: CLAWDBOT_INSTALL_SCOPES,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
return {
|
|
303
|
-
installation: result.installation || result,
|
|
304
|
-
created: true,
|
|
305
|
-
};
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const resolveGatewayToken = (repoRoot, explicitToken = null) => (
|
|
309
|
-
explicitToken
|
|
310
|
-
|| readEnvValue(repoRoot, 'CLAWDBOT_GATEWAY_TOKEN')
|
|
311
|
-
|| `local-clawdbot-${randomBytes(12).toString('hex')}`
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
const mapContainerPathToRepo = (repoRoot, configPath) => {
|
|
315
|
-
if (!configPath) return null;
|
|
316
|
-
if (!isAbsolute(configPath)) return join(repoRoot, configPath);
|
|
317
|
-
if (configPath.startsWith('/app/')) return join(repoRoot, configPath.slice('/app/'.length));
|
|
318
|
-
if (configPath.startsWith('/repo/')) return join(repoRoot, configPath.slice('/repo/'.length));
|
|
319
|
-
return configPath;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
const resolveClawdbotConfigPath = (repoRoot, configPath = null) => (
|
|
323
|
-
mapContainerPathToRepo(repoRoot, configPath) || join(repoRoot, CLAWDBOT_CONFIG_RELATIVE_PATH)
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
export const patchClawdbotConfig = ({
|
|
327
|
-
config = {},
|
|
328
|
-
accountId,
|
|
329
|
-
podId,
|
|
330
|
-
displayName,
|
|
331
|
-
runtimeToken,
|
|
332
|
-
userToken,
|
|
333
|
-
gatewayToken,
|
|
334
|
-
}) => {
|
|
335
|
-
const next = JSON.parse(JSON.stringify(config || {}));
|
|
336
|
-
|
|
337
|
-
next.gateway = next.gateway || {};
|
|
338
|
-
next.gateway.mode = next.gateway.mode || 'local';
|
|
339
|
-
next.gateway.bind = next.gateway.bind || 'lan';
|
|
340
|
-
next.gateway.auth = next.gateway.auth || {};
|
|
341
|
-
if (gatewayToken) next.gateway.auth.token = gatewayToken;
|
|
342
|
-
next.gateway.controlUi = next.gateway.controlUi || {};
|
|
343
|
-
const allowedOrigins = Array.isArray(next.gateway.controlUi.allowedOrigins)
|
|
344
|
-
? next.gateway.controlUi.allowedOrigins.filter(Boolean)
|
|
345
|
-
: [];
|
|
346
|
-
if (allowedOrigins.length === 0) {
|
|
347
|
-
next.gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback = true;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
next.channels = next.channels || {};
|
|
351
|
-
next.channels.commonly = next.channels.commonly || {};
|
|
352
|
-
next.channels.commonly.enabled = true;
|
|
353
|
-
next.channels.commonly.baseUrl = next.channels.commonly.baseUrl || 'http://backend:5000';
|
|
354
|
-
next.channels.commonly.accounts = next.channels.commonly.accounts || {};
|
|
355
|
-
const existingAccount = next.channels.commonly.accounts[accountId] || {};
|
|
356
|
-
const podIds = Array.isArray(existingAccount.podIds) ? existingAccount.podIds : [];
|
|
357
|
-
next.channels.commonly.accounts[accountId] = {
|
|
358
|
-
...existingAccount,
|
|
359
|
-
runtimeToken,
|
|
360
|
-
userToken,
|
|
361
|
-
agentName: CLAWDBOT_AGENT_NAME,
|
|
362
|
-
instanceId: accountId,
|
|
363
|
-
podIds: Array.from(new Set([...podIds, podId].filter(Boolean))),
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
next.agents = next.agents || {};
|
|
367
|
-
next.agents.list = Array.isArray(next.agents.list) ? next.agents.list : [];
|
|
368
|
-
const agentEntry = next.agents.list.find((agent) => agent?.id === accountId);
|
|
369
|
-
if (agentEntry) {
|
|
370
|
-
if (!agentEntry.name) agentEntry.name = displayName || accountId;
|
|
371
|
-
if (!agentEntry.workspace) agentEntry.workspace = `/home/node/clawd/${accountId}`;
|
|
372
|
-
} else {
|
|
373
|
-
next.agents.list.push({
|
|
374
|
-
id: accountId,
|
|
375
|
-
name: displayName || accountId,
|
|
376
|
-
workspace: `/home/node/clawd/${accountId}`,
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
next.bindings = Array.isArray(next.bindings) ? next.bindings : [];
|
|
381
|
-
const hasBinding = next.bindings.some(
|
|
382
|
-
(binding) => binding?.match?.channel === 'commonly' && binding?.match?.accountId === accountId,
|
|
383
|
-
);
|
|
384
|
-
if (!hasBinding) {
|
|
385
|
-
next.bindings.push({
|
|
386
|
-
agentId: accountId,
|
|
387
|
-
match: {
|
|
388
|
-
channel: 'commonly',
|
|
389
|
-
accountId,
|
|
390
|
-
},
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return next;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
export const bootstrapClawdbotRuntime = async ({
|
|
398
|
-
client,
|
|
399
|
-
repoRoot,
|
|
400
|
-
podId = null,
|
|
401
|
-
podName = CLAWDBOT_DEFAULT_POD_NAME,
|
|
402
|
-
instanceId = CLAWDBOT_DEFAULT_INSTANCE_ID,
|
|
403
|
-
displayName = CLAWDBOT_DEFAULT_DISPLAY_NAME,
|
|
404
|
-
gatewayToken = null,
|
|
405
|
-
force = false,
|
|
406
|
-
}) => {
|
|
407
|
-
writeEnvValues(repoRoot, {
|
|
408
|
-
COMMONLY_LOCAL_CLAWDBOT: '1',
|
|
409
|
-
CLAWDBOT_GATEWAY_TOKEN: gatewayToken,
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
const pod = await resolveOrCreatePod(client, { podId, podName });
|
|
413
|
-
const install = await ensureOpenClawInstallation(client, {
|
|
414
|
-
podId: pod.podId,
|
|
415
|
-
instanceId,
|
|
416
|
-
displayName,
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
let provisionResult = null;
|
|
420
|
-
try {
|
|
421
|
-
provisionResult = await client.post(
|
|
422
|
-
`/api/registry/pods/${pod.podId}/agents/${CLAWDBOT_AGENT_NAME}/provision`,
|
|
423
|
-
{
|
|
424
|
-
instanceId,
|
|
425
|
-
includeUserToken: true,
|
|
426
|
-
force,
|
|
427
|
-
scopes: CLAWDBOT_USER_TOKEN_SCOPES,
|
|
428
|
-
},
|
|
429
|
-
);
|
|
430
|
-
} catch (error) {
|
|
431
|
-
if (!(error.status === 429 && !force)) throw error;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const runtimeIssued = await client.post(
|
|
435
|
-
`/api/registry/pods/${pod.podId}/agents/${CLAWDBOT_AGENT_NAME}/runtime-tokens`,
|
|
436
|
-
{ instanceId, force: true },
|
|
437
|
-
);
|
|
438
|
-
const runtimeToken = runtimeIssued.token;
|
|
439
|
-
if (!runtimeToken) {
|
|
440
|
-
throw new Error('Runtime token was not returned by the runtime-tokens route');
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// Rotated like the runtime token above: an existing user token is stored
|
|
444
|
-
// only as a hash, so asking without force returns none to write here.
|
|
445
|
-
const userIssued = await client.post(
|
|
446
|
-
`/api/registry/pods/${pod.podId}/agents/${CLAWDBOT_AGENT_NAME}/user-token`,
|
|
447
|
-
{
|
|
448
|
-
instanceId,
|
|
449
|
-
displayName,
|
|
450
|
-
scopes: CLAWDBOT_USER_TOKEN_SCOPES,
|
|
451
|
-
force: true,
|
|
452
|
-
},
|
|
453
|
-
);
|
|
454
|
-
const userToken = userIssued.token;
|
|
455
|
-
if (!userToken) {
|
|
456
|
-
throw new Error('User token was not returned by the user-token route');
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const configPath = resolveClawdbotConfigPath(repoRoot, provisionResult?.configPath);
|
|
460
|
-
if (!existsSync(configPath) && !provisionResult) {
|
|
461
|
-
throw new Error(
|
|
462
|
-
`OpenClaw config not found at ${configPath}. Run with --force after the provision cooldown `
|
|
463
|
-
+ 'or clear stale clawdbot state before bootstrapping again.',
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const rawConfig = existsSync(configPath)
|
|
468
|
-
? JSON.parse(readFileSync(configPath, 'utf8') || '{}')
|
|
469
|
-
: {};
|
|
470
|
-
const nextConfig = patchClawdbotConfig({
|
|
471
|
-
config: rawConfig,
|
|
472
|
-
accountId: instanceId,
|
|
473
|
-
podId: pod.podId,
|
|
474
|
-
displayName,
|
|
475
|
-
runtimeToken,
|
|
476
|
-
userToken,
|
|
477
|
-
gatewayToken,
|
|
478
|
-
});
|
|
479
|
-
mkdirSync(dirname(configPath), { recursive: true });
|
|
480
|
-
writeFileSync(configPath, `${JSON.stringify(nextConfig, null, 2)}\n`, 'utf8');
|
|
481
|
-
|
|
482
|
-
writeEnvValues(repoRoot, {
|
|
483
|
-
COMMONLY_LOCAL_CLAWDBOT: '1',
|
|
484
|
-
CLAWDBOT_GATEWAY_TOKEN: gatewayToken,
|
|
485
|
-
OPENCLAW_RUNTIME_TOKEN: runtimeToken,
|
|
486
|
-
OPENCLAW_USER_TOKEN: userToken,
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
return {
|
|
490
|
-
podId: pod.podId,
|
|
491
|
-
podCreated: pod.created,
|
|
492
|
-
installationCreated: install.created,
|
|
493
|
-
instanceId,
|
|
494
|
-
displayName,
|
|
495
|
-
gatewayToken,
|
|
496
|
-
runtimeToken,
|
|
497
|
-
userToken,
|
|
498
|
-
configPath,
|
|
499
|
-
provisioned: Boolean(provisionResult),
|
|
500
|
-
};
|
|
501
|
-
};
|
|
502
|
-
|
|
503
60
|
export const registerDev = (program) => {
|
|
504
61
|
const dev = program.command('dev').description('Local development environment');
|
|
505
62
|
|
|
506
63
|
dev.addHelpText('after', `
|
|
507
64
|
Examples:
|
|
508
65
|
$ commonly dev up # Start a local docker-compose stack
|
|
509
|
-
$ commonly dev clawdbot # Bootstrap local OpenClaw + start it
|
|
510
66
|
$ commonly dev status # Check health
|
|
511
67
|
$ commonly dev logs backend # Tail backend logs
|
|
512
68
|
$ commonly dev down # Stop everything
|
|
@@ -518,11 +74,8 @@ Login against the local instance with:
|
|
|
518
74
|
dev
|
|
519
75
|
.command('up')
|
|
520
76
|
.description('Start local Commonly instance')
|
|
521
|
-
.
|
|
522
|
-
|
|
523
|
-
runDevSh(['up'], {
|
|
524
|
-
env: opts.withGateway ? { COMMONLY_LOCAL_CLAWDBOT: '1' } : undefined,
|
|
525
|
-
});
|
|
77
|
+
.action(async () => {
|
|
78
|
+
runDevSh(['up']);
|
|
526
79
|
|
|
527
80
|
ensureLocalInstanceConfig();
|
|
528
81
|
|
|
@@ -535,70 +88,13 @@ Login against the local instance with:
|
|
|
535
88
|
|
|
536
89
|
dev
|
|
537
90
|
.command('clawdbot')
|
|
538
|
-
.description('
|
|
539
|
-
.
|
|
540
|
-
.
|
|
541
|
-
.
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
.option('--no-start', 'Write config and env only; do not start or restart docker services')
|
|
546
|
-
.action(async (opts) => {
|
|
547
|
-
const repoRoot = findRepoRoot();
|
|
548
|
-
if (!repoRoot) {
|
|
549
|
-
console.error('dev.sh not found — run this command from within the commonly repo');
|
|
550
|
-
process.exit(1);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
const gatewayToken = resolveGatewayToken(repoRoot, opts.gatewayToken);
|
|
554
|
-
writeEnvValues(repoRoot, {
|
|
555
|
-
COMMONLY_LOCAL_CLAWDBOT: '1',
|
|
556
|
-
CLAWDBOT_GATEWAY_TOKEN: gatewayToken,
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
if (opts.start) {
|
|
560
|
-
runDevSh(['up'], {
|
|
561
|
-
env: {
|
|
562
|
-
COMMONLY_LOCAL_CLAWDBOT: '1',
|
|
563
|
-
CLAWDBOT_GATEWAY_TOKEN: gatewayToken,
|
|
564
|
-
},
|
|
565
|
-
});
|
|
566
|
-
await waitForLocalHealth();
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
ensureLocalInstanceConfig();
|
|
570
|
-
const token = await ensureLocalAuth(repoRoot);
|
|
571
|
-
const client = createClient({ instance: LOCAL_URL, token });
|
|
572
|
-
|
|
573
|
-
const result = await bootstrapClawdbotRuntime({
|
|
574
|
-
client,
|
|
575
|
-
repoRoot,
|
|
576
|
-
podId: opts.pod || null,
|
|
577
|
-
podName: opts.podName,
|
|
578
|
-
instanceId: opts.instanceId,
|
|
579
|
-
displayName: opts.display,
|
|
580
|
-
gatewayToken,
|
|
581
|
-
force: opts.force,
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
if (opts.start) {
|
|
585
|
-
runDevSh(['clawdbot', 'restart'], {
|
|
586
|
-
env: {
|
|
587
|
-
COMMONLY_LOCAL_CLAWDBOT: '1',
|
|
588
|
-
CLAWDBOT_GATEWAY_TOKEN: gatewayToken,
|
|
589
|
-
},
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
console.log('\nLocal OpenClaw bootstrap complete:');
|
|
594
|
-
console.log(` Pod: ${result.podId}`);
|
|
595
|
-
console.log(` Agent: ${CLAWDBOT_AGENT_NAME}:${result.instanceId}`);
|
|
596
|
-
console.log(` Config: ${result.configPath}`);
|
|
597
|
-
console.log(` Gateway: ${gatewayToken}`);
|
|
598
|
-
console.log(` Started: ${opts.start ? 'yes' : 'no'}`);
|
|
599
|
-
console.log('\nNext:');
|
|
600
|
-
console.log(' ./dev.sh clawdbot logs gateway');
|
|
601
|
-
console.log(' commonly pod tail <podId> --instance local');
|
|
91
|
+
.description('Retired: the local OpenClaw gateway is gone (ADR-021 Part B)')
|
|
92
|
+
.allowUnknownOption()
|
|
93
|
+
.allowExcessArguments()
|
|
94
|
+
.action(() => {
|
|
95
|
+
console.error('The local OpenClaw gateway was retired (ADR-021 Part B), so `commonly dev clawdbot` no longer does anything.');
|
|
96
|
+
console.error('Use native agents, or attach a local CLI with: commonly agent attach <cli>');
|
|
97
|
+
process.exit(1);
|
|
602
98
|
});
|
|
603
99
|
|
|
604
100
|
dev
|
|
@@ -103,7 +103,7 @@ import { BACKGROUND_PROCESS_CUE, buildMemoryPreamble, ROW_SLICING_CUE } from '..
|
|
|
103
103
|
import { claudeConfigDirFor, claudeContextTokens, claudeTranscriptPath } from '../session-recycle.js';
|
|
104
104
|
import { skillsAsText } from '../skill-prompt.js';
|
|
105
105
|
import { adapterFailure, redactKnownCredentials, spawnCredentials } from '../upstream-refusal.js';
|
|
106
|
-
import {
|
|
106
|
+
import { PUBLIC_WITHHELD_TOOLS, publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
107
107
|
import { isShippedCommonlyMcpCommand } from '../declared-mcp-guard.js';
|
|
108
108
|
import { isAnswerableToolError, PUBLIC_MCP_NOT_READY_CODE, PUBLIC_TOOL_FAILED_CODE } from '../public-tool-error.js';
|
|
109
109
|
import { resolveLaunch, resolveMcpCommand, resolveWindowsCommandWithReason } from '../windows-command.js';
|
|
@@ -637,7 +637,7 @@ const permissionPath = (path, platform) => (platform === 'win32'
|
|
|
637
637
|
const MEMORY_TOOLS = Object.freeze(['commonly_read_agent_memory', 'commonly_write_agent_memory', 'commonly_save_my_memory']);
|
|
638
638
|
|
|
639
639
|
const buildPublicClaudePolicyArgs = (mcpToolPatterns, {
|
|
640
|
-
trust, allow = [], memoryWithheld = false, platform = process.platform, home: homeOverride = null,
|
|
640
|
+
trust, allow = [], memoryWithheld = false, ownerWoken = false, platform = process.platform, home: homeOverride = null,
|
|
641
641
|
noShell = false,
|
|
642
642
|
} = {}) => {
|
|
643
643
|
const home = homeOverride || homedir();
|
|
@@ -685,11 +685,12 @@ const buildPublicClaudePolicyArgs = (mcpToolPatterns, {
|
|
|
685
685
|
: [];
|
|
686
686
|
// Nor, on any confined trust, the tools no public seat is offered
|
|
687
687
|
// (public-withheld-tools.js). A public seat also loses self-install and every
|
|
688
|
-
// memory write (F118)
|
|
689
|
-
//
|
|
688
|
+
// memory write (F118), and gets the writes back on a turn its owner woke
|
|
689
|
+
// (F145). Only a workspace seat is called with its trust at every call site;
|
|
690
|
+
// the public ones pass none, so "not workspace" is public.
|
|
690
691
|
const withheldTools = trust === 'workspace'
|
|
691
692
|
? PUBLIC_WITHHELD_TOOLS
|
|
692
|
-
:
|
|
693
|
+
: publicSeatWithheldTools({ ownerWoken });
|
|
693
694
|
const withheldDenies = withheldTools
|
|
694
695
|
.flatMap((tool) => mcpToolPatterns.map((pattern) => pattern.replace(/\*$/, tool)));
|
|
695
696
|
// A tool can be denied for two reasons (a withheld turn's memory write is
|
|
@@ -1408,6 +1409,7 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1408
1409
|
...buildPublicClaudePolicyArgs(allowedPatterns, {
|
|
1409
1410
|
...(sandboxTrust === 'workspace' ? { trust: sandboxTrust, allow: grants } : {}),
|
|
1410
1411
|
memoryWithheld: ctx.memoryWithheld === true,
|
|
1412
|
+
ownerWoken: ctx.ownerWoken,
|
|
1411
1413
|
platform: ctx._platform || process.platform,
|
|
1412
1414
|
home: ctx._home || null,
|
|
1413
1415
|
noShell: true,
|
|
@@ -1450,7 +1452,7 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1450
1452
|
innerArgv = [
|
|
1451
1453
|
...innerArgv,
|
|
1452
1454
|
...buildPublicClaudePolicyArgs(allowedPatterns, {
|
|
1453
|
-
trust: sandboxTrust, allow: grants, memoryWithheld: ctx.memoryWithheld === true,
|
|
1455
|
+
trust: sandboxTrust, allow: grants, memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken,
|
|
1454
1456
|
}),
|
|
1455
1457
|
...(ctx.publicSkillArgs || []),
|
|
1456
1458
|
];
|
|
@@ -1517,8 +1519,8 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1517
1519
|
innerArgv = [
|
|
1518
1520
|
...innerArgv,
|
|
1519
1521
|
...buildPublicClaudePolicyArgs(allowedPatterns, workspaceBwrapSandbox
|
|
1520
|
-
? { trust: sandboxTrust, allow: grants, memoryWithheld: ctx.memoryWithheld === true }
|
|
1521
|
-
: { memoryWithheld: ctx.memoryWithheld === true }),
|
|
1522
|
+
? { trust: sandboxTrust, allow: grants, memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken }
|
|
1523
|
+
: { memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken }),
|
|
1522
1524
|
...(ctx.publicSkillArgs || []),
|
|
1523
1525
|
];
|
|
1524
1526
|
} else if (allowedPatterns.length > 0) {
|
|
@@ -1685,8 +1687,9 @@ export default {
|
|
|
1685
1687
|
// long-running work in its own project.
|
|
1686
1688
|
const reapEverything = ctx.environment?.sandbox?.trust === 'public';
|
|
1687
1689
|
const workCues = publicTrust ? [] : WORK_CUES;
|
|
1688
|
-
// F118: a public seat reads its memory
|
|
1689
|
-
|
|
1690
|
+
// F118, F145: a public seat reads its memory, and is offered a write only
|
|
1691
|
+
// on a turn its owner woke.
|
|
1692
|
+
const memoryReadOnly = ctx.environment?.sandbox?.trust === 'public' && ctx.ownerWoken !== true;
|
|
1690
1693
|
const fullPrompt = buildPrompt(prompt, ctx.memoryLongTerm, {
|
|
1691
1694
|
freshSession: !isResume,
|
|
1692
1695
|
workCues,
|
|
@@ -82,7 +82,7 @@ import { resolveSkillSource, skillsAsText } from '../skill-prompt.js';
|
|
|
82
82
|
import { isLegacySandboxTrust, normalizeSandboxTrust, refuseWorkspaceTrust } from '../environment.js';
|
|
83
83
|
import { contains, realpathOfNearest, refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
84
84
|
import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
85
|
-
import {
|
|
85
|
+
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
86
86
|
import { resolveLaunch, resolveMcpCommand, resolveWindowsCommandWithReason } from '../windows-command.js';
|
|
87
87
|
|
|
88
88
|
// Default timeout for a single codex spawn (exec mode).
|
|
@@ -267,9 +267,10 @@ const buildMcpOverrideArgs = (mcpServers, ctx = {}) => {
|
|
|
267
267
|
`mcp_servers.${server.name}.default_tools_approval_mode="approve"`,
|
|
268
268
|
);
|
|
269
269
|
// ...except the tools no public seat is offered (public-withheld-tools.js),
|
|
270
|
-
// self-install and the memory writes included (F118).
|
|
270
|
+
// self-install and the memory writes included (F118). This list is argv on
|
|
271
|
+
// every spawn, `exec resume` too, so a resumed thread gets this turn's list.
|
|
271
272
|
if (ctx.publicSeat) {
|
|
272
|
-
flags.push('-c', `mcp_servers.${server.name}.disabled_tools=[${
|
|
273
|
+
flags.push('-c', `mcp_servers.${server.name}.disabled_tools=[${publicSeatWithheldTools(ctx).map(toml).join(',')}]`);
|
|
273
274
|
}
|
|
274
275
|
if (rest.length) {
|
|
275
276
|
flags.push('-c', `mcp_servers.${server.name}.args=[${rest.map(toml).join(',')}]`);
|
|
@@ -584,6 +585,8 @@ const writePublicCodexInstructions = async (publicHome, ctx) => {
|
|
|
584
585
|
// the whole catalog.
|
|
585
586
|
// - `features.goals` removes the goal tools. A goal is kept on the thread and
|
|
586
587
|
// comes back in the next turn's context.
|
|
588
|
+
// - `features.plugins`, `features.apps` and `analytics.enabled` turn off plugins,
|
|
589
|
+
// account apps and usage analytics, which a public seat has no use for.
|
|
587
590
|
//
|
|
588
591
|
// Measured against the tool list sent to the model, on codex-cli 0.162.1 with
|
|
589
592
|
// gpt-5.5, gpt-5.6 and gpt-6 models and on 0.159.3 with gpt-5.5 and gpt-6 models
|
|
@@ -593,6 +596,9 @@ const PUBLIC_BUILTIN_TOOL_FLAGS = Object.freeze([
|
|
|
593
596
|
'-c', 'features.multi_agent=false',
|
|
594
597
|
'-c', 'features.multi_agent_v2.max_concurrent_threads_per_session=1',
|
|
595
598
|
'-c', 'features.goals=false',
|
|
599
|
+
'-c', 'features.plugins=false',
|
|
600
|
+
'-c', 'features.apps=false',
|
|
601
|
+
'-c', 'analytics.enabled=false',
|
|
596
602
|
'-c', 'agents.max_depth=0',
|
|
597
603
|
]);
|
|
598
604
|
|
|
@@ -1045,7 +1051,7 @@ export default {
|
|
|
1045
1051
|
freshSession: !ctx.sessionId,
|
|
1046
1052
|
workCues: sandbox?.trust === 'public' ? [] : [ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE],
|
|
1047
1053
|
// F118: a public seat reads its memory but is not offered a write.
|
|
1048
|
-
memoryReadOnly: sandbox?.trust === 'public',
|
|
1054
|
+
memoryReadOnly: sandbox?.trust === 'public' && ctx.ownerWoken !== true,
|
|
1049
1055
|
});
|
|
1050
1056
|
|
|
1051
1057
|
const workspacePath = sandbox?.trust === 'public'
|
|
@@ -1071,6 +1077,7 @@ export default {
|
|
|
1071
1077
|
instanceUrl: ctx.instanceUrl,
|
|
1072
1078
|
credentialFile: credential?.path || null,
|
|
1073
1079
|
publicSeat: sandbox?.trust === 'public',
|
|
1080
|
+
ownerWoken: ctx.ownerWoken,
|
|
1074
1081
|
commandResolution: { env: ctx.env || process.env, ...ctx._commandResolution },
|
|
1075
1082
|
});
|
|
1076
1083
|
if (mcp.unavailableMcp.length) throw publicMcpUnavailableError(mcp.unavailableMcp);
|
|
@@ -7,6 +7,7 @@ import { tmpdir } from 'node:os';
|
|
|
7
7
|
import { isAbsolute, join } from 'node:path';
|
|
8
8
|
import { StringDecoder } from 'node:string_decoder';
|
|
9
9
|
import { buildMemoryPreamble } from '../memory-bridge.js';
|
|
10
|
+
import { OWNER_WOKEN_MEMORY_TOOLS } from '../public-withheld-tools.js';
|
|
10
11
|
import { effectiveSandboxTrust, refuseWorkspaceTrust, validateEnvironmentSpec } from '../environment.js';
|
|
11
12
|
import { writeCredentialFile } from '../credential-file.js';
|
|
12
13
|
import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
|
|
@@ -49,7 +50,7 @@ const templateLiteral = (value) => {
|
|
|
49
50
|
// public seat past 50 unseen falls back to continueAnyway, which it keeps.
|
|
50
51
|
// Self-install, the memory writes (log_cycle included) and delete_message are
|
|
51
52
|
// left out on every public seat (F118, F141, PUBLIC_ONLY_WITHHELD_TOOLS);
|
|
52
|
-
// reading memory stays.
|
|
53
|
+
// reading memory stays. The writes join only on a turn its owner woke (F145).
|
|
53
54
|
export const PUBLIC_GOOSE_TOOLS = Object.freeze([
|
|
54
55
|
'commonly_get_started', 'commonly_post_message', 'commonly_claim_message',
|
|
55
56
|
'commonly_release_claim', 'commonly_get_messages', 'commonly_get_context',
|
|
@@ -62,6 +63,10 @@ export const PUBLIC_GOOSE_TOOLS = Object.freeze([
|
|
|
62
63
|
'commonly_respond_to_ask', 'commonly_react_to_message',
|
|
63
64
|
]);
|
|
64
65
|
|
|
66
|
+
const publicGooseTools = (ctx) => (ctx?.ownerWoken === true
|
|
67
|
+
? [...PUBLIC_GOOSE_TOOLS, ...OWNER_WOKEN_MEMORY_TOOLS]
|
|
68
|
+
: PUBLIC_GOOSE_TOOLS);
|
|
69
|
+
|
|
65
70
|
export const assertSandboxSupported = (environment = {}) => {
|
|
66
71
|
const sandbox = environment?.sandbox || {};
|
|
67
72
|
refuseWorkspaceTrust(sandbox, 'goose');
|
|
@@ -185,7 +190,7 @@ export const extensionArgs = (servers, ctx) => {
|
|
|
185
190
|
ctx.publicExtensions.push({ type: 'stdio', name: server.name, cmd: command[0],
|
|
186
191
|
args: command.slice(1).map((part) => substitute(part, ctx)),
|
|
187
192
|
envs: Object.fromEntries(Object.entries(delivery.env).map(([name, value]) => [name, substitute(value, ctx)])),
|
|
188
|
-
available_tools:
|
|
193
|
+
available_tools: publicGooseTools(ctx),
|
|
189
194
|
});
|
|
190
195
|
} else {
|
|
191
196
|
args.push('--with-extension', `${server.name}:${[...env, ...commandWords].join(' ')}`);
|
|
@@ -366,7 +371,7 @@ export default {
|
|
|
366
371
|
...extensionArgs(ctx.environment?.mcp, {
|
|
367
372
|
credentialFile: credential?.path || '', instanceUrl: ctx.instanceUrl || '',
|
|
368
373
|
runtimeToken: ctx.runtimeToken || '',
|
|
369
|
-
publicSeat: isPublic, mcpReadDirectories, publicExtensions, brokerExtensions,
|
|
374
|
+
publicSeat: isPublic, ownerWoken: ctx.ownerWoken, mcpReadDirectories, publicExtensions, brokerExtensions,
|
|
370
375
|
}),
|
|
371
376
|
...(!isPublic ? ['-t', buildMemoryPreamble(prompt, ctx.memoryLongTerm, { freshSession: true })] : []),
|
|
372
377
|
];
|
|
@@ -377,8 +382,9 @@ export default {
|
|
|
377
382
|
extensions: publicExtensions.map((extension) => ({ ...extension,
|
|
378
383
|
envs: { ...extension.envs, OPENSSL_CONF: opensslConfig },
|
|
379
384
|
})),
|
|
380
|
-
// F118: a public seat reads its memory
|
|
381
|
-
|
|
385
|
+
// F118, F145: a public seat reads its memory, and is offered a write
|
|
386
|
+
// only on a turn its owner woke.
|
|
387
|
+
prompt: buildMemoryPreamble(prompt, ctx.memoryLongTerm, { freshSession: true, memoryReadOnly: ctx.ownerWoken !== true }),
|
|
382
388
|
})), { mode: 0o600 });
|
|
383
389
|
const env = {
|
|
384
390
|
...safeEnv(sourceEnv),
|
|
@@ -59,7 +59,7 @@ import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js
|
|
|
59
59
|
import { isShippedCommonlyMcpCommand } from '../declared-mcp-guard.js';
|
|
60
60
|
import { isAnswerableToolError, PUBLIC_TOOL_FAILED_CODE } from '../public-tool-error.js';
|
|
61
61
|
import { startInstanceProxy } from '../instance-proxy.js';
|
|
62
|
-
import {
|
|
62
|
+
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
63
63
|
|
|
64
64
|
const DEFAULT_TIMEOUT_MS = 15 * 60 * 1000;
|
|
65
65
|
const ISOLATED_PROXY_PORT = 8765;
|
|
@@ -621,7 +621,7 @@ const buildMcpConfig = (servers, ctx = {}) => {
|
|
|
621
621
|
return mcp;
|
|
622
622
|
};
|
|
623
623
|
|
|
624
|
-
const publicPermissions = (mode, mcpNames) => {
|
|
624
|
+
const publicPermissions = (mode, mcpNames, ctx = {}) => {
|
|
625
625
|
const read = { '*': 'allow' };
|
|
626
626
|
const edit = { '*': mode === 'read-only' ? 'deny' : 'allow' };
|
|
627
627
|
for (const pattern of PUBLIC_READ_DENIES) {
|
|
@@ -653,7 +653,7 @@ const publicPermissions = (mode, mcpNames) => {
|
|
|
653
653
|
...Object.fromEntries(mcpNames.map((name) => [`${permissionMcpName(name)}_*`, 'allow'])),
|
|
654
654
|
// After the wildcard allow, since the last matching rule wins
|
|
655
655
|
// (public-withheld-tools.js; self-install and memory writes, F118).
|
|
656
|
-
...Object.fromEntries(mcpNames.flatMap((name) =>
|
|
656
|
+
...Object.fromEntries(mcpNames.flatMap((name) => publicSeatWithheldTools(ctx)
|
|
657
657
|
.map((tool) => [`${permissionMcpName(name)}_${tool}`, 'deny']))),
|
|
658
658
|
};
|
|
659
659
|
};
|
|
@@ -1184,7 +1184,7 @@ export default {
|
|
|
1184
1184
|
const fullPrompt = buildMemoryPreamble(prompt, ctx.memoryLongTerm, {
|
|
1185
1185
|
freshSession: !ctx.sessionId,
|
|
1186
1186
|
// F118: a public seat reads its memory but is not offered a write.
|
|
1187
|
-
memoryReadOnly: isPublic,
|
|
1187
|
+
memoryReadOnly: isPublic && ctx.ownerWoken !== true,
|
|
1188
1188
|
});
|
|
1189
1189
|
const tempDir = await mkdtemp(join(ctx._tempRoot || tmpdir(), 'commonly-opencode-'));
|
|
1190
1190
|
await chmod(tempDir, 0o700);
|
|
@@ -1267,7 +1267,7 @@ export default {
|
|
|
1267
1267
|
const carriesGrant = bearerFileServers.length > 0;
|
|
1268
1268
|
const config = {
|
|
1269
1269
|
permission: isPublic
|
|
1270
|
-
? publicPermissions(sandboxMode, Object.keys(mcp))
|
|
1270
|
+
? publicPermissions(sandboxMode, Object.keys(mcp), ctx)
|
|
1271
1271
|
: 'allow',
|
|
1272
1272
|
share: 'disabled',
|
|
1273
1273
|
autoupdate: false,
|
|
@@ -552,8 +552,8 @@ export const isHttpServer = (s) => typeof s?.url === 'string' && s.url.length >
|
|
|
552
552
|
|
|
553
553
|
/**
|
|
554
554
|
* The tools the bridge may register for one server: all of them, minus the
|
|
555
|
-
* entry's `withheldTools`. pi.js sets that list on a public seat
|
|
556
|
-
* (
|
|
555
|
+
* entry's `withheldTools`. pi.js sets that list per turn on a public seat
|
|
556
|
+
* (publicSeatWithheldTools), so a withheld Commonly tool is never registered with
|
|
557
557
|
* pi at all; pi's own `--exclude-tools` removes the same names as a second
|
|
558
558
|
* layer.
|
|
559
559
|
*/
|
package/src/lib/adapters/pi.js
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*
|
|
33
33
|
* A public seat (F113b) runs the same pi as
|
|
34
34
|
* sandbox-exec -p <profile> <abs pi> … --no-builtin-tools
|
|
35
|
-
* --exclude-tools <pi built-ins +
|
|
35
|
+
* --exclude-tools <pi built-ins + this turn's withheld tools> --no-approve …
|
|
36
36
|
* with a scrubbed environment and the provider behind a loopback proxy. pi's
|
|
37
37
|
* MCP servers start inside the jailed pi (the bridge is in-process), so they
|
|
38
38
|
* inherit the profile. Confinement is an explicit `sandbox.trust: 'public'`,
|
|
@@ -70,7 +70,7 @@ import { removeCredentialFile, writeCredentialFile } from '../credential-file.js
|
|
|
70
70
|
import { resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
71
71
|
import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
72
72
|
import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
|
|
73
|
-
import {
|
|
73
|
+
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
74
74
|
|
|
75
75
|
const DEFAULT_TIMEOUT_MS = (() => {
|
|
76
76
|
const fallback = 15 * 60 * 1000;
|
|
@@ -130,7 +130,6 @@ const PI_PACKAGE = '@earendil-works/pi-coding-agent';
|
|
|
130
130
|
// adapter denies its shell; Qwen denies its read tools for this same reason,
|
|
131
131
|
// and Goose loads no built-in at all.
|
|
132
132
|
export const PI_BUILTIN_TOOLS = Object.freeze(['read', 'bash', 'edit', 'write', 'grep', 'find', 'ls']);
|
|
133
|
-
export const PUBLIC_EXCLUDED_TOOLS = Object.freeze([...PI_BUILTIN_TOOLS, ...PUBLIC_SEAT_WITHHELD_TOOLS]);
|
|
134
133
|
|
|
135
134
|
// What a public pi inherits from the launcher's environment. Everything else
|
|
136
135
|
// (operator variables, the real provider key, the seat token) stays out.
|
|
@@ -267,7 +266,7 @@ export const resolveMcpServers = (mcpServers, ctx = {}) => {
|
|
|
267
266
|
name: server.name,
|
|
268
267
|
url,
|
|
269
268
|
headers: Object.fromEntries(Object.entries(server.headers || {}).map(([k, v]) => [k, substitutePlaceholders(v, ctx)])),
|
|
270
|
-
...(ctx.publicSeat ? { withheldTools: [...
|
|
269
|
+
...(ctx.publicSeat ? { withheldTools: [...publicSeatWithheldTools(ctx)] } : {}),
|
|
271
270
|
...(grantBroker ? { confined: true } : {}),
|
|
272
271
|
...(grantBroker && ctx.credentialDir ? { credentialDir: ctx.credentialDir } : {}),
|
|
273
272
|
});
|
|
@@ -310,7 +309,7 @@ export const resolveMcpServers = (mcpServers, ctx = {}) => {
|
|
|
310
309
|
label: 'pi',
|
|
311
310
|
}).env,
|
|
312
311
|
).map(([k, v]) => [k, substitutePlaceholders(v, ctx)])),
|
|
313
|
-
...(ctx.publicSeat ? { withheldTools: [...
|
|
312
|
+
...(ctx.publicSeat ? { withheldTools: [...publicSeatWithheldTools(ctx)] } : {}),
|
|
314
313
|
});
|
|
315
314
|
continue;
|
|
316
315
|
}
|
|
@@ -502,7 +501,7 @@ export const piPackageRoot = (binary) => {
|
|
|
502
501
|
const versionOf = (value) => String(value || '').trim().match(/\b(\d+\.\d+\.\d+)\b/)?.[1] || null;
|
|
503
502
|
|
|
504
503
|
export const buildArgs = ({
|
|
505
|
-
prompt, provider, model, thinking, sessionId, isResume, sessionDir, bridge, publicSeat = false,
|
|
504
|
+
prompt, provider, model, thinking, sessionId, isResume, sessionDir, bridge, publicSeat = false, ownerWoken = false,
|
|
506
505
|
}) => [
|
|
507
506
|
'-p',
|
|
508
507
|
'--mode', 'json',
|
|
@@ -513,7 +512,11 @@ export const buildArgs = ({
|
|
|
513
512
|
// A public seat: no built-in tool (no shell, no file access), the withheld
|
|
514
513
|
// Commonly tools removed from the registry, and no project-local pi files
|
|
515
514
|
// from the workspace trusted for this run.
|
|
516
|
-
...(publicSeat ? [
|
|
515
|
+
...(publicSeat ? [
|
|
516
|
+
'--no-builtin-tools',
|
|
517
|
+
'--exclude-tools', [...PI_BUILTIN_TOOLS, ...publicSeatWithheldTools({ ownerWoken })].join(','),
|
|
518
|
+
'--no-approve',
|
|
519
|
+
] : []),
|
|
517
520
|
'--provider', provider,
|
|
518
521
|
'--model', model,
|
|
519
522
|
...(thinking ? ['--thinking', thinking] : []),
|
|
@@ -783,10 +786,10 @@ export default {
|
|
|
783
786
|
// the switch, a wiped home) starts fresh under a new id.
|
|
784
787
|
const isResume = await sessionExists(sessionDir, ctx.sessionId);
|
|
785
788
|
const sessionId = isResume ? ctx.sessionId : randomUUID();
|
|
786
|
-
// F118: a public seat reads its memory
|
|
787
|
-
// so its preamble names none.
|
|
789
|
+
// F118, F145: a public seat reads its memory and is offered the save tool
|
|
790
|
+
// only on a turn its owner woke, so otherwise its preamble names none.
|
|
788
791
|
const fullPrompt = buildMemoryPreamble(prompt, ctx.memoryLongTerm, {
|
|
789
|
-
freshSession: !isResume, memoryReadOnly: isPublic,
|
|
792
|
+
freshSession: !isResume, memoryReadOnly: isPublic && ctx.ownerWoken !== true,
|
|
790
793
|
});
|
|
791
794
|
|
|
792
795
|
// One credential file per spawn, inside this seat's own 0700 home: the
|
|
@@ -866,6 +869,7 @@ export default {
|
|
|
866
869
|
prompt: fullPrompt, provider: provider.name, model, thinking, sessionId, isResume, sessionDir,
|
|
867
870
|
bridge: servers.length ? (ctx._bridgePath || BRIDGE_PATH) : null,
|
|
868
871
|
publicSeat: isPublic,
|
|
872
|
+
ownerWoken: ctx.ownerWoken,
|
|
869
873
|
});
|
|
870
874
|
// Shell isolation must not depend on whether this turn declares MCP. A
|
|
871
875
|
// public turn has no shell at all, so it loads no shell extension (that
|
package/src/lib/adapters/qwen.js
CHANGED
|
@@ -18,7 +18,7 @@ import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
|
18
18
|
import { refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
19
19
|
import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
|
|
20
20
|
import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
21
|
-
import {
|
|
21
|
+
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
22
22
|
import { isOurGrantBroker } from '../grant-broker-guard.js';
|
|
23
23
|
import { brokerBridgeEntry } from './broker-bridge-entry.js';
|
|
24
24
|
import { describeMcpCommand } from '../mcp-server-version.js';
|
|
@@ -49,12 +49,19 @@ const EXCLUDED_TOOLS = [
|
|
|
49
49
|
];
|
|
50
50
|
// Qwen can read its own config directory. That directory also contains the
|
|
51
51
|
// per-spawn MCP credential file, so public turns cannot expose OS read tools.
|
|
52
|
-
const PUBLIC_READ_TOOLS = [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const PUBLIC_READ_TOOLS = ['read_file', 'grep_search', 'search_file_content', 'glob', 'list_directory', 'lsp'];
|
|
53
|
+
|
|
54
|
+
// What a public turn adds to --exclude-tools. Both spellings of a Commonly MCP
|
|
55
|
+
// tool, under the usual server name and any this turn declares, as with the
|
|
56
|
+
// aliases above (public-withheld-tools.js; self-install and memory writes, F118,
|
|
57
|
+
// F145).
|
|
58
|
+
export const publicExcludedTools = (serverNames, ctx) => {
|
|
59
|
+
const names = [...new Set(['commonly', ...serverNames])];
|
|
60
|
+
return [
|
|
61
|
+
...PUBLIC_READ_TOOLS,
|
|
62
|
+
...publicSeatWithheldTools(ctx).flatMap((tool) => [tool, ...names.map((name) => `mcp__${name}__${tool}`)]),
|
|
63
|
+
];
|
|
64
|
+
};
|
|
58
65
|
|
|
59
66
|
const parseVersion = (output) => {
|
|
60
67
|
const match = String(output || '').trim().match(/^(?:qwen(?:\s+code|-code)?\s+)?v?(\d+\.\d+\.\d+)$/i);
|
|
@@ -161,7 +168,7 @@ export const buildQwenMcpConfig = (servers, ctx) => {
|
|
|
161
168
|
...(server.cwd ? { cwd: server.cwd } : {}),
|
|
162
169
|
// `--exclude-tools` refuses these at the call and still lists them for
|
|
163
170
|
// the model (measured on 0.26.2), so the server entry drops them too.
|
|
164
|
-
...(ctx.publicSeat ? { excludeTools: [...
|
|
171
|
+
...(ctx.publicSeat ? { excludeTools: [...publicSeatWithheldTools(ctx)] } : {}),
|
|
165
172
|
};
|
|
166
173
|
const versionDir = ctx.publicSeat && selectedMcpVersionDir(command);
|
|
167
174
|
if (versionDir) ctx.mcpReadDirectories?.push(versionDir);
|
|
@@ -366,6 +373,7 @@ export default {
|
|
|
366
373
|
instanceUrl: ctx.instanceUrl || '',
|
|
367
374
|
runtimeToken: ctx.runtimeToken || '',
|
|
368
375
|
publicSeat: isPublic,
|
|
376
|
+
ownerWoken: ctx.ownerWoken,
|
|
369
377
|
unavailableMcp,
|
|
370
378
|
mcpReadDirectories,
|
|
371
379
|
bridgedBrokers,
|
|
@@ -383,8 +391,9 @@ export default {
|
|
|
383
391
|
// be resumed. The kernel memory preamble supplies continuity instead.
|
|
384
392
|
const fullPrompt = buildMemoryPreamble(prompt, ctx.memoryLongTerm, {
|
|
385
393
|
freshSession: true,
|
|
386
|
-
// F118: a public seat reads its memory
|
|
387
|
-
|
|
394
|
+
// F118, F145: a public seat reads its memory, and is offered a write
|
|
395
|
+
// only on a turn its owner woke.
|
|
396
|
+
memoryReadOnly: isPublic && ctx.ownerWoken !== true,
|
|
388
397
|
});
|
|
389
398
|
const allowedTools = [
|
|
390
399
|
...(Object.hasOwn(mcp.mcpServers, 'commonly') ? ['commonly'] : []), ...bridgedBrokers,
|
|
@@ -392,7 +401,7 @@ export default {
|
|
|
392
401
|
const args = [
|
|
393
402
|
'--bare', '--safe-mode', '--auth-type', 'openai', '-m', seatModel,
|
|
394
403
|
'--mcp-config', mcpPath, '--exclude-tools', [
|
|
395
|
-
...EXCLUDED_TOOLS, ...(isPublic ?
|
|
404
|
+
...EXCLUDED_TOOLS, ...(isPublic ? publicExcludedTools(Object.keys(mcp.mcpServers), ctx) : []),
|
|
396
405
|
].join(','),
|
|
397
406
|
// Qwen ignores settings permissions in bare/safe mode, but still
|
|
398
407
|
// honours CLI allow rules. Any seat needs its declared Commonly tools
|
package/src/lib/memory-bridge.js
CHANGED
|
@@ -66,9 +66,11 @@ export const BACKGROUND_PROCESS_CUE = 'Background processes: anything you start
|
|
|
66
66
|
* only the habits its CLI can act on; passing none leaves the preamble as it
|
|
67
67
|
* was.
|
|
68
68
|
*
|
|
69
|
-
* `memoryReadOnly` is a public seat
|
|
70
|
-
* the long_term it read, but it is not offered
|
|
71
|
-
*
|
|
69
|
+
* `memoryReadOnly` is a public seat on a turn its owner didn't wake (F118, F145):
|
|
70
|
+
* it reads its memory and is shown the long_term it read, but it is not offered
|
|
71
|
+
* the save tool, so no cue names one, and it is told why. A resumed session may
|
|
72
|
+
* hold an earlier turn's offer, so that line goes in every turn, not just fresh
|
|
73
|
+
* ones. `memoryWithheld` wins over it: that turn reads nothing either.
|
|
72
74
|
*/
|
|
73
75
|
export const buildMemoryPreamble = (
|
|
74
76
|
prompt,
|
|
@@ -80,6 +82,8 @@ export const buildMemoryPreamble = (
|
|
|
80
82
|
// saved here" is a false claim about its own history, and it is the same
|
|
81
83
|
// defect this cue exists to fix — one state over. When we could not read, say
|
|
82
84
|
// that, and say nothing about what is stored.
|
|
85
|
+
const ownerOnly = 'You can read your memory on this turn but not change it: '
|
|
86
|
+
+ 'a memory write works only when your owner started the turn.';
|
|
83
87
|
let context;
|
|
84
88
|
if (memoryWithheld) {
|
|
85
89
|
// A workspace seat's turn that runs public: not unreadable and not empty,
|
|
@@ -91,15 +95,16 @@ export const buildMemoryPreamble = (
|
|
|
91
95
|
} else if (memoryLongTerm === null) {
|
|
92
96
|
context = `=== Context (your persistent memory) ===\n`
|
|
93
97
|
+ `(unreadable this turn — the memory read failed, so this says NOTHING `
|
|
94
|
-
+ `about what you have saved. Do not treat it as empty
|
|
95
|
-
+ `state you may already hold.)
|
|
98
|
+
+ `about what you have saved. Do not treat it as empty`
|
|
99
|
+
+ (memoryReadOnly ? `.)\n${ownerOnly}` : ` and do not re-save state you may already hold.)`);
|
|
96
100
|
} else if (memoryLongTerm) {
|
|
97
|
-
context = `=== Context (your persistent memory) ===\n${memoryLongTerm}
|
|
101
|
+
context = `=== Context (your persistent memory) ===\n${memoryLongTerm}`
|
|
102
|
+
+ (memoryReadOnly ? `\n(${ownerOnly})` : '');
|
|
98
103
|
} else if (memoryReadOnly) {
|
|
99
|
-
// F118:
|
|
100
|
-
//
|
|
104
|
+
// F118: this turn isn't offered the save tool, so the cue that teaches it
|
|
105
|
+
// would name a tool the seat cannot call.
|
|
101
106
|
context = `=== Context (your persistent memory) ===\n`
|
|
102
|
-
+ `(empty — nothing has ever been saved here)`;
|
|
107
|
+
+ `(empty — nothing has ever been saved here)\n${ownerOnly}`;
|
|
103
108
|
} else {
|
|
104
109
|
context = `=== Context (your persistent memory) ===\n`
|
|
105
110
|
+ `(empty — nothing has ever been saved here)\n`
|
|
@@ -124,7 +129,7 @@ export const buildMemoryPreamble = (
|
|
|
124
129
|
if (memoryWithheld) {
|
|
125
130
|
sessionEndCue += 'Memory is withheld this turn, so there is nothing to save.';
|
|
126
131
|
} else if (memoryReadOnly) {
|
|
127
|
-
sessionEndCue += 'Memory is read-only on this
|
|
132
|
+
sessionEndCue += 'Memory is read-only on this turn, so there is nothing to save.';
|
|
128
133
|
} else if (memoryLongTerm === null) {
|
|
129
134
|
sessionEndCue += 'Memory was unreadable on this fresh session. Do not treat it as empty or '
|
|
130
135
|
+ 'write a replacement based on this cue.';
|
|
@@ -10,7 +10,8 @@ export const PUBLIC_WITHHELD_TOOLS = Object.freeze(['commonly_attach_file', 'com
|
|
|
10
10
|
// capabilities. A public seat answers strangers, so an injected message must
|
|
11
11
|
// not be able to spread the agent into other pods or rewrite its memory.
|
|
12
12
|
// Withheld on public trust only: a Claude workspace seat keeps its memory
|
|
13
|
-
// writes, and denies self-install itself (claude.js, workspaceDenies).
|
|
13
|
+
// writes, and denies self-install itself (claude.js, workspaceDenies). The
|
|
14
|
+
// memory writes come back on a turn the owner woke (F145, below).
|
|
14
15
|
// commonly_log_cycle is a memory write too: it appends to the agent's
|
|
15
16
|
// `cycles[]` through POST /api/agents/runtime/memory/sync. Reading memory
|
|
16
17
|
// (commonly_read_agent_memory, and the long_term the wrapper puts in the
|
|
@@ -31,3 +32,17 @@ export const PUBLIC_ONLY_WITHHELD_TOOLS = Object.freeze([
|
|
|
31
32
|
export const PUBLIC_SEAT_WITHHELD_TOOLS = Object.freeze([
|
|
32
33
|
...PUBLIC_WITHHELD_TOOLS, ...PUBLIC_ONLY_WITHHELD_TOOLS,
|
|
33
34
|
]);
|
|
35
|
+
|
|
36
|
+
// F145: what comes back on a turn the kernel verified its owner woke, so the
|
|
37
|
+
// owner keeps a remembering agent. The kernel refuses these writes on any other
|
|
38
|
+
// public turn, whatever an adapter offers.
|
|
39
|
+
export const OWNER_WOKEN_MEMORY_TOOLS = Object.freeze([
|
|
40
|
+
'commonly_write_agent_memory',
|
|
41
|
+
'commonly_save_my_memory',
|
|
42
|
+
'commonly_log_cycle',
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
/** What a public seat is not offered on this turn. Only a literal `true` opens it. */
|
|
46
|
+
export const publicSeatWithheldTools = (ctx) => (ctx?.ownerWoken === true
|
|
47
|
+
? PUBLIC_SEAT_WITHHELD_TOOLS.filter((tool) => !OWNER_WOKEN_MEMORY_TOOLS.includes(tool))
|
|
48
|
+
: PUBLIC_SEAT_WITHHELD_TOOLS);
|
|
@@ -81,6 +81,16 @@ export const isCapacityRefusal = (status) => (
|
|
|
81
81
|
status === undefined || status === null || status === 429 || status >= 500
|
|
82
82
|
);
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* The events a turn reads: its batch, or the one event it ran. A batch's own
|
|
86
|
+
* `_id` is synthetic, so the batch list is the only real answer for one. Only
|
|
87
|
+
* the wrapper builds that list, so it counts only on the batch type.
|
|
88
|
+
*/
|
|
89
|
+
export const turnEventIds = (event) => {
|
|
90
|
+
if (event?.type === 'inbox.batch' && Array.isArray(event.payload?.batchEventIds)) return event.payload.batchEventIds;
|
|
91
|
+
return event?._id ? [String(event._id)] : [];
|
|
92
|
+
};
|
|
93
|
+
|
|
84
94
|
/**
|
|
85
95
|
* A 404 with no `code` is the route missing, not this caller being refused.
|
|
86
96
|
*
|
|
@@ -178,13 +188,17 @@ export const revokeOrphanedSpawnCredentials = async ({ client, log = () => {} })
|
|
|
178
188
|
};
|
|
179
189
|
|
|
180
190
|
/**
|
|
181
|
-
* Open one lease. Returns `{ token, credentialId, source, expiresAt, grantedSeconds }`.
|
|
191
|
+
* Open one lease. Returns `{ token, credentialId, source, expiresAt, grantedSeconds, ownerWoken }`.
|
|
182
192
|
*
|
|
183
193
|
* `source` is `'spawn'` when the child got a scoped credential and
|
|
184
194
|
* `'seat-fallback'` when it got the seat token because the server could not
|
|
185
195
|
* mint. A refusal (a verdict — see the header) throws with
|
|
186
196
|
* `spawnCredentialRefused` set and the status attached, so the caller fails the
|
|
187
197
|
* spawn closed rather than falling back.
|
|
198
|
+
*
|
|
199
|
+
* `ownerWoken` (F145) is true only when the server said exactly that. A seat
|
|
200
|
+
* token can't be marked, and an older backend doesn't answer, so both read as
|
|
201
|
+
* false and the memory tools stay withheld.
|
|
188
202
|
*/
|
|
189
203
|
export const openSpawnCredential = async ({
|
|
190
204
|
client,
|
|
@@ -192,6 +206,8 @@ export const openSpawnCredential = async ({
|
|
|
192
206
|
spawnId,
|
|
193
207
|
desiredTtlSeconds = null,
|
|
194
208
|
policy = null,
|
|
209
|
+
publicSeat = false,
|
|
210
|
+
eventIds = [],
|
|
195
211
|
log = () => {},
|
|
196
212
|
}) => {
|
|
197
213
|
const cap = typeof policy?.maxTtlSeconds === 'number' ? policy.maxTtlSeconds : null;
|
|
@@ -209,18 +225,24 @@ export const openSpawnCredential = async ({
|
|
|
209
225
|
try {
|
|
210
226
|
minted = await client.post(
|
|
211
227
|
SPAWN_CREDENTIAL_BASE,
|
|
212
|
-
|
|
228
|
+
{
|
|
229
|
+
spawnId,
|
|
230
|
+
...(ask === null ? {} : { ttlSeconds: ask }),
|
|
231
|
+
...(publicSeat ? { publicSeat: true, eventIds } : {}),
|
|
232
|
+
},
|
|
213
233
|
);
|
|
214
234
|
} catch (err) {
|
|
215
235
|
const status = err?.status ?? null;
|
|
216
236
|
if (isCapacityRefusal(status === null ? undefined : status)) {
|
|
217
237
|
log(`spawn credential unavailable (${status === null ? 'no response' : `HTTP ${status}`}) — spawning with the seat token`);
|
|
218
|
-
return {
|
|
238
|
+
return {
|
|
239
|
+
token: seatToken, credentialId: null, source: 'seat-fallback', expiresAt: null, grantedSeconds: null, ownerWoken: false,
|
|
240
|
+
};
|
|
219
241
|
}
|
|
220
242
|
if (isRouteAbsentRefusal(status, err?.body)) {
|
|
221
243
|
log('spawn credential route absent on this backend (HTTP 404 with no code) — spawning with the seat token');
|
|
222
244
|
return {
|
|
223
|
-
token: seatToken, credentialId: null, source: 'seat-fallback', expiresAt: null, grantedSeconds: null, reason: 'route-absent',
|
|
245
|
+
token: seatToken, credentialId: null, source: 'seat-fallback', expiresAt: null, grantedSeconds: null, ownerWoken: false, reason: 'route-absent',
|
|
224
246
|
};
|
|
225
247
|
}
|
|
226
248
|
const code = err?.body?.code ? ` code=${err.body.code}` : '';
|
|
@@ -240,7 +262,7 @@ export const openSpawnCredential = async ({
|
|
|
240
262
|
if (typeof minted?.token !== 'string' || !minted.token.trim()) {
|
|
241
263
|
log('spawn credential response carried no token — spawning with the seat token');
|
|
242
264
|
return {
|
|
243
|
-
token: seatToken, credentialId: null, source: 'seat-fallback', expiresAt: null, grantedSeconds: null, reason: 'no-token',
|
|
265
|
+
token: seatToken, credentialId: null, source: 'seat-fallback', expiresAt: null, grantedSeconds: null, ownerWoken: false, reason: 'no-token',
|
|
244
266
|
};
|
|
245
267
|
}
|
|
246
268
|
|
|
@@ -253,6 +275,7 @@ export const openSpawnCredential = async ({
|
|
|
253
275
|
source: 'spawn',
|
|
254
276
|
expiresAt: minted.expiresAt || null,
|
|
255
277
|
grantedSeconds,
|
|
278
|
+
ownerWoken: minted.ownerWoken === true,
|
|
256
279
|
};
|
|
257
280
|
};
|
|
258
281
|
|
|
@@ -275,6 +298,8 @@ export const createSpawnCredentialLease = ({
|
|
|
275
298
|
spawnId,
|
|
276
299
|
desiredTtlSeconds = null,
|
|
277
300
|
policy = null,
|
|
301
|
+
publicSeat = false,
|
|
302
|
+
eventIds = [],
|
|
278
303
|
log = () => {},
|
|
279
304
|
setIntervalImpl = setInterval,
|
|
280
305
|
clearIntervalImpl = clearInterval,
|
|
@@ -337,7 +362,9 @@ export const createSpawnCredentialLease = ({
|
|
|
337
362
|
|
|
338
363
|
return {
|
|
339
364
|
async open() {
|
|
340
|
-
const opened = await openSpawnCredential({
|
|
365
|
+
const opened = await openSpawnCredential({
|
|
366
|
+
client, seatToken, spawnId, desiredTtlSeconds, policy, publicSeat, eventIds, log,
|
|
367
|
+
});
|
|
341
368
|
credentialId = opened.credentialId;
|
|
342
369
|
grantedSeconds = opened.grantedSeconds;
|
|
343
370
|
if (opened.source === 'spawn' && credentialId) startRenewal();
|