@askexenow/exe-os 0.8.80 → 0.8.82
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/dist/bin/backfill-conversations.js +359 -267
- package/dist/bin/backfill-responses.js +357 -265
- package/dist/bin/backfill-vectors.js +339 -264
- package/dist/bin/cleanup-stale-review-tasks.js +315 -256
- package/dist/bin/cli.js +494 -240
- package/dist/bin/exe-agent.js +141 -46
- package/dist/bin/exe-assign.js +151 -63
- package/dist/bin/exe-boot.js +294 -115
- package/dist/bin/exe-call.js +76 -51
- package/dist/bin/exe-cloud.js +58 -45
- package/dist/bin/exe-dispatch.js +434 -277
- package/dist/bin/exe-doctor.js +317 -246
- package/dist/bin/exe-export-behaviors.js +328 -248
- package/dist/bin/exe-forget.js +314 -231
- package/dist/bin/exe-gateway.js +2676 -1402
- package/dist/bin/exe-heartbeat.js +329 -264
- package/dist/bin/exe-kill.js +324 -244
- package/dist/bin/exe-launch-agent.js +574 -463
- package/dist/bin/exe-link.js +1055 -95
- package/dist/bin/exe-new-employee.js +49 -54
- package/dist/bin/exe-pending-messages.js +310 -253
- package/dist/bin/exe-pending-notifications.js +299 -228
- package/dist/bin/exe-pending-reviews.js +314 -245
- package/dist/bin/exe-rename.js +259 -195
- package/dist/bin/exe-review.js +140 -64
- package/dist/bin/exe-search.js +543 -356
- package/dist/bin/exe-session-cleanup.js +463 -382
- package/dist/bin/exe-settings.js +129 -99
- package/dist/bin/exe-start.sh +6 -6
- package/dist/bin/exe-status.js +95 -36
- package/dist/bin/exe-team.js +116 -51
- package/dist/bin/git-sweep.js +482 -307
- package/dist/bin/graph-backfill.js +357 -245
- package/dist/bin/graph-export.js +324 -244
- package/dist/bin/install.js +33 -10
- package/dist/bin/scan-tasks.js +481 -307
- package/dist/bin/setup.js +1147 -140
- package/dist/bin/shard-migrate.js +321 -241
- package/dist/bin/update.js +1 -7
- package/dist/bin/wiki-sync.js +318 -238
- package/dist/gateway/index.js +2656 -1383
- package/dist/hooks/bug-report-worker.js +641 -472
- package/dist/hooks/commit-complete.js +482 -307
- package/dist/hooks/error-recall.js +363 -135
- package/dist/hooks/exe-heartbeat-hook.js +97 -27
- package/dist/hooks/ingest-worker.js +584 -397
- package/dist/hooks/ingest.js +123 -58
- package/dist/hooks/instructions-loaded.js +212 -82
- package/dist/hooks/notification.js +200 -70
- package/dist/hooks/post-compact.js +199 -81
- package/dist/hooks/pre-compact.js +352 -140
- package/dist/hooks/pre-tool-use.js +416 -278
- package/dist/hooks/prompt-ingest-worker.js +376 -299
- package/dist/hooks/prompt-submit.js +414 -188
- package/dist/hooks/response-ingest-worker.js +408 -338
- package/dist/hooks/session-end.js +209 -83
- package/dist/hooks/session-start.js +382 -158
- package/dist/hooks/stop.js +209 -83
- package/dist/hooks/subagent-stop.js +209 -85
- package/dist/hooks/summary-worker.js +606 -510
- package/dist/index.js +2133 -855
- package/dist/lib/cloud-sync.js +1175 -184
- package/dist/lib/config.js +1 -9
- package/dist/lib/consolidation.js +71 -34
- package/dist/lib/database.js +166 -14
- package/dist/lib/device-registry.js +189 -117
- package/dist/lib/embedder.js +6 -10
- package/dist/lib/employee-templates.js +134 -39
- package/dist/lib/employees.js +30 -7
- package/dist/lib/exe-daemon-client.js +5 -7
- package/dist/lib/exe-daemon.js +514 -152
- package/dist/lib/hybrid-search.js +543 -356
- package/dist/lib/identity-templates.js +15 -15
- package/dist/lib/identity.js +19 -15
- package/dist/lib/license.js +1 -7
- package/dist/lib/messaging.js +157 -135
- package/dist/lib/reminders.js +97 -0
- package/dist/lib/schedules.js +302 -231
- package/dist/lib/skill-learning.js +33 -27
- package/dist/lib/status-brief.js +11 -14
- package/dist/lib/store.js +326 -237
- package/dist/lib/task-router.js +105 -1
- package/dist/lib/tasks.js +233 -116
- package/dist/lib/tmux-routing.js +173 -56
- package/dist/lib/ws-client.js +13 -3
- package/dist/mcp/server.js +2009 -1015
- package/dist/mcp/tools/complete-reminder.js +97 -0
- package/dist/mcp/tools/create-reminder.js +97 -0
- package/dist/mcp/tools/create-task.js +426 -262
- package/dist/mcp/tools/deactivate-behavior.js +119 -44
- package/dist/mcp/tools/list-reminders.js +97 -0
- package/dist/mcp/tools/list-tasks.js +56 -57
- package/dist/mcp/tools/send-message.js +206 -143
- package/dist/mcp/tools/update-task.js +259 -85
- package/dist/runtime/index.js +495 -316
- package/dist/tui/App.js +1128 -919
- package/package.json +2 -10
- package/src/commands/exe/afk.md +8 -8
- package/src/commands/exe/assign.md +1 -1
- package/src/commands/exe/build-adv.md +1 -1
- package/src/commands/exe/call.md +10 -10
- package/src/commands/exe/employee-heartbeat.md +9 -6
- package/src/commands/exe/heartbeat.md +5 -5
- package/src/commands/exe/intercom.md +26 -15
- package/src/commands/exe/launch.md +2 -2
- package/src/commands/exe/new-employee.md +1 -1
- package/src/commands/exe/review.md +2 -2
- package/src/commands/exe/schedule.md +1 -1
- package/src/commands/exe/sessions.md +2 -2
- package/src/commands/exe.md +22 -20
|
@@ -165,13 +165,7 @@ var init_config = __esm({
|
|
|
165
165
|
wikiUrl: "",
|
|
166
166
|
wikiApiKey: "",
|
|
167
167
|
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
168
|
-
wikiWorkspaceMapping: {
|
|
169
|
-
exe: "Executive",
|
|
170
|
-
yoshi: "Engineering",
|
|
171
|
-
mari: "Marketing",
|
|
172
|
-
tom: "Engineering",
|
|
173
|
-
sasha: "Production"
|
|
174
|
-
},
|
|
168
|
+
wikiWorkspaceMapping: {},
|
|
175
169
|
wikiAutoUpdate: true,
|
|
176
170
|
wikiAutoUpdateThreshold: 0.5,
|
|
177
171
|
wikiAutoUpdateCreateNew: true,
|
|
@@ -243,14 +237,212 @@ var init_session_key = __esm({
|
|
|
243
237
|
}
|
|
244
238
|
});
|
|
245
239
|
|
|
246
|
-
// src/lib/
|
|
247
|
-
|
|
240
|
+
// src/lib/employees.ts
|
|
241
|
+
var employees_exports = {};
|
|
242
|
+
__export(employees_exports, {
|
|
243
|
+
COORDINATOR_ROLE: () => COORDINATOR_ROLE,
|
|
244
|
+
DEFAULT_COORDINATOR_TEMPLATE_NAME: () => DEFAULT_COORDINATOR_TEMPLATE_NAME,
|
|
245
|
+
EMPLOYEES_PATH: () => EMPLOYEES_PATH,
|
|
246
|
+
addEmployee: () => addEmployee,
|
|
247
|
+
canCoordinate: () => canCoordinate,
|
|
248
|
+
getCoordinatorEmployee: () => getCoordinatorEmployee,
|
|
249
|
+
getCoordinatorName: () => getCoordinatorName,
|
|
250
|
+
getEmployee: () => getEmployee,
|
|
251
|
+
getEmployeeByRole: () => getEmployeeByRole,
|
|
252
|
+
getEmployeeNamesByRole: () => getEmployeeNamesByRole,
|
|
253
|
+
hasRole: () => hasRole,
|
|
254
|
+
isCoordinatorName: () => isCoordinatorName,
|
|
255
|
+
isCoordinatorRole: () => isCoordinatorRole,
|
|
256
|
+
isMultiInstance: () => isMultiInstance,
|
|
257
|
+
loadEmployees: () => loadEmployees,
|
|
258
|
+
loadEmployeesSync: () => loadEmployeesSync,
|
|
259
|
+
normalizeRole: () => normalizeRole,
|
|
260
|
+
normalizeRosterCase: () => normalizeRosterCase,
|
|
261
|
+
registerBinSymlinks: () => registerBinSymlinks,
|
|
262
|
+
saveEmployees: () => saveEmployees,
|
|
263
|
+
validateEmployeeName: () => validateEmployeeName
|
|
264
|
+
});
|
|
265
|
+
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
266
|
+
import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
|
|
267
|
+
import { execSync as execSync2 } from "child_process";
|
|
268
|
+
import path2 from "path";
|
|
248
269
|
import os2 from "os";
|
|
270
|
+
function normalizeRole(role) {
|
|
271
|
+
return (role ?? "").trim().toLowerCase();
|
|
272
|
+
}
|
|
273
|
+
function isCoordinatorRole(role) {
|
|
274
|
+
return normalizeRole(role) === normalizeRole(COORDINATOR_ROLE);
|
|
275
|
+
}
|
|
276
|
+
function getCoordinatorEmployee(employees) {
|
|
277
|
+
return employees.find((e) => isCoordinatorRole(e.role));
|
|
278
|
+
}
|
|
279
|
+
function getCoordinatorName(employees = loadEmployeesSync()) {
|
|
280
|
+
return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
|
|
281
|
+
}
|
|
282
|
+
function isCoordinatorName(agentName, employees = loadEmployeesSync()) {
|
|
283
|
+
if (!agentName) return false;
|
|
284
|
+
return agentName.toLowerCase() === getCoordinatorName(employees).toLowerCase();
|
|
285
|
+
}
|
|
286
|
+
function canCoordinate(agentName, agentRole, employees = loadEmployeesSync()) {
|
|
287
|
+
return agentName === "default" || isCoordinatorRole(agentRole) || isCoordinatorName(agentName, employees);
|
|
288
|
+
}
|
|
289
|
+
function validateEmployeeName(name) {
|
|
290
|
+
if (!name) {
|
|
291
|
+
return { valid: false, error: "Name is required" };
|
|
292
|
+
}
|
|
293
|
+
if (name.length > 32) {
|
|
294
|
+
return { valid: false, error: "Name must be 32 characters or fewer" };
|
|
295
|
+
}
|
|
296
|
+
if (!/^[a-z][a-z0-9]*$/.test(name)) {
|
|
297
|
+
return {
|
|
298
|
+
valid: false,
|
|
299
|
+
error: "Name must start with a letter and contain only lowercase alphanumeric characters"
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return { valid: true };
|
|
303
|
+
}
|
|
304
|
+
async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
|
|
305
|
+
if (!existsSync2(employeesPath)) {
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
const raw = await readFile2(employeesPath, "utf-8");
|
|
309
|
+
try {
|
|
310
|
+
return JSON.parse(raw);
|
|
311
|
+
} catch {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
async function saveEmployees(employees, employeesPath = EMPLOYEES_PATH) {
|
|
316
|
+
await mkdir2(path2.dirname(employeesPath), { recursive: true });
|
|
317
|
+
await writeFile2(employeesPath, JSON.stringify(employees, null, 2) + "\n", "utf-8");
|
|
318
|
+
}
|
|
319
|
+
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
320
|
+
if (!existsSync2(employeesPath)) return [];
|
|
321
|
+
try {
|
|
322
|
+
return JSON.parse(readFileSync2(employeesPath, "utf-8"));
|
|
323
|
+
} catch {
|
|
324
|
+
return [];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function getEmployee(employees, name) {
|
|
328
|
+
return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
|
|
329
|
+
}
|
|
330
|
+
function getEmployeeByRole(employees, role) {
|
|
331
|
+
const lower = role.toLowerCase();
|
|
332
|
+
return employees.find((e) => e.role.toLowerCase() === lower);
|
|
333
|
+
}
|
|
334
|
+
function getEmployeeNamesByRole(employees, role) {
|
|
335
|
+
const lower = role.toLowerCase();
|
|
336
|
+
return employees.filter((e) => e.role.toLowerCase() === lower).map((e) => e.name);
|
|
337
|
+
}
|
|
338
|
+
function hasRole(agentName, role) {
|
|
339
|
+
const employees = loadEmployeesSync();
|
|
340
|
+
const emp = getEmployee(employees, agentName);
|
|
341
|
+
return emp ? emp.role.toLowerCase() === role.toLowerCase() : false;
|
|
342
|
+
}
|
|
343
|
+
function isMultiInstance(agentName, employees) {
|
|
344
|
+
const roster = employees ?? loadEmployeesSync();
|
|
345
|
+
const emp = getEmployee(roster, agentName);
|
|
346
|
+
if (!emp) return false;
|
|
347
|
+
return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
|
|
348
|
+
}
|
|
349
|
+
function addEmployee(employees, employee) {
|
|
350
|
+
const normalized = { ...employee, name: employee.name.toLowerCase() };
|
|
351
|
+
if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
|
|
352
|
+
throw new Error(`Employee '${normalized.name}' already exists`);
|
|
353
|
+
}
|
|
354
|
+
return [...employees, normalized];
|
|
355
|
+
}
|
|
356
|
+
async function normalizeRosterCase(rosterPath) {
|
|
357
|
+
const employees = await loadEmployees(rosterPath);
|
|
358
|
+
let changed = false;
|
|
359
|
+
for (const emp of employees) {
|
|
360
|
+
if (emp.name !== emp.name.toLowerCase()) {
|
|
361
|
+
const oldName = emp.name;
|
|
362
|
+
emp.name = emp.name.toLowerCase();
|
|
363
|
+
changed = true;
|
|
364
|
+
try {
|
|
365
|
+
const identityDir = path2.join(os2.homedir(), ".exe-os", "identity");
|
|
366
|
+
const oldPath = path2.join(identityDir, `${oldName}.md`);
|
|
367
|
+
const newPath = path2.join(identityDir, `${emp.name}.md`);
|
|
368
|
+
if (existsSync2(oldPath) && !existsSync2(newPath)) {
|
|
369
|
+
renameSync2(oldPath, newPath);
|
|
370
|
+
} else if (existsSync2(oldPath) && oldPath !== newPath) {
|
|
371
|
+
const content = readFileSync2(oldPath, "utf-8");
|
|
372
|
+
writeFileSync(newPath, content, "utf-8");
|
|
373
|
+
if (oldPath.toLowerCase() !== newPath.toLowerCase()) {
|
|
374
|
+
unlinkSync(oldPath);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (changed) {
|
|
382
|
+
await saveEmployees(employees, rosterPath);
|
|
383
|
+
}
|
|
384
|
+
return changed;
|
|
385
|
+
}
|
|
386
|
+
function findExeBin() {
|
|
387
|
+
try {
|
|
388
|
+
return execSync2(process.platform === "win32" ? "where exe-os" : "which exe-os", { encoding: "utf8" }).trim();
|
|
389
|
+
} catch {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function registerBinSymlinks(name) {
|
|
394
|
+
const created = [];
|
|
395
|
+
const skipped = [];
|
|
396
|
+
const errors = [];
|
|
397
|
+
const exeBinPath = findExeBin();
|
|
398
|
+
if (!exeBinPath) {
|
|
399
|
+
errors.push("Could not find 'exe-os' in PATH");
|
|
400
|
+
return { created, skipped, errors };
|
|
401
|
+
}
|
|
402
|
+
const binDir = path2.dirname(exeBinPath);
|
|
403
|
+
let target;
|
|
404
|
+
try {
|
|
405
|
+
target = readlinkSync(exeBinPath);
|
|
406
|
+
} catch {
|
|
407
|
+
errors.push("Could not read 'exe' symlink");
|
|
408
|
+
return { created, skipped, errors };
|
|
409
|
+
}
|
|
410
|
+
for (const suffix of ["", "-opencode"]) {
|
|
411
|
+
const linkName = `${name}${suffix}`;
|
|
412
|
+
const linkPath = path2.join(binDir, linkName);
|
|
413
|
+
if (existsSync2(linkPath)) {
|
|
414
|
+
skipped.push(linkName);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
try {
|
|
418
|
+
symlinkSync(target, linkPath);
|
|
419
|
+
created.push(linkName);
|
|
420
|
+
} catch (err) {
|
|
421
|
+
errors.push(`${linkName}: ${err instanceof Error ? err.message : String(err)}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return { created, skipped, errors };
|
|
425
|
+
}
|
|
426
|
+
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE, MULTI_INSTANCE_ROLES;
|
|
427
|
+
var init_employees = __esm({
|
|
428
|
+
"src/lib/employees.ts"() {
|
|
429
|
+
"use strict";
|
|
430
|
+
init_config();
|
|
431
|
+
EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
432
|
+
DEFAULT_COORDINATOR_TEMPLATE_NAME = "exe";
|
|
433
|
+
COORDINATOR_ROLE = "COO";
|
|
434
|
+
MULTI_INSTANCE_ROLES = /* @__PURE__ */ new Set(["principal engineer", "content production specialist", "staff code reviewer"]);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// src/lib/session-registry.ts
|
|
439
|
+
import path4 from "path";
|
|
440
|
+
import os3 from "os";
|
|
249
441
|
var REGISTRY_PATH;
|
|
250
442
|
var init_session_registry = __esm({
|
|
251
443
|
"src/lib/session-registry.ts"() {
|
|
252
444
|
"use strict";
|
|
253
|
-
REGISTRY_PATH =
|
|
445
|
+
REGISTRY_PATH = path4.join(os3.homedir(), ".exe-os", "session-registry.json");
|
|
254
446
|
}
|
|
255
447
|
});
|
|
256
448
|
|
|
@@ -362,7 +554,7 @@ var init_transport = __esm({
|
|
|
362
554
|
});
|
|
363
555
|
|
|
364
556
|
// src/lib/cc-agent-support.ts
|
|
365
|
-
import { execSync as
|
|
557
|
+
import { execSync as execSync4 } from "child_process";
|
|
366
558
|
var init_cc_agent_support = __esm({
|
|
367
559
|
"src/lib/cc-agent-support.ts"() {
|
|
368
560
|
"use strict";
|
|
@@ -391,16 +583,16 @@ var init_provider_table = __esm({
|
|
|
391
583
|
});
|
|
392
584
|
|
|
393
585
|
// src/lib/intercom-queue.ts
|
|
394
|
-
import { readFileSync as
|
|
395
|
-
import
|
|
396
|
-
import
|
|
586
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, renameSync as renameSync3, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "fs";
|
|
587
|
+
import path5 from "path";
|
|
588
|
+
import os4 from "os";
|
|
397
589
|
var QUEUE_PATH, TTL_MS, INTERCOM_LOG;
|
|
398
590
|
var init_intercom_queue = __esm({
|
|
399
591
|
"src/lib/intercom-queue.ts"() {
|
|
400
592
|
"use strict";
|
|
401
|
-
QUEUE_PATH =
|
|
593
|
+
QUEUE_PATH = path5.join(os4.homedir(), ".exe-os", "intercom-queue.json");
|
|
402
594
|
TTL_MS = 60 * 60 * 1e3;
|
|
403
|
-
INTERCOM_LOG =
|
|
595
|
+
INTERCOM_LOG = path5.join(os4.homedir(), ".exe-os", "intercom.log");
|
|
404
596
|
}
|
|
405
597
|
});
|
|
406
598
|
|
|
@@ -443,7 +635,7 @@ function wrapWithRetry(client) {
|
|
|
443
635
|
return (sql) => retryOnBusy(() => target.execute(sql), "execute");
|
|
444
636
|
}
|
|
445
637
|
if (prop === "batch") {
|
|
446
|
-
return (stmts) => retryOnBusy(() => target.batch(stmts), "batch");
|
|
638
|
+
return (stmts, mode) => retryOnBusy(() => target.batch(stmts, mode), "batch");
|
|
447
639
|
}
|
|
448
640
|
return Reflect.get(target, prop, receiver);
|
|
449
641
|
}
|
|
@@ -606,22 +798,24 @@ async function ensureSchema() {
|
|
|
606
798
|
ON behaviors(agent_id, active);
|
|
607
799
|
`);
|
|
608
800
|
try {
|
|
801
|
+
const coordinatorName = getCoordinatorName();
|
|
609
802
|
const existing = await client.execute({
|
|
610
|
-
sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id =
|
|
611
|
-
args: []
|
|
803
|
+
sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id = ?",
|
|
804
|
+
args: [coordinatorName]
|
|
612
805
|
});
|
|
613
806
|
if (Number(existing.rows[0]?.cnt) === 0) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
807
|
+
const seededAt = "2026-03-25T00:00:00Z";
|
|
808
|
+
for (const [domain, content] of [
|
|
809
|
+
["workflow", `Don't ask "keep going?" \u2014 just keep executing phases/plans autonomously`],
|
|
810
|
+
["tool-use", "Always use create_task MCP tool, never write .md files directly for task creation"],
|
|
811
|
+
["workflow", "Auto-start reviewing when idle and reviews are pending \u2014 never ask founder for permission"]
|
|
812
|
+
]) {
|
|
813
|
+
await client.execute({
|
|
814
|
+
sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
|
|
815
|
+
VALUES (hex(randomblob(16)), ?, NULL, ?, ?, 1, ?, ?)`,
|
|
816
|
+
args: [coordinatorName, domain, content, seededAt, seededAt]
|
|
817
|
+
});
|
|
818
|
+
}
|
|
625
819
|
}
|
|
626
820
|
} catch {
|
|
627
821
|
}
|
|
@@ -1313,6 +1507,39 @@ async function ensureSchema() {
|
|
|
1313
1507
|
} catch {
|
|
1314
1508
|
}
|
|
1315
1509
|
}
|
|
1510
|
+
try {
|
|
1511
|
+
await client.execute({
|
|
1512
|
+
sql: `ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0`,
|
|
1513
|
+
args: []
|
|
1514
|
+
});
|
|
1515
|
+
} catch {
|
|
1516
|
+
}
|
|
1517
|
+
try {
|
|
1518
|
+
await client.execute(
|
|
1519
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_draft ON memories(draft) WHERE draft = 1`
|
|
1520
|
+
);
|
|
1521
|
+
} catch {
|
|
1522
|
+
}
|
|
1523
|
+
try {
|
|
1524
|
+
await client.execute({
|
|
1525
|
+
sql: `ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'`,
|
|
1526
|
+
args: []
|
|
1527
|
+
});
|
|
1528
|
+
} catch {
|
|
1529
|
+
}
|
|
1530
|
+
try {
|
|
1531
|
+
await client.execute(
|
|
1532
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(memory_type)`
|
|
1533
|
+
);
|
|
1534
|
+
} catch {
|
|
1535
|
+
}
|
|
1536
|
+
try {
|
|
1537
|
+
await client.execute({
|
|
1538
|
+
sql: `ALTER TABLE memories ADD COLUMN trajectory TEXT`,
|
|
1539
|
+
args: []
|
|
1540
|
+
});
|
|
1541
|
+
} catch {
|
|
1542
|
+
}
|
|
1316
1543
|
}
|
|
1317
1544
|
async function disposeDatabase() {
|
|
1318
1545
|
if (_client) {
|
|
@@ -1326,6 +1553,7 @@ var init_database = __esm({
|
|
|
1326
1553
|
"src/lib/database.ts"() {
|
|
1327
1554
|
"use strict";
|
|
1328
1555
|
init_db_retry();
|
|
1556
|
+
init_employees();
|
|
1329
1557
|
_client = null;
|
|
1330
1558
|
_resilientClient = null;
|
|
1331
1559
|
initTurso = initDatabase;
|
|
@@ -1333,175 +1561,6 @@ var init_database = __esm({
|
|
|
1333
1561
|
}
|
|
1334
1562
|
});
|
|
1335
1563
|
|
|
1336
|
-
// src/lib/employees.ts
|
|
1337
|
-
var employees_exports = {};
|
|
1338
|
-
__export(employees_exports, {
|
|
1339
|
-
EMPLOYEES_PATH: () => EMPLOYEES_PATH,
|
|
1340
|
-
addEmployee: () => addEmployee,
|
|
1341
|
-
getEmployee: () => getEmployee,
|
|
1342
|
-
getEmployeeByRole: () => getEmployeeByRole,
|
|
1343
|
-
getEmployeeNamesByRole: () => getEmployeeNamesByRole,
|
|
1344
|
-
hasRole: () => hasRole,
|
|
1345
|
-
isMultiInstance: () => isMultiInstance,
|
|
1346
|
-
loadEmployees: () => loadEmployees,
|
|
1347
|
-
loadEmployeesSync: () => loadEmployeesSync,
|
|
1348
|
-
normalizeRosterCase: () => normalizeRosterCase,
|
|
1349
|
-
registerBinSymlinks: () => registerBinSymlinks,
|
|
1350
|
-
saveEmployees: () => saveEmployees,
|
|
1351
|
-
validateEmployeeName: () => validateEmployeeName
|
|
1352
|
-
});
|
|
1353
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
1354
|
-
import { existsSync as existsSync3, symlinkSync, readlinkSync, readFileSync as readFileSync4, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1355
|
-
import { execSync as execSync4 } from "child_process";
|
|
1356
|
-
import path5 from "path";
|
|
1357
|
-
import os4 from "os";
|
|
1358
|
-
function validateEmployeeName(name) {
|
|
1359
|
-
if (!name) {
|
|
1360
|
-
return { valid: false, error: "Name is required" };
|
|
1361
|
-
}
|
|
1362
|
-
if (name.length > 32) {
|
|
1363
|
-
return { valid: false, error: "Name must be 32 characters or fewer" };
|
|
1364
|
-
}
|
|
1365
|
-
if (!/^[a-z][a-z0-9]*$/.test(name)) {
|
|
1366
|
-
return {
|
|
1367
|
-
valid: false,
|
|
1368
|
-
error: "Name must start with a letter and contain only lowercase alphanumeric characters"
|
|
1369
|
-
};
|
|
1370
|
-
}
|
|
1371
|
-
return { valid: true };
|
|
1372
|
-
}
|
|
1373
|
-
async function loadEmployees(employeesPath = EMPLOYEES_PATH) {
|
|
1374
|
-
if (!existsSync3(employeesPath)) {
|
|
1375
|
-
return [];
|
|
1376
|
-
}
|
|
1377
|
-
const raw = await readFile2(employeesPath, "utf-8");
|
|
1378
|
-
try {
|
|
1379
|
-
return JSON.parse(raw);
|
|
1380
|
-
} catch {
|
|
1381
|
-
return [];
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
async function saveEmployees(employees, employeesPath = EMPLOYEES_PATH) {
|
|
1385
|
-
await mkdir2(path5.dirname(employeesPath), { recursive: true });
|
|
1386
|
-
await writeFile2(employeesPath, JSON.stringify(employees, null, 2) + "\n", "utf-8");
|
|
1387
|
-
}
|
|
1388
|
-
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
1389
|
-
if (!existsSync3(employeesPath)) return [];
|
|
1390
|
-
try {
|
|
1391
|
-
return JSON.parse(readFileSync4(employeesPath, "utf-8"));
|
|
1392
|
-
} catch {
|
|
1393
|
-
return [];
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
function getEmployee(employees, name) {
|
|
1397
|
-
return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
|
|
1398
|
-
}
|
|
1399
|
-
function getEmployeeByRole(employees, role) {
|
|
1400
|
-
const lower = role.toLowerCase();
|
|
1401
|
-
return employees.find((e) => e.role.toLowerCase() === lower);
|
|
1402
|
-
}
|
|
1403
|
-
function getEmployeeNamesByRole(employees, role) {
|
|
1404
|
-
const lower = role.toLowerCase();
|
|
1405
|
-
return employees.filter((e) => e.role.toLowerCase() === lower).map((e) => e.name);
|
|
1406
|
-
}
|
|
1407
|
-
function hasRole(agentName, role) {
|
|
1408
|
-
const employees = loadEmployeesSync();
|
|
1409
|
-
const emp = getEmployee(employees, agentName);
|
|
1410
|
-
return emp ? emp.role.toLowerCase() === role.toLowerCase() : false;
|
|
1411
|
-
}
|
|
1412
|
-
function isMultiInstance(agentName, employees) {
|
|
1413
|
-
const roster = employees ?? loadEmployeesSync();
|
|
1414
|
-
const emp = getEmployee(roster, agentName);
|
|
1415
|
-
if (!emp) return false;
|
|
1416
|
-
return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
|
|
1417
|
-
}
|
|
1418
|
-
function addEmployee(employees, employee) {
|
|
1419
|
-
const normalized = { ...employee, name: employee.name.toLowerCase() };
|
|
1420
|
-
if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
|
|
1421
|
-
throw new Error(`Employee '${normalized.name}' already exists`);
|
|
1422
|
-
}
|
|
1423
|
-
return [...employees, normalized];
|
|
1424
|
-
}
|
|
1425
|
-
async function normalizeRosterCase(rosterPath) {
|
|
1426
|
-
const employees = await loadEmployees(rosterPath);
|
|
1427
|
-
let changed = false;
|
|
1428
|
-
for (const emp of employees) {
|
|
1429
|
-
if (emp.name !== emp.name.toLowerCase()) {
|
|
1430
|
-
const oldName = emp.name;
|
|
1431
|
-
emp.name = emp.name.toLowerCase();
|
|
1432
|
-
changed = true;
|
|
1433
|
-
try {
|
|
1434
|
-
const identityDir = path5.join(os4.homedir(), ".exe-os", "identity");
|
|
1435
|
-
const oldPath = path5.join(identityDir, `${oldName}.md`);
|
|
1436
|
-
const newPath = path5.join(identityDir, `${emp.name}.md`);
|
|
1437
|
-
if (existsSync3(oldPath) && !existsSync3(newPath)) {
|
|
1438
|
-
renameSync3(oldPath, newPath);
|
|
1439
|
-
} else if (existsSync3(oldPath) && oldPath !== newPath) {
|
|
1440
|
-
const content = readFileSync4(oldPath, "utf-8");
|
|
1441
|
-
writeFileSync3(newPath, content, "utf-8");
|
|
1442
|
-
if (oldPath.toLowerCase() !== newPath.toLowerCase()) {
|
|
1443
|
-
unlinkSync2(oldPath);
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
} catch {
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
if (changed) {
|
|
1451
|
-
await saveEmployees(employees, rosterPath);
|
|
1452
|
-
}
|
|
1453
|
-
return changed;
|
|
1454
|
-
}
|
|
1455
|
-
function findExeBin() {
|
|
1456
|
-
try {
|
|
1457
|
-
return execSync4(process.platform === "win32" ? "where exe-os" : "which exe-os", { encoding: "utf8" }).trim();
|
|
1458
|
-
} catch {
|
|
1459
|
-
return null;
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
function registerBinSymlinks(name) {
|
|
1463
|
-
const created = [];
|
|
1464
|
-
const skipped = [];
|
|
1465
|
-
const errors = [];
|
|
1466
|
-
const exeBinPath = findExeBin();
|
|
1467
|
-
if (!exeBinPath) {
|
|
1468
|
-
errors.push("Could not find 'exe-os' in PATH");
|
|
1469
|
-
return { created, skipped, errors };
|
|
1470
|
-
}
|
|
1471
|
-
const binDir = path5.dirname(exeBinPath);
|
|
1472
|
-
let target;
|
|
1473
|
-
try {
|
|
1474
|
-
target = readlinkSync(exeBinPath);
|
|
1475
|
-
} catch {
|
|
1476
|
-
errors.push("Could not read 'exe' symlink");
|
|
1477
|
-
return { created, skipped, errors };
|
|
1478
|
-
}
|
|
1479
|
-
for (const suffix of ["", "-opencode"]) {
|
|
1480
|
-
const linkName = `${name}${suffix}`;
|
|
1481
|
-
const linkPath = path5.join(binDir, linkName);
|
|
1482
|
-
if (existsSync3(linkPath)) {
|
|
1483
|
-
skipped.push(linkName);
|
|
1484
|
-
continue;
|
|
1485
|
-
}
|
|
1486
|
-
try {
|
|
1487
|
-
symlinkSync(target, linkPath);
|
|
1488
|
-
created.push(linkName);
|
|
1489
|
-
} catch (err) {
|
|
1490
|
-
errors.push(`${linkName}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
return { created, skipped, errors };
|
|
1494
|
-
}
|
|
1495
|
-
var EMPLOYEES_PATH, MULTI_INSTANCE_ROLES;
|
|
1496
|
-
var init_employees = __esm({
|
|
1497
|
-
"src/lib/employees.ts"() {
|
|
1498
|
-
"use strict";
|
|
1499
|
-
init_config();
|
|
1500
|
-
EMPLOYEES_PATH = path5.join(EXE_AI_DIR, "exe-employees.json");
|
|
1501
|
-
MULTI_INSTANCE_ROLES = /* @__PURE__ */ new Set(["principal engineer", "content production specialist", "staff code reviewer"]);
|
|
1502
|
-
}
|
|
1503
|
-
});
|
|
1504
|
-
|
|
1505
1564
|
// src/lib/license.ts
|
|
1506
1565
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync4, existsSync as existsSync4, mkdirSync as mkdirSync3 } from "fs";
|
|
1507
1566
|
import { randomUUID } from "crypto";
|
|
@@ -1542,8 +1601,10 @@ function getMySession() {
|
|
|
1542
1601
|
return getTransport().getMySession();
|
|
1543
1602
|
}
|
|
1544
1603
|
function extractRootExe(name) {
|
|
1545
|
-
|
|
1546
|
-
|
|
1604
|
+
if (!name) return null;
|
|
1605
|
+
if (!name.includes("-")) return name;
|
|
1606
|
+
const parts = name.split("-").filter(Boolean);
|
|
1607
|
+
return parts.length > 0 ? parts[parts.length - 1] : null;
|
|
1547
1608
|
}
|
|
1548
1609
|
function getParentExe(sessionKey) {
|
|
1549
1610
|
try {
|
|
@@ -1578,6 +1639,7 @@ var init_tmux_routing = __esm({
|
|
|
1578
1639
|
init_provider_table();
|
|
1579
1640
|
init_intercom_queue();
|
|
1580
1641
|
init_plan_limits();
|
|
1642
|
+
init_employees();
|
|
1581
1643
|
SPAWN_LOCK_DIR = path8.join(os5.homedir(), ".exe-os", "spawn-locks");
|
|
1582
1644
|
SESSION_CACHE = path8.join(os5.homedir(), ".exe-os", "session-cache");
|
|
1583
1645
|
INTERCOM_LOG2 = path8.join(os5.homedir(), ".exe-os", "intercom.log");
|
|
@@ -1610,15 +1672,16 @@ var init_task_scope = __esm({
|
|
|
1610
1672
|
}
|
|
1611
1673
|
});
|
|
1612
1674
|
|
|
1613
|
-
// src/lib/
|
|
1614
|
-
var
|
|
1615
|
-
__export(
|
|
1675
|
+
// src/lib/cto-delegation-gate.ts
|
|
1676
|
+
var cto_delegation_gate_exports = {};
|
|
1677
|
+
__export(cto_delegation_gate_exports, {
|
|
1616
1678
|
GATED_AGENT: () => GATED_AGENT,
|
|
1617
1679
|
GATED_ROLE: () => GATED_ROLE,
|
|
1618
1680
|
GATE_BLOCK_MESSAGE: () => GATE_BLOCK_MESSAGE,
|
|
1619
1681
|
classifyPath: () => classifyPath,
|
|
1620
1682
|
evaluateDelegationGate: () => evaluateDelegationGate,
|
|
1621
|
-
|
|
1683
|
+
getGatedAgent: () => getGatedAgent,
|
|
1684
|
+
hasRecentEngineerDispatch: () => hasRecentEngineerDispatch,
|
|
1622
1685
|
hasValidScratchpadEscape: () => hasValidScratchpadEscape,
|
|
1623
1686
|
scratchpadPath: () => scratchpadPath
|
|
1624
1687
|
});
|
|
@@ -1629,11 +1692,14 @@ function resolveGatedAgent() {
|
|
|
1629
1692
|
try {
|
|
1630
1693
|
const employees = loadEmployeesSync();
|
|
1631
1694
|
const cto = getEmployeeByRole(employees, GATED_ROLE);
|
|
1632
|
-
return cto?.name ?? "
|
|
1695
|
+
return cto?.name ?? "";
|
|
1633
1696
|
} catch {
|
|
1634
|
-
return "
|
|
1697
|
+
return "";
|
|
1635
1698
|
}
|
|
1636
1699
|
}
|
|
1700
|
+
function getGatedAgent() {
|
|
1701
|
+
return resolveGatedAgent() || GATED_AGENT;
|
|
1702
|
+
}
|
|
1637
1703
|
function toWorkspaceRelative(filePath, cwd = process.cwd()) {
|
|
1638
1704
|
const normalized = path9.normalize(filePath);
|
|
1639
1705
|
if (normalized.startsWith(cwd + path9.sep)) {
|
|
@@ -1665,13 +1731,15 @@ function classifyPath(filePath, cwd) {
|
|
|
1665
1731
|
if (BLOCKED_PATH_PREFIXES.some((p) => rel.startsWith(p))) return "code";
|
|
1666
1732
|
return "exempt";
|
|
1667
1733
|
}
|
|
1668
|
-
async function
|
|
1734
|
+
async function hasRecentEngineerDispatch(now = Date.now()) {
|
|
1669
1735
|
try {
|
|
1670
1736
|
const client = getClient();
|
|
1671
1737
|
const engineers = loadEmployeesSync().filter(
|
|
1672
1738
|
(e) => e.role.toLowerCase() === "principal engineer"
|
|
1673
1739
|
);
|
|
1674
1740
|
const engineerNames = engineers.map((e) => e.name);
|
|
1741
|
+
const gatedAgent = getGatedAgent();
|
|
1742
|
+
if (!gatedAgent) return false;
|
|
1675
1743
|
if (engineerNames.length === 0) return false;
|
|
1676
1744
|
const placeholders = engineerNames.map(() => "?").join(",");
|
|
1677
1745
|
const ydScope = sessionScopeFilter();
|
|
@@ -1679,7 +1747,7 @@ async function hasRecentTomDispatch(now = Date.now()) {
|
|
|
1679
1747
|
sql: `SELECT MAX(created_at) AS last_dispatch
|
|
1680
1748
|
FROM tasks
|
|
1681
1749
|
WHERE assigned_by = ? AND assigned_to IN (${placeholders})${ydScope.sql}`,
|
|
1682
|
-
args: [
|
|
1750
|
+
args: [gatedAgent, ...engineerNames, ...ydScope.args]
|
|
1683
1751
|
});
|
|
1684
1752
|
const raw = result.rows[0]?.last_dispatch;
|
|
1685
1753
|
if (raw === null || raw === void 0) return false;
|
|
@@ -1695,23 +1763,26 @@ function scratchpadPath(sessionId, homeDir = os6.homedir()) {
|
|
|
1695
1763
|
homeDir,
|
|
1696
1764
|
".exe-os",
|
|
1697
1765
|
"session-cache",
|
|
1698
|
-
`
|
|
1766
|
+
`cto-scratchpad-${sessionId}.txt`
|
|
1699
1767
|
);
|
|
1700
1768
|
}
|
|
1701
1769
|
function hasValidScratchpadEscape(sessionId, now = Date.now(), homeDir = os6.homedir()) {
|
|
1702
|
-
const
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1770
|
+
const paths = [scratchpadPath(sessionId, homeDir)];
|
|
1771
|
+
for (const filePath of paths) {
|
|
1772
|
+
if (!existsSync7(filePath)) continue;
|
|
1773
|
+
try {
|
|
1774
|
+
const stat = statSync(filePath);
|
|
1775
|
+
if (now - stat.mtimeMs > SCRATCHPAD_MAX_AGE_MS) continue;
|
|
1776
|
+
const body = readFileSync8(filePath, "utf-8");
|
|
1777
|
+
if (SCRATCHPAD_ESCAPE_PATTERN.test(body)) return true;
|
|
1778
|
+
} catch {
|
|
1779
|
+
}
|
|
1711
1780
|
}
|
|
1781
|
+
return false;
|
|
1712
1782
|
}
|
|
1713
1783
|
async function evaluateDelegationGate(opts) {
|
|
1714
|
-
|
|
1784
|
+
const gatedAgent = getGatedAgent();
|
|
1785
|
+
if (!gatedAgent || opts.agentId !== gatedAgent) {
|
|
1715
1786
|
return { outcome: "allow", reason: "agent_not_gated" };
|
|
1716
1787
|
}
|
|
1717
1788
|
if (!/^(Write|Edit)$/.test(opts.toolName)) {
|
|
@@ -1720,8 +1791,8 @@ async function evaluateDelegationGate(opts) {
|
|
|
1720
1791
|
if (classifyPath(opts.filePath, opts.cwd) === "exempt") {
|
|
1721
1792
|
return { outcome: "allow", reason: "exempt_path" };
|
|
1722
1793
|
}
|
|
1723
|
-
if (await
|
|
1724
|
-
return { outcome: "allow", reason: "
|
|
1794
|
+
if (await hasRecentEngineerDispatch(opts.now)) {
|
|
1795
|
+
return { outcome: "allow", reason: "recent_engineer_dispatch" };
|
|
1725
1796
|
}
|
|
1726
1797
|
if (hasValidScratchpadEscape(opts.sessionId, opts.now, opts.homeDir)) {
|
|
1727
1798
|
return { outcome: "allow", reason: "scratchpad_escape" };
|
|
@@ -1729,8 +1800,8 @@ async function evaluateDelegationGate(opts) {
|
|
|
1729
1800
|
return { outcome: "block", reason: "no_delegation_no_escape" };
|
|
1730
1801
|
}
|
|
1731
1802
|
var GATED_ROLE, GATED_AGENT, BLOCKED_PATH_PREFIXES, BLOCKED_FILENAMES, BLOCKED_DOCKERFILE_PREFIX, BLOCKED_EXTENSIONS, EXEMPT_MD_DIR_PREFIXES, RECENT_DISPATCH_WINDOW_MS, SCRATCHPAD_MAX_AGE_MS, SCRATCHPAD_ESCAPE_PATTERN, GATE_BLOCK_MESSAGE;
|
|
1732
|
-
var
|
|
1733
|
-
"src/lib/
|
|
1803
|
+
var init_cto_delegation_gate = __esm({
|
|
1804
|
+
"src/lib/cto-delegation-gate.ts"() {
|
|
1734
1805
|
"use strict";
|
|
1735
1806
|
init_database();
|
|
1736
1807
|
init_task_scope();
|
|
@@ -1768,17 +1839,15 @@ var init_yoshi_delegation_gate = __esm({
|
|
|
1768
1839
|
EXEMPT_MD_DIR_PREFIXES = [
|
|
1769
1840
|
".planning/",
|
|
1770
1841
|
"exe/output/",
|
|
1771
|
-
"exe/yoshi/",
|
|
1772
|
-
"exe/tom/",
|
|
1773
1842
|
"exe/",
|
|
1774
1843
|
"docs/"
|
|
1775
1844
|
];
|
|
1776
1845
|
RECENT_DISPATCH_WINDOW_MS = 5 * 60 * 1e3;
|
|
1777
1846
|
SCRATCHPAD_MAX_AGE_MS = 10 * 60 * 1e3;
|
|
1778
|
-
SCRATCHPAD_ESCAPE_PATTERN = /^TOM-CAPABLE:\s*NO\s*—\s*reason:\s*\S+/m;
|
|
1847
|
+
SCRATCHPAD_ESCAPE_PATTERN = /^(?:ENGINEER|TOM)-CAPABLE:\s*NO\s*—\s*reason:\s*\S+/m;
|
|
1779
1848
|
GATE_BLOCK_MESSAGE = [
|
|
1780
|
-
"
|
|
1781
|
-
"Dispatch create_task now OR mark
|
|
1849
|
+
"DELEGATE CHECK: this edit looks implementable by an engineer.",
|
|
1850
|
+
"Dispatch create_task now OR mark ENGINEER-CAPABLE: NO with reason.",
|
|
1782
1851
|
"No code until decided."
|
|
1783
1852
|
].join("\n");
|
|
1784
1853
|
}
|
|
@@ -2019,7 +2088,11 @@ async function ensureShardSchema(client) {
|
|
|
2019
2088
|
"ALTER TABLE memories ADD COLUMN source_path TEXT",
|
|
2020
2089
|
"ALTER TABLE memories ADD COLUMN source_type TEXT DEFAULT 'text'",
|
|
2021
2090
|
"ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3",
|
|
2022
|
-
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT"
|
|
2091
|
+
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT",
|
|
2092
|
+
// MS-11: draft staging, MS-6a: memory_type, MS-7: trajectory
|
|
2093
|
+
"ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0",
|
|
2094
|
+
"ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'",
|
|
2095
|
+
"ALTER TABLE memories ADD COLUMN trajectory TEXT"
|
|
2023
2096
|
]) {
|
|
2024
2097
|
try {
|
|
2025
2098
|
await client.execute(col);
|
|
@@ -2149,26 +2222,26 @@ var init_platform_procedures = __esm({
|
|
|
2149
2222
|
title: "What is exe-os \u2014 the operating model every agent must understand",
|
|
2150
2223
|
domain: "architecture",
|
|
2151
2224
|
priority: "p0",
|
|
2152
|
-
content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO
|
|
2225
|
+
content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO, CTO, CMO, engineers, and content production specialists. Each agent has identity, expertise, and experience layers \u2014 persistent memory that makes them better over time. All data is local-first, E2EE, owned by the user. The MCP server is the ONLY data interface \u2014 never access the DB directly."
|
|
2153
2226
|
},
|
|
2154
2227
|
{
|
|
2155
2228
|
title: "Mode 1 \u2014 how exe-os runs inside Claude Code",
|
|
2156
2229
|
domain: "architecture",
|
|
2157
2230
|
priority: "p0",
|
|
2158
|
-
content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC
|
|
2231
|
+
content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC and boots the COO. The COO manages employees in tmux sessions. Each coordinator session is a separate CC window/project. Employees run in their own tmux panes via create_task auto-spawn. The founder talks to the COO; the COO orchestrates the team. CC is the shell, exe-os is the brain."
|
|
2159
2232
|
},
|
|
2160
2233
|
{
|
|
2161
|
-
title: "Sessions explained \u2014
|
|
2234
|
+
title: "Sessions explained \u2014 coordinator session names and projects",
|
|
2162
2235
|
domain: "architecture",
|
|
2163
2236
|
priority: "p0",
|
|
2164
|
-
content: "Each
|
|
2237
|
+
content: "Each coordinator session is an isolated project session. One might be exe-os development, another might be exe-wiki. Each session spawns its own employees using {employee}-{coordinatorSession}. Sessions share the same memory DB but tasks are scoped to the session that created them. A founder can run multiple projects simultaneously. Sessions never interfere with each other."
|
|
2165
2238
|
},
|
|
2166
2239
|
// --- Hierarchy and dispatch ---
|
|
2167
2240
|
{
|
|
2168
2241
|
title: "Chain of command \u2014 who talks to whom",
|
|
2169
2242
|
domain: "workflow",
|
|
2170
2243
|
priority: "p0",
|
|
2171
|
-
content: "Founder
|
|
2244
|
+
content: "Founder -> COO -> CTO/CMO. CTO -> engineers. CMO -> content production. Never skip levels: the COO does not bypass managers for specialist work. Specialists report to their manager. If you need cross-team info, use ask_team_memory \u2014 don't read other agents' task folders. Each level owns dispatch downward and review upward."
|
|
2172
2245
|
},
|
|
2173
2246
|
{
|
|
2174
2247
|
title: "Single dispatch path \u2014 create_task only",
|
|
@@ -2178,30 +2251,30 @@ var init_platform_procedures = __esm({
|
|
|
2178
2251
|
},
|
|
2179
2252
|
// --- Session isolation ---
|
|
2180
2253
|
{
|
|
2181
|
-
title: "Session scoping \u2014 stay in your
|
|
2254
|
+
title: "Session scoping \u2014 stay in your coordinator boundary",
|
|
2182
2255
|
domain: "security",
|
|
2183
2256
|
priority: "p0",
|
|
2184
|
-
content: "Session scoping is mandatory. Managers dispatch to workers within their own
|
|
2257
|
+
content: "Session scoping is mandatory. Managers dispatch to workers within their own coordinator session ONLY. Employee sessions use {employee}-{coordinatorSession}. Cross-session dispatch is blocked by the system. Verify session names before dispatch. Tasks are scoped to the creating coordinator session."
|
|
2185
2258
|
},
|
|
2186
2259
|
{
|
|
2187
2260
|
title: "Session isolation \u2014 never touch another session's work",
|
|
2188
2261
|
domain: "workflow",
|
|
2189
2262
|
priority: "p0",
|
|
2190
|
-
content:
|
|
2263
|
+
content: "Sessions are isolated. A coordinator session owns ONLY tasks it dispatched. (1) Never close/update/cancel tasks from another coordinator session. (2) Never review work from a different session \u2014 report that it belongs to another session and skip. (3) Ignore other sessions' items in list_tasks results. (4) Employees inherit session: employee sessions work ONLY on their parent coordinator session's tasks. Cross-session work is a system violation."
|
|
2191
2264
|
},
|
|
2192
2265
|
// --- Engineering: session scoping in code ---
|
|
2193
2266
|
{
|
|
2194
2267
|
title: "Three-dimensional scoping \u2014 session, project, role \u2014 enforced in every query",
|
|
2195
2268
|
domain: "architecture",
|
|
2196
2269
|
priority: "p0",
|
|
2197
|
-
content: "Every DB query, notification, review count, and task operation MUST be scoped on 3 dimensions: (1) Session \u2014 filter by session_scope matching current
|
|
2270
|
+
content: "Every DB query, notification, review count, and task operation MUST be scoped on 3 dimensions: (1) Session \u2014 filter by session_scope matching the current coordinator session. (2) Project \u2014 filter by project_name. (3) Role \u2014 agents only see data at their hierarchy level. When writing ANY function that touches tasks, reviews, messages, or notifications: always accept a sessionScope parameter and pass it to the SQL WHERE clause. Unscoped queries are bugs. Test by running 2+ coordinator sessions simultaneously."
|
|
2198
2271
|
},
|
|
2199
2272
|
// --- Hard constraints ---
|
|
2200
2273
|
{
|
|
2201
2274
|
title: "What you CANNOT do in exe-os \u2014 hard constraints",
|
|
2202
2275
|
domain: "security",
|
|
2203
2276
|
priority: "p0",
|
|
2204
|
-
content: "NEVER: (1) Access the database directly \u2014 it's SQLCipher encrypted, always fails. Use MCP tools only. (2) Manually spawn tmux sessions \u2014 create_task handles it. (3) Run git checkout main \u2014 agents work in worktrees. (4) Modify another agent's in-progress task. (5) Push to remote \u2014
|
|
2277
|
+
content: "NEVER: (1) Access the database directly \u2014 it's SQLCipher encrypted, always fails. Use MCP tools only. (2) Manually spawn tmux sessions \u2014 create_task handles it. (3) Run git checkout main \u2014 agents work in worktrees. (4) Modify another agent's in-progress task. (5) Push to remote \u2014 the COO reviews and pushes. (6) Skip update_task(done) \u2014 it's the ONLY way your work gets reviewed. (7) Run git init."
|
|
2205
2278
|
},
|
|
2206
2279
|
// --- Operations ---
|
|
2207
2280
|
{
|
|
@@ -2441,7 +2514,10 @@ async function writeMemory(record) {
|
|
|
2441
2514
|
source_path: record.source_path ?? null,
|
|
2442
2515
|
source_type: record.source_type ?? null,
|
|
2443
2516
|
tier: record.tier ?? classifyTier(record),
|
|
2444
|
-
supersedes_id: record.supersedes_id ?? null
|
|
2517
|
+
supersedes_id: record.supersedes_id ?? null,
|
|
2518
|
+
draft: record.draft ? 1 : 0,
|
|
2519
|
+
memory_type: record.memory_type ?? "raw",
|
|
2520
|
+
trajectory: record.trajectory ? JSON.stringify(record.trajectory) : null
|
|
2445
2521
|
};
|
|
2446
2522
|
_pendingRecords.push(dbRow);
|
|
2447
2523
|
orgBus.emit({
|
|
@@ -2496,6 +2572,9 @@ async function flushBatch() {
|
|
|
2496
2572
|
const sourceType = row.source_type ?? null;
|
|
2497
2573
|
const tier = row.tier ?? 3;
|
|
2498
2574
|
const supersedesId = row.supersedes_id ?? null;
|
|
2575
|
+
const draft = row.draft ? 1 : 0;
|
|
2576
|
+
const memoryType = row.memory_type ?? "raw";
|
|
2577
|
+
const trajectory = row.trajectory ?? null;
|
|
2499
2578
|
return {
|
|
2500
2579
|
sql: hasVector ? `INSERT OR IGNORE INTO memories
|
|
2501
2580
|
(id, agent_id, agent_role, session_id, timestamp,
|
|
@@ -2503,15 +2582,15 @@ async function flushBatch() {
|
|
|
2503
2582
|
has_error, raw_text, vector, version, task_id, importance, status,
|
|
2504
2583
|
confidence, last_accessed,
|
|
2505
2584
|
workspace_id, document_id, user_id, char_offset, page_number,
|
|
2506
|
-
source_path, source_type, tier, supersedes_id)
|
|
2507
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
|
|
2585
|
+
source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
|
|
2586
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
|
|
2508
2587
|
(id, agent_id, agent_role, session_id, timestamp,
|
|
2509
2588
|
tool_name, project_name,
|
|
2510
2589
|
has_error, raw_text, vector, version, task_id, importance, status,
|
|
2511
2590
|
confidence, last_accessed,
|
|
2512
2591
|
workspace_id, document_id, user_id, char_offset, page_number,
|
|
2513
|
-
source_path, source_type, tier, supersedes_id)
|
|
2514
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
2592
|
+
source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
|
|
2593
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
2515
2594
|
args: hasVector ? [
|
|
2516
2595
|
row.id,
|
|
2517
2596
|
row.agent_id,
|
|
@@ -2537,7 +2616,10 @@ async function flushBatch() {
|
|
|
2537
2616
|
sourcePath,
|
|
2538
2617
|
sourceType,
|
|
2539
2618
|
tier,
|
|
2540
|
-
supersedesId
|
|
2619
|
+
supersedesId,
|
|
2620
|
+
draft,
|
|
2621
|
+
memoryType,
|
|
2622
|
+
trajectory
|
|
2541
2623
|
] : [
|
|
2542
2624
|
row.id,
|
|
2543
2625
|
row.agent_id,
|
|
@@ -2562,7 +2644,10 @@ async function flushBatch() {
|
|
|
2562
2644
|
sourcePath,
|
|
2563
2645
|
sourceType,
|
|
2564
2646
|
tier,
|
|
2565
|
-
supersedesId
|
|
2647
|
+
supersedesId,
|
|
2648
|
+
draft,
|
|
2649
|
+
memoryType,
|
|
2650
|
+
trajectory
|
|
2566
2651
|
]
|
|
2567
2652
|
};
|
|
2568
2653
|
};
|
|
@@ -2631,6 +2716,8 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
2631
2716
|
const limit = options?.limit ?? 10;
|
|
2632
2717
|
const statusFilter = options?.includeArchived ? "" : `
|
|
2633
2718
|
AND COALESCE(status, 'active') = 'active'`;
|
|
2719
|
+
const draftFilter = options?.includeDrafts ? "" : `
|
|
2720
|
+
AND (draft = 0 OR draft IS NULL)`;
|
|
2634
2721
|
let sql = `SELECT id, agent_id, agent_role, session_id, timestamp,
|
|
2635
2722
|
tool_name, project_name,
|
|
2636
2723
|
has_error, raw_text, vector, importance, status,
|
|
@@ -2640,7 +2727,7 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
2640
2727
|
source_path, source_type
|
|
2641
2728
|
FROM memories
|
|
2642
2729
|
WHERE agent_id = ?
|
|
2643
|
-
AND vector IS NOT NULL${statusFilter}
|
|
2730
|
+
AND vector IS NOT NULL${statusFilter}${draftFilter}
|
|
2644
2731
|
AND COALESCE(confidence, 0.7) >= 0.3`;
|
|
2645
2732
|
const args = [agentId];
|
|
2646
2733
|
const scope = buildWikiScopeFilter(options, "");
|
|
@@ -2662,6 +2749,10 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
2662
2749
|
sql += ` AND timestamp >= ?`;
|
|
2663
2750
|
args.push(options.since);
|
|
2664
2751
|
}
|
|
2752
|
+
if (options?.memoryType) {
|
|
2753
|
+
sql += ` AND memory_type = ?`;
|
|
2754
|
+
args.push(options.memoryType);
|
|
2755
|
+
}
|
|
2665
2756
|
sql += ` ORDER BY vector_distance_cos(vector, vector32(?))`;
|
|
2666
2757
|
args.push(vectorToBlob(queryVector));
|
|
2667
2758
|
sql += ` LIMIT ?`;
|
|
@@ -2827,7 +2918,7 @@ function checkCommitsExist(taskCreatedAt) {
|
|
|
2827
2918
|
).trim();
|
|
2828
2919
|
const count = output ? output.split("\n").length : 0;
|
|
2829
2920
|
if (count === 0) {
|
|
2830
|
-
return { pass: false, count: 0, error: "REVIEW GATE: No commits found since task was created. Did
|
|
2921
|
+
return { pass: false, count: 0, error: "REVIEW GATE: No commits found since task was created. Did the engineer actually ship code?" };
|
|
2831
2922
|
}
|
|
2832
2923
|
return { pass: true, count };
|
|
2833
2924
|
} catch {
|
|
@@ -2940,30 +3031,73 @@ import path12 from "path";
|
|
|
2940
3031
|
|
|
2941
3032
|
// src/adapters/claude/active-agent.ts
|
|
2942
3033
|
init_config();
|
|
2943
|
-
import { readFileSync as
|
|
2944
|
-
import { execSync as
|
|
2945
|
-
import
|
|
3034
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync, unlinkSync as unlinkSync2, readdirSync } from "fs";
|
|
3035
|
+
import { execSync as execSync3 } from "child_process";
|
|
3036
|
+
import path3 from "path";
|
|
2946
3037
|
|
|
2947
3038
|
// src/adapters/claude/session-key.ts
|
|
2948
3039
|
init_session_key();
|
|
2949
3040
|
|
|
2950
3041
|
// src/adapters/claude/active-agent.ts
|
|
2951
|
-
|
|
3042
|
+
init_employees();
|
|
3043
|
+
var CACHE_DIR = path3.join(EXE_AI_DIR, "session-cache");
|
|
2952
3044
|
var STALE_MS = 24 * 60 * 60 * 1e3;
|
|
3045
|
+
function isNameWithOptionalInstance(candidate, baseName) {
|
|
3046
|
+
if (candidate === baseName) return true;
|
|
3047
|
+
if (!candidate.startsWith(baseName)) return false;
|
|
3048
|
+
return /^\d+$/.test(candidate.slice(baseName.length));
|
|
3049
|
+
}
|
|
3050
|
+
function resolveEmployeeFromSessionPrefix(prefix, employees) {
|
|
3051
|
+
const sorted = [...employees].sort((a, b) => b.name.length - a.name.length);
|
|
3052
|
+
for (const employee of sorted) {
|
|
3053
|
+
if (isNameWithOptionalInstance(prefix, employee.name)) {
|
|
3054
|
+
return { agentId: employee.name, agentRole: employee.role };
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
return null;
|
|
3058
|
+
}
|
|
3059
|
+
function resolveActiveAgentFromTmuxSession(sessionName) {
|
|
3060
|
+
const employees = loadEmployeesSync();
|
|
3061
|
+
const coordinator = getCoordinatorEmployee(employees);
|
|
3062
|
+
const coordinatorName = coordinator?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
|
|
3063
|
+
if (isNameWithOptionalInstance(sessionName, coordinatorName)) {
|
|
3064
|
+
return {
|
|
3065
|
+
agentId: coordinatorName,
|
|
3066
|
+
agentRole: coordinator?.role ?? "COO"
|
|
3067
|
+
};
|
|
3068
|
+
}
|
|
3069
|
+
if (isNameWithOptionalInstance(sessionName, DEFAULT_COORDINATOR_TEMPLATE_NAME)) {
|
|
3070
|
+
return {
|
|
3071
|
+
agentId: coordinator?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME,
|
|
3072
|
+
agentRole: coordinator?.role ?? "COO"
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
if (sessionName.includes("-")) {
|
|
3076
|
+
const prefix = sessionName.split("-")[0] ?? "";
|
|
3077
|
+
const employee = resolveEmployeeFromSessionPrefix(prefix, employees);
|
|
3078
|
+
if (employee) return employee;
|
|
3079
|
+
const legacy = prefix.match(/^([a-zA-Z]+)\d*$/);
|
|
3080
|
+
if (legacy?.[1] && legacy[1] !== DEFAULT_COORDINATOR_TEMPLATE_NAME) {
|
|
3081
|
+
const emp = getEmployee(employees, legacy[1]);
|
|
3082
|
+
return { agentId: emp?.name ?? legacy[1], agentRole: emp?.role ?? "employee" };
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
return null;
|
|
3086
|
+
}
|
|
2953
3087
|
function getMarkerPath() {
|
|
2954
|
-
return
|
|
3088
|
+
return path3.join(CACHE_DIR, `active-agent-${getSessionKey()}.json`);
|
|
2955
3089
|
}
|
|
2956
3090
|
function getActiveAgent() {
|
|
2957
3091
|
try {
|
|
2958
3092
|
const markerPath = getMarkerPath();
|
|
2959
|
-
const raw =
|
|
3093
|
+
const raw = readFileSync3(markerPath, "utf8");
|
|
2960
3094
|
const data = JSON.parse(raw);
|
|
2961
3095
|
if (data.agentId) {
|
|
2962
3096
|
if (data.startedAt) {
|
|
2963
3097
|
const age = Date.now() - new Date(data.startedAt).getTime();
|
|
2964
3098
|
if (age > STALE_MS) {
|
|
2965
3099
|
try {
|
|
2966
|
-
|
|
3100
|
+
unlinkSync2(markerPath);
|
|
2967
3101
|
} catch {
|
|
2968
3102
|
}
|
|
2969
3103
|
} else {
|
|
@@ -2982,17 +3116,12 @@ function getActiveAgent() {
|
|
|
2982
3116
|
} catch {
|
|
2983
3117
|
}
|
|
2984
3118
|
try {
|
|
2985
|
-
const sessionName =
|
|
3119
|
+
const sessionName = execSync3(
|
|
2986
3120
|
"tmux display-message -p '#{session_name}' 2>/dev/null",
|
|
2987
3121
|
{ encoding: "utf8", timeout: 2e3 }
|
|
2988
3122
|
).trim();
|
|
2989
|
-
const
|
|
2990
|
-
if (
|
|
2991
|
-
return { agentId: empMatch[1], agentRole: "employee" };
|
|
2992
|
-
}
|
|
2993
|
-
if (/^exe\d+$/.test(sessionName)) {
|
|
2994
|
-
return { agentId: "exe", agentRole: "COO" };
|
|
2995
|
-
}
|
|
3123
|
+
const resolved = resolveActiveAgentFromTmuxSession(sessionName);
|
|
3124
|
+
if (resolved) return resolved;
|
|
2996
3125
|
} catch {
|
|
2997
3126
|
}
|
|
2998
3127
|
return {
|
|
@@ -3004,13 +3133,13 @@ function getActiveAgent() {
|
|
|
3004
3133
|
// src/adapters/claude/hooks/pre-tool-use.ts
|
|
3005
3134
|
init_config();
|
|
3006
3135
|
init_task_scope();
|
|
3136
|
+
init_employees();
|
|
3007
3137
|
if (!process.env.AGENT_ID) {
|
|
3008
3138
|
process.env.AGENT_ID = "default";
|
|
3009
3139
|
process.env.AGENT_ROLE = "employee";
|
|
3010
3140
|
}
|
|
3011
3141
|
var DELEGATION_TASK_THRESHOLD = 3;
|
|
3012
3142
|
var CTO_ROLES = ["CTO", "executive"];
|
|
3013
|
-
var TOM_SESSION_PATTERN = /^tom.*-exe/;
|
|
3014
3143
|
var CACHE_DIR2 = path12.join(EXE_AI_DIR, "session-cache");
|
|
3015
3144
|
var timeout = setTimeout(() => {
|
|
3016
3145
|
process.exit(0);
|
|
@@ -3033,13 +3162,21 @@ function markDelegationFired() {
|
|
|
3033
3162
|
} catch {
|
|
3034
3163
|
}
|
|
3035
3164
|
}
|
|
3036
|
-
function
|
|
3165
|
+
function countEngineerSessions() {
|
|
3037
3166
|
try {
|
|
3038
3167
|
const output = execSync6("tmux list-sessions 2>/dev/null", {
|
|
3039
3168
|
encoding: "utf8",
|
|
3040
3169
|
timeout: 2e3
|
|
3041
3170
|
});
|
|
3042
|
-
|
|
3171
|
+
const engineerNames = loadEmployeesSync().filter((e) => e.role.toLowerCase() === "principal engineer").map((e) => e.name);
|
|
3172
|
+
if (engineerNames.length === 0) return 0;
|
|
3173
|
+
return output.split("\n").filter((line) => {
|
|
3174
|
+
const sessionName = line.split(":")[0] ?? "";
|
|
3175
|
+
const prefix = sessionName.split("-")[0] ?? "";
|
|
3176
|
+
return engineerNames.some(
|
|
3177
|
+
(name) => prefix === name || prefix.startsWith(name) && /^\d+$/.test(prefix.slice(name.length))
|
|
3178
|
+
);
|
|
3179
|
+
}).length;
|
|
3043
3180
|
} catch {
|
|
3044
3181
|
return 0;
|
|
3045
3182
|
}
|
|
@@ -3057,7 +3194,7 @@ process.stdin.on("end", async () => {
|
|
|
3057
3194
|
}
|
|
3058
3195
|
const data = JSON.parse(input);
|
|
3059
3196
|
const agent = getActiveAgent();
|
|
3060
|
-
if (/^(Write|Edit)$/.test(data.tool_name) && agent.
|
|
3197
|
+
if (/^(Write|Edit)$/.test(data.tool_name) && !canCoordinate(agent.agentId, agent.agentRole)) {
|
|
3061
3198
|
const filePath = data.tool_input?.file_path ?? "";
|
|
3062
3199
|
const exeMatch = filePath.match(/exe\/([^/]+)\//);
|
|
3063
3200
|
if (exeMatch && exeMatch[1] !== agent.agentId && exeMatch[1] !== "output") {
|
|
@@ -3074,14 +3211,15 @@ This write was prevented. Do NOT retry.`
|
|
|
3074
3211
|
process.exit(0);
|
|
3075
3212
|
}
|
|
3076
3213
|
}
|
|
3077
|
-
const {
|
|
3214
|
+
const { getGatedAgent: getGatedAgent2 } = await Promise.resolve().then(() => (init_cto_delegation_gate(), cto_delegation_gate_exports));
|
|
3215
|
+
const gatedAgent = getGatedAgent2();
|
|
3078
3216
|
if (agent.agentId === gatedAgent && /^(Write|Edit)$/.test(data.tool_name)) {
|
|
3079
3217
|
const filePath = data.tool_input?.file_path ?? "";
|
|
3080
3218
|
if (filePath) {
|
|
3081
3219
|
try {
|
|
3082
3220
|
const { initStore: initStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
|
|
3083
3221
|
await initStore2();
|
|
3084
|
-
const { evaluateDelegationGate: evaluateDelegationGate2, GATE_BLOCK_MESSAGE: GATE_BLOCK_MESSAGE2 } = await Promise.resolve().then(() => (
|
|
3222
|
+
const { evaluateDelegationGate: evaluateDelegationGate2, GATE_BLOCK_MESSAGE: GATE_BLOCK_MESSAGE2 } = await Promise.resolve().then(() => (init_cto_delegation_gate(), cto_delegation_gate_exports));
|
|
3085
3223
|
const decision = await evaluateDelegationGate2({
|
|
3086
3224
|
agentId: agent.agentId,
|
|
3087
3225
|
toolName: data.tool_name,
|
|
@@ -3090,7 +3228,7 @@ This write was prevented. Do NOT retry.`
|
|
|
3090
3228
|
});
|
|
3091
3229
|
if (decision.outcome === "block") {
|
|
3092
3230
|
process.stderr.write(
|
|
3093
|
-
`[pre-tool-use]
|
|
3231
|
+
`[pre-tool-use] CTO delegation gate BLOCKED Write/Edit on ${filePath}
|
|
3094
3232
|
`
|
|
3095
3233
|
);
|
|
3096
3234
|
const output = JSON.stringify({
|
|
@@ -3102,7 +3240,7 @@ This write was prevented. Do NOT retry.`
|
|
|
3102
3240
|
}
|
|
3103
3241
|
} catch (err) {
|
|
3104
3242
|
process.stderr.write(
|
|
3105
|
-
`[pre-tool-use]
|
|
3243
|
+
`[pre-tool-use] CTO delegation gate error (non-fatal): ${err instanceof Error ? err.message : String(err)}
|
|
3106
3244
|
`
|
|
3107
3245
|
);
|
|
3108
3246
|
}
|
|
@@ -3111,7 +3249,7 @@ This write was prevented. Do NOT retry.`
|
|
|
3111
3249
|
if (/^(Write|Edit|Read)$/.test(data.tool_name)) {
|
|
3112
3250
|
const filePath = data.tool_input?.file_path ?? "";
|
|
3113
3251
|
const sensitivePatterns = /\/(\.env\.local|\.env\.production|id_rsa|id_ed25519|credentials\.json|\.ssh\/config)$/;
|
|
3114
|
-
if (sensitivePatterns.test(filePath) && agent.agentRole
|
|
3252
|
+
if (sensitivePatterns.test(filePath) && !canCoordinate(agent.agentId, agent.agentRole)) {
|
|
3115
3253
|
const output = JSON.stringify({
|
|
3116
3254
|
hookSpecificOutput: {
|
|
3117
3255
|
permissionDecision: "ask"
|
|
@@ -3197,24 +3335,24 @@ This write was prevented. Do NOT retry.`
|
|
|
3197
3335
|
});
|
|
3198
3336
|
const taskCount = Number(result.rows[0]?.cnt ?? 0);
|
|
3199
3337
|
if (taskCount >= DELEGATION_TASK_THRESHOLD) {
|
|
3200
|
-
const
|
|
3201
|
-
if (
|
|
3338
|
+
const engineerCount = countEngineerSessions();
|
|
3339
|
+
if (engineerCount === 0) {
|
|
3202
3340
|
markDelegationFired();
|
|
3203
3341
|
const checkpoint = [
|
|
3204
3342
|
"## Delegation Checkpoint",
|
|
3205
3343
|
"",
|
|
3206
|
-
`You have ${taskCount} open tasks and zero
|
|
3344
|
+
`You have ${taskCount} open tasks and zero engineer sessions running.`,
|
|
3207
3345
|
'Your identity non-negotiable: "Delegate before you implement."',
|
|
3208
3346
|
"",
|
|
3209
3347
|
"Before continuing, justify ONE of:",
|
|
3210
|
-
"1. I'm delegating now \u2014 here are the tasks I'm creating
|
|
3348
|
+
"1. I'm delegating now \u2014 here are the engineer tasks I'm creating",
|
|
3211
3349
|
"2. This specific task requires my full codebase context because: [reason]",
|
|
3212
3350
|
"3. I'm reviewing/triaging, not implementing",
|
|
3213
3351
|
"",
|
|
3214
3352
|
"If you can't justify, STOP and delegate."
|
|
3215
3353
|
].join("\n");
|
|
3216
3354
|
process.stderr.write(
|
|
3217
|
-
`[pre-tool-use] Delegation checkpoint fired for ${agent.agentId}: ${taskCount} tasks, 0
|
|
3355
|
+
`[pre-tool-use] Delegation checkpoint fired for ${agent.agentId}: ${taskCount} tasks, 0 engineer sessions
|
|
3218
3356
|
`
|
|
3219
3357
|
);
|
|
3220
3358
|
const output = JSON.stringify({
|