@kodizm/acp 0.9.3 → 0.9.4
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/index.js +279 -155
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51,7 +51,7 @@ var package_default;
|
|
|
51
51
|
var init_package = __esm(() => {
|
|
52
52
|
package_default = {
|
|
53
53
|
name: "@kodizm/acp",
|
|
54
|
-
version: "0.9.
|
|
54
|
+
version: "0.9.4",
|
|
55
55
|
description: "Custom ACP server bridging Claude Code and opencode CLIs through a single Kodizm-flavored protocol surface.",
|
|
56
56
|
type: "module",
|
|
57
57
|
bin: {
|
|
@@ -44362,6 +44362,207 @@ var init_driver2 = __esm(() => {
|
|
|
44362
44362
|
logger = createLogger({ env: process.env });
|
|
44363
44363
|
});
|
|
44364
44364
|
|
|
44365
|
+
// src/live/start-flags.ts
|
|
44366
|
+
function parsePaneFeatures(content, permissionMode) {
|
|
44367
|
+
let json;
|
|
44368
|
+
try {
|
|
44369
|
+
json = JSON.parse(content);
|
|
44370
|
+
} catch {
|
|
44371
|
+
return null;
|
|
44372
|
+
}
|
|
44373
|
+
const parsed = FeaturesSchema.safeParse(json);
|
|
44374
|
+
if (!parsed.success || parsed.data.simple === true) {
|
|
44375
|
+
return null;
|
|
44376
|
+
}
|
|
44377
|
+
const names = parsed.data.tools;
|
|
44378
|
+
if (names !== undefined && (names.length === 0 || !names.every((name) => TOOL_NAME.test(name)))) {
|
|
44379
|
+
return null;
|
|
44380
|
+
}
|
|
44381
|
+
const translated = translateFeaturesToClaude(parsed.data, permissionMode);
|
|
44382
|
+
return { tools: translated.tools, disallowedTools: translated.disallowedTools, env: translated.env };
|
|
44383
|
+
}
|
|
44384
|
+
function parseStartExtras(args) {
|
|
44385
|
+
for (const key of Object.keys(args)) {
|
|
44386
|
+
if (!START_FLAGS.has(key)) {
|
|
44387
|
+
return null;
|
|
44388
|
+
}
|
|
44389
|
+
}
|
|
44390
|
+
const permissionMode = parsePermissionMode(args["permission-mode"]);
|
|
44391
|
+
const oneShot = parseOneShot(args["one-shot"]);
|
|
44392
|
+
const deadlineSeconds = parseSeconds(args["deadline-seconds"], 1);
|
|
44393
|
+
const retainFailedSeconds = parseSeconds(args["retain-failed-seconds"], 0);
|
|
44394
|
+
const pluginDir = parsePluginDir(args["plugin-dir"]);
|
|
44395
|
+
const settingSources = parseSettingSources(args["setting-sources"]);
|
|
44396
|
+
const promptMode = parsePromptMode(args["prompt-mode"]);
|
|
44397
|
+
const agent = args.agent;
|
|
44398
|
+
if (permissionMode === null || oneShot === null || deadlineSeconds === null || retainFailedSeconds === null || pluginDir === null || settingSources === null || promptMode === null || !promptModeFits(promptMode, agent, pluginDir, args["system-prompt-file"], args.resume)) {
|
|
44399
|
+
return null;
|
|
44400
|
+
}
|
|
44401
|
+
return {
|
|
44402
|
+
permissionMode,
|
|
44403
|
+
oneShot,
|
|
44404
|
+
deadlineSeconds,
|
|
44405
|
+
retainFailedSeconds: retainFailedSeconds ?? 0,
|
|
44406
|
+
pluginDir,
|
|
44407
|
+
settingSources,
|
|
44408
|
+
promptMode,
|
|
44409
|
+
agent
|
|
44410
|
+
};
|
|
44411
|
+
}
|
|
44412
|
+
function parsePromptMode(value) {
|
|
44413
|
+
if (value === undefined) {
|
|
44414
|
+
return "append";
|
|
44415
|
+
}
|
|
44416
|
+
return value === "append" || value === "system" || value === "agent" ? value : null;
|
|
44417
|
+
}
|
|
44418
|
+
function promptModeFits(mode, agent, pluginDir, systemPromptFile, resume) {
|
|
44419
|
+
if (mode !== "agent") {
|
|
44420
|
+
return agent === undefined && (mode !== "system" || systemPromptFile !== undefined);
|
|
44421
|
+
}
|
|
44422
|
+
return agent !== undefined && AGENT_NAME.test(agent) && pluginDir !== undefined && systemPromptFile === undefined && resume === undefined;
|
|
44423
|
+
}
|
|
44424
|
+
function parsePluginDir(value) {
|
|
44425
|
+
if (value === undefined) {
|
|
44426
|
+
return;
|
|
44427
|
+
}
|
|
44428
|
+
return PluginPathSchema.safeParse(value).success ? value : null;
|
|
44429
|
+
}
|
|
44430
|
+
function parseSettingSources(value) {
|
|
44431
|
+
if (value === undefined) {
|
|
44432
|
+
return;
|
|
44433
|
+
}
|
|
44434
|
+
return value === "project" ? value : null;
|
|
44435
|
+
}
|
|
44436
|
+
function parsePermissionMode(value) {
|
|
44437
|
+
if (value === undefined) {
|
|
44438
|
+
return;
|
|
44439
|
+
}
|
|
44440
|
+
return value === "default" || value === "dontAsk" ? value : null;
|
|
44441
|
+
}
|
|
44442
|
+
function parseOneShot(value) {
|
|
44443
|
+
if (value === undefined || value === "0") {
|
|
44444
|
+
return false;
|
|
44445
|
+
}
|
|
44446
|
+
return value === "1" ? true : null;
|
|
44447
|
+
}
|
|
44448
|
+
function parseSeconds(value, min) {
|
|
44449
|
+
if (value === undefined) {
|
|
44450
|
+
return;
|
|
44451
|
+
}
|
|
44452
|
+
if (!DIGITS.test(value)) {
|
|
44453
|
+
return null;
|
|
44454
|
+
}
|
|
44455
|
+
const seconds = Number(value);
|
|
44456
|
+
return seconds >= min && seconds <= MAX_SECONDS ? seconds : null;
|
|
44457
|
+
}
|
|
44458
|
+
var START_FLAGS, START_FILE_FLAGS, TOOL_NAME, MAX_SECONDS = 2147483, DIGITS, AGENT_NAME;
|
|
44459
|
+
var init_start_flags = __esm(() => {
|
|
44460
|
+
init_features();
|
|
44461
|
+
init_schemas3();
|
|
44462
|
+
START_FLAGS = new Set([
|
|
44463
|
+
"pane",
|
|
44464
|
+
"cwd",
|
|
44465
|
+
"settings-base",
|
|
44466
|
+
"env-file",
|
|
44467
|
+
"model",
|
|
44468
|
+
"resume",
|
|
44469
|
+
"mcp-config",
|
|
44470
|
+
"tool-policy",
|
|
44471
|
+
"system-prompt-file",
|
|
44472
|
+
"features",
|
|
44473
|
+
"permission-mode",
|
|
44474
|
+
"one-shot",
|
|
44475
|
+
"deadline-seconds",
|
|
44476
|
+
"retain-failed-seconds",
|
|
44477
|
+
"plugin-dir",
|
|
44478
|
+
"setting-sources",
|
|
44479
|
+
"prompt-mode",
|
|
44480
|
+
"agent",
|
|
44481
|
+
"cli-config-file"
|
|
44482
|
+
]);
|
|
44483
|
+
START_FILE_FLAGS = [
|
|
44484
|
+
"env-file",
|
|
44485
|
+
"tool-policy",
|
|
44486
|
+
"system-prompt-file",
|
|
44487
|
+
"mcp-config",
|
|
44488
|
+
"features",
|
|
44489
|
+
"cli-config-file"
|
|
44490
|
+
];
|
|
44491
|
+
TOOL_NAME = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
44492
|
+
DIGITS = /^[0-9]+$/;
|
|
44493
|
+
AGENT_NAME = /^(?!-)[A-Za-z0-9_.-]{1,40}:[A-Za-z0-9_.-]{1,60}$/;
|
|
44494
|
+
});
|
|
44495
|
+
|
|
44496
|
+
// src/live/cli-config.ts
|
|
44497
|
+
function parseCliConfig(content) {
|
|
44498
|
+
let json;
|
|
44499
|
+
try {
|
|
44500
|
+
json = JSON.parse(content);
|
|
44501
|
+
} catch {
|
|
44502
|
+
return refused(undefined);
|
|
44503
|
+
}
|
|
44504
|
+
if (!isRecord(json)) {
|
|
44505
|
+
return refused(undefined);
|
|
44506
|
+
}
|
|
44507
|
+
if (Object.keys(json).some((key) => !KNOWN_KEYS.has(key))) {
|
|
44508
|
+
return refused(undefined);
|
|
44509
|
+
}
|
|
44510
|
+
const tools = json.disallowedTools ?? [];
|
|
44511
|
+
if (!Array.isArray(tools) || !tools.every((tool) => typeof tool === "string" && TOOL_NAME.test(tool))) {
|
|
44512
|
+
return refused("disallowedTools");
|
|
44513
|
+
}
|
|
44514
|
+
const env = json.env ?? {};
|
|
44515
|
+
if (!isRecord(env)) {
|
|
44516
|
+
return refused("env");
|
|
44517
|
+
}
|
|
44518
|
+
const switches = {};
|
|
44519
|
+
for (const [name, value] of Object.entries(env)) {
|
|
44520
|
+
const pinned = Object.hasOwn(CLI_CONFIG_ENV, name) ? CLI_CONFIG_ENV[name] : undefined;
|
|
44521
|
+
if (pinned === undefined) {
|
|
44522
|
+
return refused("env");
|
|
44523
|
+
}
|
|
44524
|
+
if (value !== pinned) {
|
|
44525
|
+
return refused(`env.${name}`);
|
|
44526
|
+
}
|
|
44527
|
+
switches[name] = pinned;
|
|
44528
|
+
}
|
|
44529
|
+
const disableSlashCommands = json.disableSlashCommands ?? false;
|
|
44530
|
+
if (typeof disableSlashCommands !== "boolean") {
|
|
44531
|
+
return refused("disableSlashCommands");
|
|
44532
|
+
}
|
|
44533
|
+
return {
|
|
44534
|
+
ok: true,
|
|
44535
|
+
config: {
|
|
44536
|
+
disallowedTools: [...new Set(tools)],
|
|
44537
|
+
env: switches,
|
|
44538
|
+
disableSlashCommands
|
|
44539
|
+
}
|
|
44540
|
+
};
|
|
44541
|
+
}
|
|
44542
|
+
function refused(key) {
|
|
44543
|
+
return { ok: false, key };
|
|
44544
|
+
}
|
|
44545
|
+
function isRecord(value) {
|
|
44546
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44547
|
+
}
|
|
44548
|
+
var CLI_CONFIG_ENV, KNOWN_KEYS;
|
|
44549
|
+
var init_cli_config = __esm(() => {
|
|
44550
|
+
init_start_flags();
|
|
44551
|
+
CLI_CONFIG_ENV = Object.freeze({
|
|
44552
|
+
CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS: "1",
|
|
44553
|
+
CLAUDE_CODE_DISABLE_WORKFLOWS: "1",
|
|
44554
|
+
CLAUDE_CODE_DISABLE_WEB_FETCH: "1",
|
|
44555
|
+
CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS: "1",
|
|
44556
|
+
CLAUDE_CODE_DISABLE_CLAUDE_MDS: "1",
|
|
44557
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
|
|
44558
|
+
CLAUDE_CODE_DISABLE_TERMINAL_TITLE: "1",
|
|
44559
|
+
CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING: "1",
|
|
44560
|
+
CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION: "false",
|
|
44561
|
+
DISABLE_AUTOUPDATER: "1"
|
|
44562
|
+
});
|
|
44563
|
+
KNOWN_KEYS = new Set(["disallowedTools", "env", "disableSlashCommands"]);
|
|
44564
|
+
});
|
|
44565
|
+
|
|
44365
44566
|
// src/live/redact.ts
|
|
44366
44567
|
function redact(text, knownValues) {
|
|
44367
44568
|
const values = knownValues.filter((value) => value !== "").sort((left, right) => right.length - left.length);
|
|
@@ -44395,7 +44596,7 @@ function redactDeep(value, knownValues) {
|
|
|
44395
44596
|
if (Array.isArray(value)) {
|
|
44396
44597
|
return value.map((item) => redactDeep(item, knownValues));
|
|
44397
44598
|
}
|
|
44398
|
-
if (
|
|
44599
|
+
if (isRecord2(value)) {
|
|
44399
44600
|
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactDeep(item, knownValues)]));
|
|
44400
44601
|
}
|
|
44401
44602
|
return value;
|
|
@@ -44457,7 +44658,7 @@ function toolOutput(response) {
|
|
|
44457
44658
|
if (typeof response === "string") {
|
|
44458
44659
|
return response.slice(0, OUTPUT_MAX);
|
|
44459
44660
|
}
|
|
44460
|
-
if (
|
|
44661
|
+
if (isRecord2(response) && typeof response.stdout === "string") {
|
|
44461
44662
|
const stderr = typeof response.stderr === "string" && response.stderr !== "" ? `
|
|
44462
44663
|
${response.stderr}` : "";
|
|
44463
44664
|
return `${response.stdout}${stderr}`.slice(0, OUTPUT_MAX);
|
|
@@ -44521,11 +44722,11 @@ function sessionFailed(reason, detail) {
|
|
|
44521
44722
|
function text(value) {
|
|
44522
44723
|
return typeof value === "string" ? value : undefined;
|
|
44523
44724
|
}
|
|
44524
|
-
function
|
|
44725
|
+
function isRecord2(value) {
|
|
44525
44726
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44526
44727
|
}
|
|
44527
44728
|
function toolTitle(name, input) {
|
|
44528
|
-
if (!
|
|
44729
|
+
if (!isRecord2(input)) {
|
|
44529
44730
|
return name;
|
|
44530
44731
|
}
|
|
44531
44732
|
const field = TITLE_FIELDS.find((key) => typeof input[key] === "string" && input[key] !== "");
|
|
@@ -44582,7 +44783,7 @@ import { readFile, rename, writeFile } from "fs/promises";
|
|
|
44582
44783
|
import { createConnection } from "net";
|
|
44583
44784
|
async function buildPaneSettings(options) {
|
|
44584
44785
|
const base = JSON.parse(await readFile(options.basePath, "utf8"));
|
|
44585
|
-
if (!
|
|
44786
|
+
if (!isRecord3(base)) {
|
|
44586
44787
|
throw new Error(`${options.basePath} does not hold a JSON object`);
|
|
44587
44788
|
}
|
|
44588
44789
|
const hooks = Object.fromEntries(HOOK_EVENTS.map((event) => [
|
|
@@ -44611,7 +44812,7 @@ async function buildPaneSettings(options) {
|
|
|
44611
44812
|
return settings;
|
|
44612
44813
|
}
|
|
44613
44814
|
function mergePermissions(base, rules) {
|
|
44614
|
-
const permissions =
|
|
44815
|
+
const permissions = isRecord3(base) ? base : {};
|
|
44615
44816
|
const merge = (list) => {
|
|
44616
44817
|
const own = permissions[list];
|
|
44617
44818
|
const entries = Array.isArray(own) ? own.filter((entry) => typeof entry === "string") : [];
|
|
@@ -44653,10 +44854,10 @@ async function runHookHelper(options) {
|
|
|
44653
44854
|
}
|
|
44654
44855
|
throw error;
|
|
44655
44856
|
}
|
|
44656
|
-
return blocking &&
|
|
44857
|
+
return blocking && isRecord3(response) ? hookDecisionOutput(response.decision) : "";
|
|
44657
44858
|
}
|
|
44658
44859
|
function hookDecisionOutput(decision) {
|
|
44659
|
-
if (!
|
|
44860
|
+
if (!isRecord3(decision) || decision.behavior !== "allow" && decision.behavior !== "deny") {
|
|
44660
44861
|
return "";
|
|
44661
44862
|
}
|
|
44662
44863
|
const answer = {
|
|
@@ -44715,7 +44916,7 @@ function hookCommand(options, event) {
|
|
|
44715
44916
|
}
|
|
44716
44917
|
function parseObject(text) {
|
|
44717
44918
|
const parsed = parseJson(text);
|
|
44718
|
-
return parsed !== undefined &&
|
|
44919
|
+
return parsed !== undefined && isRecord3(parsed.value) ? parsed.value : null;
|
|
44719
44920
|
}
|
|
44720
44921
|
function parseJson(text) {
|
|
44721
44922
|
try {
|
|
@@ -44727,7 +44928,7 @@ function parseJson(text) {
|
|
|
44727
44928
|
throw error;
|
|
44728
44929
|
}
|
|
44729
44930
|
}
|
|
44730
|
-
function
|
|
44931
|
+
function isRecord3(value) {
|
|
44731
44932
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44732
44933
|
}
|
|
44733
44934
|
var HOOK_EVENTS, DEFAULT_BASE_SETTINGS_PATH = "/home/agent/.claude/kodizm-live-base.json", HOOK_TIMEOUT_S = 10, PERMISSION_HOOK_TIMEOUT_S = 3600, HELPER_TIMEOUT_MS = 3000, PERMISSION_HELPER_TIMEOUT_MS, SocketRequestError;
|
|
@@ -44949,15 +45150,16 @@ function launchArgv(options) {
|
|
|
44949
45150
|
if (options.mcpConfig !== undefined) {
|
|
44950
45151
|
argv.push("--mcp-config", options.mcpConfig, "--strict-mcp-config");
|
|
44951
45152
|
}
|
|
44952
|
-
|
|
44953
|
-
argv.push("--append-system-prompt-file", options.systemPromptFile);
|
|
44954
|
-
}
|
|
45153
|
+
argv.push(...promptArgv(options));
|
|
44955
45154
|
if (options.tools !== undefined) {
|
|
44956
45155
|
argv.push("--tools", options.tools.join(","));
|
|
44957
45156
|
}
|
|
44958
45157
|
if (options.disallowedTools !== undefined && options.disallowedTools.length > 0) {
|
|
44959
45158
|
argv.push("--disallowedTools", options.disallowedTools.join(","));
|
|
44960
45159
|
}
|
|
45160
|
+
if (options.disableSlashCommands === true) {
|
|
45161
|
+
argv.push("--disable-slash-commands");
|
|
45162
|
+
}
|
|
44961
45163
|
if (options.model !== undefined) {
|
|
44962
45164
|
argv.push("--model", options.model);
|
|
44963
45165
|
}
|
|
@@ -44966,6 +45168,16 @@ function launchArgv(options) {
|
|
|
44966
45168
|
}
|
|
44967
45169
|
return argv;
|
|
44968
45170
|
}
|
|
45171
|
+
function promptArgv(options) {
|
|
45172
|
+
switch (options.promptMode ?? "append") {
|
|
45173
|
+
case "agent":
|
|
45174
|
+
return options.agent === undefined ? [] : ["--agent", options.agent];
|
|
45175
|
+
case "system":
|
|
45176
|
+
return options.systemPromptFile === undefined ? [] : ["--system-prompt-file", options.systemPromptFile];
|
|
45177
|
+
case "append":
|
|
45178
|
+
return options.systemPromptFile === undefined ? [] : ["--append-system-prompt-file", options.systemPromptFile];
|
|
45179
|
+
}
|
|
45180
|
+
}
|
|
44969
45181
|
async function trustRoots(cwd) {
|
|
44970
45182
|
const roots = new Set([cwd]);
|
|
44971
45183
|
const repository = await findGitEntry(cwd);
|
|
@@ -45048,7 +45260,7 @@ function approvedKeySuffix(apiKey) {
|
|
|
45048
45260
|
return apiKey === undefined || apiKey === "" ? undefined : apiKey.slice(-20);
|
|
45049
45261
|
}
|
|
45050
45262
|
function approveKey(current, suffix) {
|
|
45051
|
-
const responses =
|
|
45263
|
+
const responses = isRecord4(current) ? current : {};
|
|
45052
45264
|
const approved = stringList(responses.approved);
|
|
45053
45265
|
return {
|
|
45054
45266
|
...responses,
|
|
@@ -45070,9 +45282,9 @@ async function writeTrust(dirs, roots, keySuffix) {
|
|
|
45070
45282
|
for (const dir of dirs) {
|
|
45071
45283
|
const path = join3(dir, ".claude.json");
|
|
45072
45284
|
const config = await readConfig(path);
|
|
45073
|
-
const projects =
|
|
45285
|
+
const projects = isRecord4(config.projects) ? config.projects : {};
|
|
45074
45286
|
for (const root of roots) {
|
|
45075
|
-
const project =
|
|
45287
|
+
const project = isRecord4(projects[root]) ? projects[root] : {};
|
|
45076
45288
|
projects[root] = {
|
|
45077
45289
|
allowedTools: [],
|
|
45078
45290
|
...project,
|
|
@@ -45099,12 +45311,12 @@ async function readConfig(path) {
|
|
|
45099
45311
|
return {};
|
|
45100
45312
|
}
|
|
45101
45313
|
const config = JSON.parse(await readFile2(path, "utf8"));
|
|
45102
|
-
if (!
|
|
45314
|
+
if (!isRecord4(config)) {
|
|
45103
45315
|
throw new Error(`${path} does not hold a JSON object`);
|
|
45104
45316
|
}
|
|
45105
45317
|
return config;
|
|
45106
45318
|
}
|
|
45107
|
-
function
|
|
45319
|
+
function isRecord4(value) {
|
|
45108
45320
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45109
45321
|
}
|
|
45110
45322
|
function sessionTarget(pane) {
|
|
@@ -45196,7 +45408,7 @@ var init_pane = __esm(() => {
|
|
|
45196
45408
|
// src/live/policy.ts
|
|
45197
45409
|
function parseToolPolicy(text) {
|
|
45198
45410
|
const policy = parseJson2(text);
|
|
45199
|
-
if (!
|
|
45411
|
+
if (!isRecord5(policy) || !Object.keys(policy).every((key) => POLICY_KEYS.includes(key))) {
|
|
45200
45412
|
return null;
|
|
45201
45413
|
}
|
|
45202
45414
|
const rules = {
|
|
@@ -45235,7 +45447,7 @@ function translatePattern(pattern, list) {
|
|
|
45235
45447
|
return mcpRule(parsed.mcpPath);
|
|
45236
45448
|
}
|
|
45237
45449
|
const { toolName, argPattern } = parsed;
|
|
45238
|
-
if (!
|
|
45450
|
+
if (!TOOL_NAME2.test(toolName)) {
|
|
45239
45451
|
return null;
|
|
45240
45452
|
}
|
|
45241
45453
|
if (argPattern === undefined || argPattern === "*") {
|
|
@@ -45294,10 +45506,10 @@ function parseJson2(text) {
|
|
|
45294
45506
|
throw error;
|
|
45295
45507
|
}
|
|
45296
45508
|
}
|
|
45297
|
-
function
|
|
45509
|
+
function isRecord5(value) {
|
|
45298
45510
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45299
45511
|
}
|
|
45300
|
-
var RULE_LISTS, POLICY_KEYS, FILE_TOOLS,
|
|
45512
|
+
var RULE_LISTS, POLICY_KEYS, FILE_TOOLS, TOOL_NAME2;
|
|
45301
45513
|
var init_policy4 = __esm(() => {
|
|
45302
45514
|
init_policy();
|
|
45303
45515
|
RULE_LISTS = ["allow", "deny", "ask"];
|
|
@@ -45311,117 +45523,7 @@ var init_policy4 = __esm(() => {
|
|
|
45311
45523
|
["Glob", "Read"],
|
|
45312
45524
|
["Grep", "Read"]
|
|
45313
45525
|
]);
|
|
45314
|
-
|
|
45315
|
-
});
|
|
45316
|
-
|
|
45317
|
-
// src/live/start-flags.ts
|
|
45318
|
-
function parsePaneFeatures(content, permissionMode) {
|
|
45319
|
-
let json;
|
|
45320
|
-
try {
|
|
45321
|
-
json = JSON.parse(content);
|
|
45322
|
-
} catch {
|
|
45323
|
-
return null;
|
|
45324
|
-
}
|
|
45325
|
-
const parsed = FeaturesSchema.safeParse(json);
|
|
45326
|
-
if (!parsed.success || parsed.data.simple === true) {
|
|
45327
|
-
return null;
|
|
45328
|
-
}
|
|
45329
|
-
const names = parsed.data.tools;
|
|
45330
|
-
if (names !== undefined && (names.length === 0 || !names.every((name) => TOOL_NAME2.test(name)))) {
|
|
45331
|
-
return null;
|
|
45332
|
-
}
|
|
45333
|
-
const translated = translateFeaturesToClaude(parsed.data, permissionMode);
|
|
45334
|
-
return { tools: translated.tools, disallowedTools: translated.disallowedTools, env: translated.env };
|
|
45335
|
-
}
|
|
45336
|
-
function parseStartExtras(args) {
|
|
45337
|
-
for (const key of Object.keys(args)) {
|
|
45338
|
-
if (!START_FLAGS.has(key)) {
|
|
45339
|
-
return null;
|
|
45340
|
-
}
|
|
45341
|
-
}
|
|
45342
|
-
const permissionMode = parsePermissionMode(args["permission-mode"]);
|
|
45343
|
-
const oneShot = parseOneShot(args["one-shot"]);
|
|
45344
|
-
const deadlineSeconds = parseSeconds(args["deadline-seconds"], 1);
|
|
45345
|
-
const retainFailedSeconds = parseSeconds(args["retain-failed-seconds"], 0);
|
|
45346
|
-
const pluginDir = parsePluginDir(args["plugin-dir"]);
|
|
45347
|
-
const settingSources = parseSettingSources(args["setting-sources"]);
|
|
45348
|
-
if (permissionMode === null || oneShot === null || deadlineSeconds === null || retainFailedSeconds === null || pluginDir === null || settingSources === null) {
|
|
45349
|
-
return null;
|
|
45350
|
-
}
|
|
45351
|
-
return {
|
|
45352
|
-
permissionMode,
|
|
45353
|
-
oneShot,
|
|
45354
|
-
deadlineSeconds,
|
|
45355
|
-
retainFailedSeconds: retainFailedSeconds ?? 0,
|
|
45356
|
-
pluginDir,
|
|
45357
|
-
settingSources
|
|
45358
|
-
};
|
|
45359
|
-
}
|
|
45360
|
-
function parsePluginDir(value) {
|
|
45361
|
-
if (value === undefined) {
|
|
45362
|
-
return;
|
|
45363
|
-
}
|
|
45364
|
-
return PluginPathSchema.safeParse(value).success ? value : null;
|
|
45365
|
-
}
|
|
45366
|
-
function parseSettingSources(value) {
|
|
45367
|
-
if (value === undefined) {
|
|
45368
|
-
return;
|
|
45369
|
-
}
|
|
45370
|
-
return value === "project" ? value : null;
|
|
45371
|
-
}
|
|
45372
|
-
function parsePermissionMode(value) {
|
|
45373
|
-
if (value === undefined) {
|
|
45374
|
-
return;
|
|
45375
|
-
}
|
|
45376
|
-
return value === "default" || value === "dontAsk" ? value : null;
|
|
45377
|
-
}
|
|
45378
|
-
function parseOneShot(value) {
|
|
45379
|
-
if (value === undefined || value === "0") {
|
|
45380
|
-
return false;
|
|
45381
|
-
}
|
|
45382
|
-
return value === "1" ? true : null;
|
|
45383
|
-
}
|
|
45384
|
-
function parseSeconds(value, min) {
|
|
45385
|
-
if (value === undefined) {
|
|
45386
|
-
return;
|
|
45387
|
-
}
|
|
45388
|
-
if (!DIGITS.test(value)) {
|
|
45389
|
-
return null;
|
|
45390
|
-
}
|
|
45391
|
-
const seconds = Number(value);
|
|
45392
|
-
return seconds >= min && seconds <= MAX_SECONDS ? seconds : null;
|
|
45393
|
-
}
|
|
45394
|
-
var START_FLAGS, START_FILE_FLAGS, TOOL_NAME2, MAX_SECONDS = 2147483, DIGITS;
|
|
45395
|
-
var init_start_flags = __esm(() => {
|
|
45396
|
-
init_features();
|
|
45397
|
-
init_schemas3();
|
|
45398
|
-
START_FLAGS = new Set([
|
|
45399
|
-
"pane",
|
|
45400
|
-
"cwd",
|
|
45401
|
-
"settings-base",
|
|
45402
|
-
"env-file",
|
|
45403
|
-
"model",
|
|
45404
|
-
"resume",
|
|
45405
|
-
"mcp-config",
|
|
45406
|
-
"tool-policy",
|
|
45407
|
-
"system-prompt-file",
|
|
45408
|
-
"features",
|
|
45409
|
-
"permission-mode",
|
|
45410
|
-
"one-shot",
|
|
45411
|
-
"deadline-seconds",
|
|
45412
|
-
"retain-failed-seconds",
|
|
45413
|
-
"plugin-dir",
|
|
45414
|
-
"setting-sources"
|
|
45415
|
-
]);
|
|
45416
|
-
START_FILE_FLAGS = [
|
|
45417
|
-
"env-file",
|
|
45418
|
-
"tool-policy",
|
|
45419
|
-
"system-prompt-file",
|
|
45420
|
-
"mcp-config",
|
|
45421
|
-
"features"
|
|
45422
|
-
];
|
|
45423
|
-
TOOL_NAME2 = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
45424
|
-
DIGITS = /^[0-9]+$/;
|
|
45526
|
+
TOOL_NAME2 = /^[A-Z][A-Za-z0-9_]*$/;
|
|
45425
45527
|
});
|
|
45426
45528
|
|
|
45427
45529
|
// src/live/transcript.ts
|
|
@@ -45489,7 +45591,7 @@ function classifyInterrupt(record) {
|
|
|
45489
45591
|
return null;
|
|
45490
45592
|
}
|
|
45491
45593
|
const [block] = content;
|
|
45492
|
-
if (!
|
|
45594
|
+
if (!isRecord6(block) || block.type !== "text") {
|
|
45493
45595
|
return null;
|
|
45494
45596
|
}
|
|
45495
45597
|
if (block.text === INTERRUPT_MARKER) {
|
|
@@ -45531,7 +45633,7 @@ class UsageLedger {
|
|
|
45531
45633
|
if (record.type !== "assistant" || !isMainChain(record) || message === null) {
|
|
45532
45634
|
return null;
|
|
45533
45635
|
}
|
|
45534
|
-
if (typeof message.id !== "string" || !
|
|
45636
|
+
if (typeof message.id !== "string" || !isRecord6(message.usage)) {
|
|
45535
45637
|
return null;
|
|
45536
45638
|
}
|
|
45537
45639
|
const seen = this.counted.get(message.id) ?? emptyCounts();
|
|
@@ -45558,7 +45660,7 @@ function assistantBlocks(record) {
|
|
|
45558
45660
|
}
|
|
45559
45661
|
const blocks = [];
|
|
45560
45662
|
for (const block of content) {
|
|
45561
|
-
if (!
|
|
45663
|
+
if (!isRecord6(block)) {
|
|
45562
45664
|
continue;
|
|
45563
45665
|
}
|
|
45564
45666
|
if (block.type === "text" && typeof block.text === "string" && block.text !== "") {
|
|
@@ -45578,12 +45680,12 @@ function isMainChain(record) {
|
|
|
45578
45680
|
return record.isSidechain !== true;
|
|
45579
45681
|
}
|
|
45580
45682
|
function messageOf(record) {
|
|
45581
|
-
return
|
|
45683
|
+
return isRecord6(record.message) ? record.message : null;
|
|
45582
45684
|
}
|
|
45583
45685
|
function parseLine(line) {
|
|
45584
45686
|
try {
|
|
45585
45687
|
const value = JSON.parse(line);
|
|
45586
|
-
return
|
|
45688
|
+
return isRecord6(value) ? value : null;
|
|
45587
45689
|
} catch (error) {
|
|
45588
45690
|
if (error instanceof SyntaxError) {
|
|
45589
45691
|
return null;
|
|
@@ -45621,7 +45723,7 @@ function emptyCounts() {
|
|
|
45621
45723
|
cacheCreationTokens: 0
|
|
45622
45724
|
};
|
|
45623
45725
|
}
|
|
45624
|
-
function
|
|
45726
|
+
function isRecord6(value) {
|
|
45625
45727
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45626
45728
|
}
|
|
45627
45729
|
var INTERRUPT_MARKER = "[Request interrupted by user]", INTERRUPT_TOOL_MARKER = "[Request interrupted by user for tool use]", NEWLINE = 10, USAGE_LIMIT_TEXT, LIMIT_RESETS, NOT_A_USAGE_LIMIT, STATUS_REASONS, API_ERROR_DETAIL_MAX = 200;
|
|
@@ -45751,10 +45853,10 @@ class EventQueue {
|
|
|
45751
45853
|
},
|
|
45752
45854
|
timeoutMs: this.options.timings().ingestTimeoutMs
|
|
45753
45855
|
});
|
|
45754
|
-
if (response.status === 200 &&
|
|
45856
|
+
if (response.status === 200 && isRecord2(response.body) && typeof response.body.lastSeq === "number") {
|
|
45755
45857
|
return this.acknowledge(response.body.lastSeq);
|
|
45756
45858
|
}
|
|
45757
|
-
const error =
|
|
45859
|
+
const error = isRecord2(response.body) && isRecord2(response.body.error) ? response.body.error : {};
|
|
45758
45860
|
if (response.status === 409 && error.code === "stale_gen") {
|
|
45759
45861
|
this.options.logger.warn("tmuxd ingest moved to a newer gen", {
|
|
45760
45862
|
gen: this.options.gen,
|
|
@@ -46208,7 +46310,7 @@ class LivePane {
|
|
|
46208
46310
|
if (immediate !== "pending") {
|
|
46209
46311
|
return immediate;
|
|
46210
46312
|
}
|
|
46211
|
-
const id =
|
|
46313
|
+
const id = isRecord2(opened.body) ? text(opened.body.id) : undefined;
|
|
46212
46314
|
if (id === undefined) {
|
|
46213
46315
|
return;
|
|
46214
46316
|
}
|
|
@@ -46589,6 +46691,7 @@ class LiveDaemon {
|
|
|
46589
46691
|
const systemPromptFile = args["system-prompt-file"];
|
|
46590
46692
|
const mcpConfig = args["mcp-config"];
|
|
46591
46693
|
const featuresFile = args.features;
|
|
46694
|
+
const cliConfigFile = args["cli-config-file"];
|
|
46592
46695
|
if (id === undefined || !PANE_ID2.test(id) || cwd === undefined || !isAbsolute2(cwd)) {
|
|
46593
46696
|
return refuse("usage_error");
|
|
46594
46697
|
}
|
|
@@ -46599,7 +46702,7 @@ class LiveDaemon {
|
|
|
46599
46702
|
return refuse("usage_error");
|
|
46600
46703
|
}
|
|
46601
46704
|
const extras = parseStartExtras(args);
|
|
46602
|
-
if (extras === null || [policyFile, systemPromptFile, mcpConfig, featuresFile].some((path) => !optionalAbsolute(path))) {
|
|
46705
|
+
if (extras === null || [policyFile, systemPromptFile, mcpConfig, featuresFile, cliConfigFile].some((path) => !optionalAbsolute(path))) {
|
|
46603
46706
|
return refuse("usage_error");
|
|
46604
46707
|
}
|
|
46605
46708
|
if (this.panes.has(id) || this.starting.has(id)) {
|
|
@@ -46621,6 +46724,7 @@ class LiveDaemon {
|
|
|
46621
46724
|
systemPromptFile,
|
|
46622
46725
|
mcpConfig,
|
|
46623
46726
|
featuresFile,
|
|
46727
|
+
cliConfigFile,
|
|
46624
46728
|
extras
|
|
46625
46729
|
});
|
|
46626
46730
|
} finally {
|
|
@@ -46639,6 +46743,7 @@ class LiveDaemon {
|
|
|
46639
46743
|
systemPromptFile,
|
|
46640
46744
|
mcpConfig,
|
|
46641
46745
|
featuresFile,
|
|
46746
|
+
cliConfigFile,
|
|
46642
46747
|
extras
|
|
46643
46748
|
} = request;
|
|
46644
46749
|
const content = await readSecretFile(envFile);
|
|
@@ -46659,6 +46764,11 @@ class LiveDaemon {
|
|
|
46659
46764
|
if (features === null) {
|
|
46660
46765
|
return refuse("usage_error");
|
|
46661
46766
|
}
|
|
46767
|
+
const cliConfig = cliConfigFile === undefined ? undefined : await readCliConfig(cliConfigFile);
|
|
46768
|
+
if (cliConfig?.ok === false) {
|
|
46769
|
+
return refuse("usage_error", { cli_config_key: cliConfig.key });
|
|
46770
|
+
}
|
|
46771
|
+
const role = cliConfig?.config;
|
|
46662
46772
|
const mcpSpellings = mcpConfig === undefined ? [] : [...new Set([mcpConfig, await realpath2(mcpConfig)])];
|
|
46663
46773
|
const settingsPath = join4(settingsBase, `${id}.settings.json`);
|
|
46664
46774
|
await mkdir2(settingsBase, { recursive: true, mode: 448 });
|
|
@@ -46682,13 +46792,16 @@ class LiveDaemon {
|
|
|
46682
46792
|
cwd,
|
|
46683
46793
|
home: this.options.home,
|
|
46684
46794
|
settingsPath,
|
|
46685
|
-
env: { ...env.authEnv, ...features?.env },
|
|
46795
|
+
env: { ...env.authEnv, ...features?.env, ...role?.env },
|
|
46686
46796
|
model,
|
|
46687
46797
|
resumeSessionId: resume,
|
|
46688
46798
|
mcpConfig,
|
|
46689
46799
|
systemPromptFile,
|
|
46800
|
+
promptMode: extras.promptMode,
|
|
46801
|
+
agent: extras.agent,
|
|
46690
46802
|
tools: features?.tools,
|
|
46691
|
-
disallowedTools: features?.disallowedTools,
|
|
46803
|
+
disallowedTools: [...new Set([...features?.disallowedTools ?? [], ...role?.disallowedTools ?? []])],
|
|
46804
|
+
disableSlashCommands: role?.disableSlashCommands,
|
|
46692
46805
|
permissionMode: extras.permissionMode,
|
|
46693
46806
|
pluginDir: extras.pluginDir,
|
|
46694
46807
|
settingSources: extras.settingSources,
|
|
@@ -46930,7 +47043,7 @@ class LiveDaemon {
|
|
|
46930
47043
|
const request = parseRequest(line);
|
|
46931
47044
|
try {
|
|
46932
47045
|
if (request?.kind === "hook" && typeof request.pane === "string" && typeof request.event === "string") {
|
|
46933
|
-
return await this.hook(request.pane, request.event,
|
|
47046
|
+
return await this.hook(request.pane, request.event, isRecord2(request.payload) ? request.payload : {}, signal);
|
|
46934
47047
|
}
|
|
46935
47048
|
if (request?.kind === "ctl" && typeof request.verb === "string") {
|
|
46936
47049
|
return await this.ctl(request.verb, stringArgs(request.args));
|
|
@@ -46966,7 +47079,7 @@ function tokenGen(token) {
|
|
|
46966
47079
|
const [payload] = token.slice(TOKEN_PREFIX.length).split(".");
|
|
46967
47080
|
try {
|
|
46968
47081
|
const claims = JSON.parse(Buffer.from(payload ?? "", "base64url").toString("utf8"));
|
|
46969
|
-
return
|
|
47082
|
+
return isRecord2(claims) && Number.isInteger(claims.gen) ? claims.gen : null;
|
|
46970
47083
|
} catch (error) {
|
|
46971
47084
|
if (error instanceof SyntaxError) {
|
|
46972
47085
|
return null;
|
|
@@ -47065,6 +47178,10 @@ async function readPaneFeatures(path, permissionMode) {
|
|
|
47065
47178
|
const content = await readSecretFile(path);
|
|
47066
47179
|
return content === null ? null : parsePaneFeatures(content, permissionMode);
|
|
47067
47180
|
}
|
|
47181
|
+
async function readCliConfig(path) {
|
|
47182
|
+
const content = await readSecretFile(path);
|
|
47183
|
+
return content === null ? { ok: false, key: undefined } : parseCliConfig(content);
|
|
47184
|
+
}
|
|
47068
47185
|
async function readFileOrNull(path) {
|
|
47069
47186
|
return readFile3(path, "utf8").catch((error) => {
|
|
47070
47187
|
if (error.code === "ENOENT" || error.code === "EISDIR") {
|
|
@@ -47088,7 +47205,7 @@ async function removeFile(path) {
|
|
|
47088
47205
|
});
|
|
47089
47206
|
}
|
|
47090
47207
|
function decisionFrom(body) {
|
|
47091
|
-
const status =
|
|
47208
|
+
const status = isRecord2(body) ? body.status : undefined;
|
|
47092
47209
|
switch (status) {
|
|
47093
47210
|
case "pending":
|
|
47094
47211
|
return "pending";
|
|
@@ -47097,7 +47214,7 @@ function decisionFrom(body) {
|
|
|
47097
47214
|
case "denied":
|
|
47098
47215
|
return {
|
|
47099
47216
|
behavior: "deny",
|
|
47100
|
-
message: (
|
|
47217
|
+
message: (isRecord2(body) ? text(body.message) : undefined) ?? "Denied by the operator."
|
|
47101
47218
|
};
|
|
47102
47219
|
case "expired":
|
|
47103
47220
|
return {
|
|
@@ -47207,7 +47324,7 @@ function sameJson(left, right) {
|
|
|
47207
47324
|
function parseRequest(line) {
|
|
47208
47325
|
try {
|
|
47209
47326
|
const value = JSON.parse(line);
|
|
47210
|
-
return
|
|
47327
|
+
return isRecord2(value) ? value : null;
|
|
47211
47328
|
} catch (error) {
|
|
47212
47329
|
if (error instanceof SyntaxError) {
|
|
47213
47330
|
return null;
|
|
@@ -47216,7 +47333,7 @@ function parseRequest(line) {
|
|
|
47216
47333
|
}
|
|
47217
47334
|
}
|
|
47218
47335
|
function stringArgs(value) {
|
|
47219
|
-
if (!
|
|
47336
|
+
if (!isRecord2(value)) {
|
|
47220
47337
|
return {};
|
|
47221
47338
|
}
|
|
47222
47339
|
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
@@ -47248,6 +47365,7 @@ var DAEMON_VERSION, HEARTBEAT_INTERVAL_MS = 20000, WATCHDOG_QUIET_MS = 30000, CA
|
|
|
47248
47365
|
var init_daemon = __esm(() => {
|
|
47249
47366
|
init_package();
|
|
47250
47367
|
init_logger();
|
|
47368
|
+
init_cli_config();
|
|
47251
47369
|
init_events2();
|
|
47252
47370
|
init_hooks();
|
|
47253
47371
|
init_input();
|
|
@@ -47511,8 +47629,12 @@ Commands:
|
|
|
47511
47629
|
Verbs: start, prompt, command, cancel, stop, rotate-token, status.
|
|
47512
47630
|
start also takes --permission-mode default|dontAsk, --one-shot 0|1,
|
|
47513
47631
|
--deadline-seconds N, --retain-failed-seconds N,
|
|
47514
|
-
--plugin-dir /opt/kodizm/plugins/DIR, --setting-sources project
|
|
47515
|
-
--
|
|
47632
|
+
--plugin-dir /opt/kodizm/plugins/DIR, --setting-sources project,
|
|
47633
|
+
--prompt-mode append|system|agent (system needs --system-prompt-file),
|
|
47634
|
+
--agent PLUGIN:AGENT (agent mode only, with --plugin-dir and neither
|
|
47635
|
+
--system-prompt-file nor --resume) and
|
|
47636
|
+
--mcp-config/--tool-policy/--system-prompt-file/--features/
|
|
47637
|
+
--cli-config-file PATH.
|
|
47516
47638
|
hook <Event> --pane <id> --socket <path> Hook helper the pane settings run; reads the payload on stdin.
|
|
47517
47639
|
daemon Run the daemon in the foreground; ctl start spawns it detached.
|
|
47518
47640
|
|
|
@@ -47533,7 +47655,9 @@ Environment:
|
|
|
47533
47655
|
"token-file",
|
|
47534
47656
|
"mcp-config",
|
|
47535
47657
|
"tool-policy",
|
|
47536
|
-
"system-prompt-file"
|
|
47658
|
+
"system-prompt-file",
|
|
47659
|
+
"features",
|
|
47660
|
+
"cli-config-file"
|
|
47537
47661
|
]);
|
|
47538
47662
|
HANDOFF_FLAGS = new Map([
|
|
47539
47663
|
["start", START_FILE_FLAGS],
|