@kodizm/acp 0.9.2 → 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 +293 -139
- 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: {
|
|
@@ -5073,7 +5073,7 @@ var AbsolutePathSchema, PLUGIN_ROOT = "/opt/kodizm/plugins/", PluginPathSchema,
|
|
|
5073
5073
|
var init_schemas3 = __esm(() => {
|
|
5074
5074
|
init_zod();
|
|
5075
5075
|
AbsolutePathSchema = string2().regex(/^\//, 'path must be absolute (start with "/")');
|
|
5076
|
-
PluginPathSchema = AbsolutePathSchema.refine((path) => path.length > PLUGIN_ROOT.length && path.startsWith(PLUGIN_ROOT) && !path.split("/").
|
|
5076
|
+
PluginPathSchema = AbsolutePathSchema.refine((path) => path.length > PLUGIN_ROOT.length && path.startsWith(PLUGIN_ROOT) && !path.slice(PLUGIN_ROOT.length).split("/").some((segment) => segment === "" || segment === "." || segment === ".."), { message: `plugin path must live under ${PLUGIN_ROOT} with no ".", ".." or empty segment` });
|
|
5077
5077
|
McpServerSchema = object({
|
|
5078
5078
|
type: literal("http"),
|
|
5079
5079
|
name: string2().min(1),
|
|
@@ -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;
|
|
@@ -44933,22 +45134,32 @@ function paneEnv(options) {
|
|
|
44933
45134
|
};
|
|
44934
45135
|
}
|
|
44935
45136
|
function launchArgv(options) {
|
|
44936
|
-
const argv = [
|
|
45137
|
+
const argv = [
|
|
45138
|
+
options.claudeBin ?? "claude",
|
|
45139
|
+
"--settings",
|
|
45140
|
+
options.settingsPath,
|
|
45141
|
+
"--setting-sources",
|
|
45142
|
+
options.settingSources ?? ""
|
|
45143
|
+
];
|
|
45144
|
+
if (options.pluginDir !== undefined) {
|
|
45145
|
+
argv.push("--plugin-dir", options.pluginDir);
|
|
45146
|
+
}
|
|
44937
45147
|
if (options.permissionMode !== undefined) {
|
|
44938
45148
|
argv.push("--permission-mode", options.permissionMode);
|
|
44939
45149
|
}
|
|
44940
45150
|
if (options.mcpConfig !== undefined) {
|
|
44941
45151
|
argv.push("--mcp-config", options.mcpConfig, "--strict-mcp-config");
|
|
44942
45152
|
}
|
|
44943
|
-
|
|
44944
|
-
argv.push("--append-system-prompt-file", options.systemPromptFile);
|
|
44945
|
-
}
|
|
45153
|
+
argv.push(...promptArgv(options));
|
|
44946
45154
|
if (options.tools !== undefined) {
|
|
44947
45155
|
argv.push("--tools", options.tools.join(","));
|
|
44948
45156
|
}
|
|
44949
45157
|
if (options.disallowedTools !== undefined && options.disallowedTools.length > 0) {
|
|
44950
45158
|
argv.push("--disallowedTools", options.disallowedTools.join(","));
|
|
44951
45159
|
}
|
|
45160
|
+
if (options.disableSlashCommands === true) {
|
|
45161
|
+
argv.push("--disable-slash-commands");
|
|
45162
|
+
}
|
|
44952
45163
|
if (options.model !== undefined) {
|
|
44953
45164
|
argv.push("--model", options.model);
|
|
44954
45165
|
}
|
|
@@ -44957,6 +45168,16 @@ function launchArgv(options) {
|
|
|
44957
45168
|
}
|
|
44958
45169
|
return argv;
|
|
44959
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
|
+
}
|
|
44960
45181
|
async function trustRoots(cwd) {
|
|
44961
45182
|
const roots = new Set([cwd]);
|
|
44962
45183
|
const repository = await findGitEntry(cwd);
|
|
@@ -45039,7 +45260,7 @@ function approvedKeySuffix(apiKey) {
|
|
|
45039
45260
|
return apiKey === undefined || apiKey === "" ? undefined : apiKey.slice(-20);
|
|
45040
45261
|
}
|
|
45041
45262
|
function approveKey(current, suffix) {
|
|
45042
|
-
const responses =
|
|
45263
|
+
const responses = isRecord4(current) ? current : {};
|
|
45043
45264
|
const approved = stringList(responses.approved);
|
|
45044
45265
|
return {
|
|
45045
45266
|
...responses,
|
|
@@ -45061,9 +45282,9 @@ async function writeTrust(dirs, roots, keySuffix) {
|
|
|
45061
45282
|
for (const dir of dirs) {
|
|
45062
45283
|
const path = join3(dir, ".claude.json");
|
|
45063
45284
|
const config = await readConfig(path);
|
|
45064
|
-
const projects =
|
|
45285
|
+
const projects = isRecord4(config.projects) ? config.projects : {};
|
|
45065
45286
|
for (const root of roots) {
|
|
45066
|
-
const project =
|
|
45287
|
+
const project = isRecord4(projects[root]) ? projects[root] : {};
|
|
45067
45288
|
projects[root] = {
|
|
45068
45289
|
allowedTools: [],
|
|
45069
45290
|
...project,
|
|
@@ -45090,12 +45311,12 @@ async function readConfig(path) {
|
|
|
45090
45311
|
return {};
|
|
45091
45312
|
}
|
|
45092
45313
|
const config = JSON.parse(await readFile2(path, "utf8"));
|
|
45093
|
-
if (!
|
|
45314
|
+
if (!isRecord4(config)) {
|
|
45094
45315
|
throw new Error(`${path} does not hold a JSON object`);
|
|
45095
45316
|
}
|
|
45096
45317
|
return config;
|
|
45097
45318
|
}
|
|
45098
|
-
function
|
|
45319
|
+
function isRecord4(value) {
|
|
45099
45320
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45100
45321
|
}
|
|
45101
45322
|
function sessionTarget(pane) {
|
|
@@ -45187,7 +45408,7 @@ var init_pane = __esm(() => {
|
|
|
45187
45408
|
// src/live/policy.ts
|
|
45188
45409
|
function parseToolPolicy(text) {
|
|
45189
45410
|
const policy = parseJson2(text);
|
|
45190
|
-
if (!
|
|
45411
|
+
if (!isRecord5(policy) || !Object.keys(policy).every((key) => POLICY_KEYS.includes(key))) {
|
|
45191
45412
|
return null;
|
|
45192
45413
|
}
|
|
45193
45414
|
const rules = {
|
|
@@ -45226,7 +45447,7 @@ function translatePattern(pattern, list) {
|
|
|
45226
45447
|
return mcpRule(parsed.mcpPath);
|
|
45227
45448
|
}
|
|
45228
45449
|
const { toolName, argPattern } = parsed;
|
|
45229
|
-
if (!
|
|
45450
|
+
if (!TOOL_NAME2.test(toolName)) {
|
|
45230
45451
|
return null;
|
|
45231
45452
|
}
|
|
45232
45453
|
if (argPattern === undefined || argPattern === "*") {
|
|
@@ -45285,10 +45506,10 @@ function parseJson2(text) {
|
|
|
45285
45506
|
throw error;
|
|
45286
45507
|
}
|
|
45287
45508
|
}
|
|
45288
|
-
function
|
|
45509
|
+
function isRecord5(value) {
|
|
45289
45510
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45290
45511
|
}
|
|
45291
|
-
var RULE_LISTS, POLICY_KEYS, FILE_TOOLS,
|
|
45512
|
+
var RULE_LISTS, POLICY_KEYS, FILE_TOOLS, TOOL_NAME2;
|
|
45292
45513
|
var init_policy4 = __esm(() => {
|
|
45293
45514
|
init_policy();
|
|
45294
45515
|
RULE_LISTS = ["allow", "deny", "ask"];
|
|
@@ -45302,99 +45523,7 @@ var init_policy4 = __esm(() => {
|
|
|
45302
45523
|
["Glob", "Read"],
|
|
45303
45524
|
["Grep", "Read"]
|
|
45304
45525
|
]);
|
|
45305
|
-
|
|
45306
|
-
});
|
|
45307
|
-
|
|
45308
|
-
// src/live/start-flags.ts
|
|
45309
|
-
function parsePaneFeatures(content, permissionMode) {
|
|
45310
|
-
let json;
|
|
45311
|
-
try {
|
|
45312
|
-
json = JSON.parse(content);
|
|
45313
|
-
} catch {
|
|
45314
|
-
return null;
|
|
45315
|
-
}
|
|
45316
|
-
const parsed = FeaturesSchema.safeParse(json);
|
|
45317
|
-
if (!parsed.success || parsed.data.simple === true) {
|
|
45318
|
-
return null;
|
|
45319
|
-
}
|
|
45320
|
-
const names = parsed.data.tools;
|
|
45321
|
-
if (names !== undefined && (names.length === 0 || !names.every((name) => TOOL_NAME2.test(name)))) {
|
|
45322
|
-
return null;
|
|
45323
|
-
}
|
|
45324
|
-
const translated = translateFeaturesToClaude(parsed.data, permissionMode);
|
|
45325
|
-
return { tools: translated.tools, disallowedTools: translated.disallowedTools, env: translated.env };
|
|
45326
|
-
}
|
|
45327
|
-
function parseStartExtras(args) {
|
|
45328
|
-
for (const key of Object.keys(args)) {
|
|
45329
|
-
if (!START_FLAGS.has(key)) {
|
|
45330
|
-
return null;
|
|
45331
|
-
}
|
|
45332
|
-
}
|
|
45333
|
-
const permissionMode = parsePermissionMode(args["permission-mode"]);
|
|
45334
|
-
const oneShot = parseOneShot(args["one-shot"]);
|
|
45335
|
-
const deadlineSeconds = parseSeconds(args["deadline-seconds"], 1);
|
|
45336
|
-
const retainFailedSeconds = parseSeconds(args["retain-failed-seconds"], 0);
|
|
45337
|
-
if (permissionMode === null || oneShot === null || deadlineSeconds === null || retainFailedSeconds === null) {
|
|
45338
|
-
return null;
|
|
45339
|
-
}
|
|
45340
|
-
return {
|
|
45341
|
-
permissionMode,
|
|
45342
|
-
oneShot,
|
|
45343
|
-
deadlineSeconds,
|
|
45344
|
-
retainFailedSeconds: retainFailedSeconds ?? 0
|
|
45345
|
-
};
|
|
45346
|
-
}
|
|
45347
|
-
function parsePermissionMode(value) {
|
|
45348
|
-
if (value === undefined) {
|
|
45349
|
-
return;
|
|
45350
|
-
}
|
|
45351
|
-
return value === "default" || value === "dontAsk" ? value : null;
|
|
45352
|
-
}
|
|
45353
|
-
function parseOneShot(value) {
|
|
45354
|
-
if (value === undefined || value === "0") {
|
|
45355
|
-
return false;
|
|
45356
|
-
}
|
|
45357
|
-
return value === "1" ? true : null;
|
|
45358
|
-
}
|
|
45359
|
-
function parseSeconds(value, min) {
|
|
45360
|
-
if (value === undefined) {
|
|
45361
|
-
return;
|
|
45362
|
-
}
|
|
45363
|
-
if (!DIGITS.test(value)) {
|
|
45364
|
-
return null;
|
|
45365
|
-
}
|
|
45366
|
-
const seconds = Number(value);
|
|
45367
|
-
return seconds >= min && seconds <= MAX_SECONDS ? seconds : null;
|
|
45368
|
-
}
|
|
45369
|
-
var START_FLAGS, START_FILE_FLAGS, TOOL_NAME2, MAX_SECONDS = 2147483, DIGITS;
|
|
45370
|
-
var init_start_flags = __esm(() => {
|
|
45371
|
-
init_features();
|
|
45372
|
-
init_schemas3();
|
|
45373
|
-
START_FLAGS = new Set([
|
|
45374
|
-
"pane",
|
|
45375
|
-
"cwd",
|
|
45376
|
-
"settings-base",
|
|
45377
|
-
"env-file",
|
|
45378
|
-
"model",
|
|
45379
|
-
"resume",
|
|
45380
|
-
"mcp-config",
|
|
45381
|
-
"tool-policy",
|
|
45382
|
-
"system-prompt-file",
|
|
45383
|
-
"features",
|
|
45384
|
-
"permission-mode",
|
|
45385
|
-
"one-shot",
|
|
45386
|
-
"deadline-seconds",
|
|
45387
|
-
"retain-failed-seconds"
|
|
45388
|
-
]);
|
|
45389
|
-
START_FILE_FLAGS = [
|
|
45390
|
-
"env-file",
|
|
45391
|
-
"tool-policy",
|
|
45392
|
-
"system-prompt-file",
|
|
45393
|
-
"mcp-config",
|
|
45394
|
-
"features"
|
|
45395
|
-
];
|
|
45396
|
-
TOOL_NAME2 = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
45397
|
-
DIGITS = /^[0-9]+$/;
|
|
45526
|
+
TOOL_NAME2 = /^[A-Z][A-Za-z0-9_]*$/;
|
|
45398
45527
|
});
|
|
45399
45528
|
|
|
45400
45529
|
// src/live/transcript.ts
|
|
@@ -45462,7 +45591,7 @@ function classifyInterrupt(record) {
|
|
|
45462
45591
|
return null;
|
|
45463
45592
|
}
|
|
45464
45593
|
const [block] = content;
|
|
45465
|
-
if (!
|
|
45594
|
+
if (!isRecord6(block) || block.type !== "text") {
|
|
45466
45595
|
return null;
|
|
45467
45596
|
}
|
|
45468
45597
|
if (block.text === INTERRUPT_MARKER) {
|
|
@@ -45504,7 +45633,7 @@ class UsageLedger {
|
|
|
45504
45633
|
if (record.type !== "assistant" || !isMainChain(record) || message === null) {
|
|
45505
45634
|
return null;
|
|
45506
45635
|
}
|
|
45507
|
-
if (typeof message.id !== "string" || !
|
|
45636
|
+
if (typeof message.id !== "string" || !isRecord6(message.usage)) {
|
|
45508
45637
|
return null;
|
|
45509
45638
|
}
|
|
45510
45639
|
const seen = this.counted.get(message.id) ?? emptyCounts();
|
|
@@ -45531,7 +45660,7 @@ function assistantBlocks(record) {
|
|
|
45531
45660
|
}
|
|
45532
45661
|
const blocks = [];
|
|
45533
45662
|
for (const block of content) {
|
|
45534
|
-
if (!
|
|
45663
|
+
if (!isRecord6(block)) {
|
|
45535
45664
|
continue;
|
|
45536
45665
|
}
|
|
45537
45666
|
if (block.type === "text" && typeof block.text === "string" && block.text !== "") {
|
|
@@ -45551,12 +45680,12 @@ function isMainChain(record) {
|
|
|
45551
45680
|
return record.isSidechain !== true;
|
|
45552
45681
|
}
|
|
45553
45682
|
function messageOf(record) {
|
|
45554
|
-
return
|
|
45683
|
+
return isRecord6(record.message) ? record.message : null;
|
|
45555
45684
|
}
|
|
45556
45685
|
function parseLine(line) {
|
|
45557
45686
|
try {
|
|
45558
45687
|
const value = JSON.parse(line);
|
|
45559
|
-
return
|
|
45688
|
+
return isRecord6(value) ? value : null;
|
|
45560
45689
|
} catch (error) {
|
|
45561
45690
|
if (error instanceof SyntaxError) {
|
|
45562
45691
|
return null;
|
|
@@ -45594,7 +45723,7 @@ function emptyCounts() {
|
|
|
45594
45723
|
cacheCreationTokens: 0
|
|
45595
45724
|
};
|
|
45596
45725
|
}
|
|
45597
|
-
function
|
|
45726
|
+
function isRecord6(value) {
|
|
45598
45727
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45599
45728
|
}
|
|
45600
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;
|
|
@@ -45724,10 +45853,10 @@ class EventQueue {
|
|
|
45724
45853
|
},
|
|
45725
45854
|
timeoutMs: this.options.timings().ingestTimeoutMs
|
|
45726
45855
|
});
|
|
45727
|
-
if (response.status === 200 &&
|
|
45856
|
+
if (response.status === 200 && isRecord2(response.body) && typeof response.body.lastSeq === "number") {
|
|
45728
45857
|
return this.acknowledge(response.body.lastSeq);
|
|
45729
45858
|
}
|
|
45730
|
-
const error =
|
|
45859
|
+
const error = isRecord2(response.body) && isRecord2(response.body.error) ? response.body.error : {};
|
|
45731
45860
|
if (response.status === 409 && error.code === "stale_gen") {
|
|
45732
45861
|
this.options.logger.warn("tmuxd ingest moved to a newer gen", {
|
|
45733
45862
|
gen: this.options.gen,
|
|
@@ -46181,7 +46310,7 @@ class LivePane {
|
|
|
46181
46310
|
if (immediate !== "pending") {
|
|
46182
46311
|
return immediate;
|
|
46183
46312
|
}
|
|
46184
|
-
const id =
|
|
46313
|
+
const id = isRecord2(opened.body) ? text(opened.body.id) : undefined;
|
|
46185
46314
|
if (id === undefined) {
|
|
46186
46315
|
return;
|
|
46187
46316
|
}
|
|
@@ -46562,6 +46691,7 @@ class LiveDaemon {
|
|
|
46562
46691
|
const systemPromptFile = args["system-prompt-file"];
|
|
46563
46692
|
const mcpConfig = args["mcp-config"];
|
|
46564
46693
|
const featuresFile = args.features;
|
|
46694
|
+
const cliConfigFile = args["cli-config-file"];
|
|
46565
46695
|
if (id === undefined || !PANE_ID2.test(id) || cwd === undefined || !isAbsolute2(cwd)) {
|
|
46566
46696
|
return refuse("usage_error");
|
|
46567
46697
|
}
|
|
@@ -46572,7 +46702,7 @@ class LiveDaemon {
|
|
|
46572
46702
|
return refuse("usage_error");
|
|
46573
46703
|
}
|
|
46574
46704
|
const extras = parseStartExtras(args);
|
|
46575
|
-
if (extras === null || [policyFile, systemPromptFile, mcpConfig, featuresFile].some((path) => !optionalAbsolute(path))) {
|
|
46705
|
+
if (extras === null || [policyFile, systemPromptFile, mcpConfig, featuresFile, cliConfigFile].some((path) => !optionalAbsolute(path))) {
|
|
46576
46706
|
return refuse("usage_error");
|
|
46577
46707
|
}
|
|
46578
46708
|
if (this.panes.has(id) || this.starting.has(id)) {
|
|
@@ -46594,6 +46724,7 @@ class LiveDaemon {
|
|
|
46594
46724
|
systemPromptFile,
|
|
46595
46725
|
mcpConfig,
|
|
46596
46726
|
featuresFile,
|
|
46727
|
+
cliConfigFile,
|
|
46597
46728
|
extras
|
|
46598
46729
|
});
|
|
46599
46730
|
} finally {
|
|
@@ -46612,6 +46743,7 @@ class LiveDaemon {
|
|
|
46612
46743
|
systemPromptFile,
|
|
46613
46744
|
mcpConfig,
|
|
46614
46745
|
featuresFile,
|
|
46746
|
+
cliConfigFile,
|
|
46615
46747
|
extras
|
|
46616
46748
|
} = request;
|
|
46617
46749
|
const content = await readSecretFile(envFile);
|
|
@@ -46632,6 +46764,11 @@ class LiveDaemon {
|
|
|
46632
46764
|
if (features === null) {
|
|
46633
46765
|
return refuse("usage_error");
|
|
46634
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;
|
|
46635
46772
|
const mcpSpellings = mcpConfig === undefined ? [] : [...new Set([mcpConfig, await realpath2(mcpConfig)])];
|
|
46636
46773
|
const settingsPath = join4(settingsBase, `${id}.settings.json`);
|
|
46637
46774
|
await mkdir2(settingsBase, { recursive: true, mode: 448 });
|
|
@@ -46655,14 +46792,19 @@ class LiveDaemon {
|
|
|
46655
46792
|
cwd,
|
|
46656
46793
|
home: this.options.home,
|
|
46657
46794
|
settingsPath,
|
|
46658
|
-
env: { ...env.authEnv, ...features?.env },
|
|
46795
|
+
env: { ...env.authEnv, ...features?.env, ...role?.env },
|
|
46659
46796
|
model,
|
|
46660
46797
|
resumeSessionId: resume,
|
|
46661
46798
|
mcpConfig,
|
|
46662
46799
|
systemPromptFile,
|
|
46800
|
+
promptMode: extras.promptMode,
|
|
46801
|
+
agent: extras.agent,
|
|
46663
46802
|
tools: features?.tools,
|
|
46664
|
-
disallowedTools: features?.disallowedTools,
|
|
46803
|
+
disallowedTools: [...new Set([...features?.disallowedTools ?? [], ...role?.disallowedTools ?? []])],
|
|
46804
|
+
disableSlashCommands: role?.disableSlashCommands,
|
|
46665
46805
|
permissionMode: extras.permissionMode,
|
|
46806
|
+
pluginDir: extras.pluginDir,
|
|
46807
|
+
settingSources: extras.settingSources,
|
|
46666
46808
|
claudeBin: this.options.claudeBin,
|
|
46667
46809
|
socket: pane.socket,
|
|
46668
46810
|
confirmStarted: (timeoutMs) => live.started.wait(timeoutMs)
|
|
@@ -46901,7 +47043,7 @@ class LiveDaemon {
|
|
|
46901
47043
|
const request = parseRequest(line);
|
|
46902
47044
|
try {
|
|
46903
47045
|
if (request?.kind === "hook" && typeof request.pane === "string" && typeof request.event === "string") {
|
|
46904
|
-
return await this.hook(request.pane, request.event,
|
|
47046
|
+
return await this.hook(request.pane, request.event, isRecord2(request.payload) ? request.payload : {}, signal);
|
|
46905
47047
|
}
|
|
46906
47048
|
if (request?.kind === "ctl" && typeof request.verb === "string") {
|
|
46907
47049
|
return await this.ctl(request.verb, stringArgs(request.args));
|
|
@@ -46937,7 +47079,7 @@ function tokenGen(token) {
|
|
|
46937
47079
|
const [payload] = token.slice(TOKEN_PREFIX.length).split(".");
|
|
46938
47080
|
try {
|
|
46939
47081
|
const claims = JSON.parse(Buffer.from(payload ?? "", "base64url").toString("utf8"));
|
|
46940
|
-
return
|
|
47082
|
+
return isRecord2(claims) && Number.isInteger(claims.gen) ? claims.gen : null;
|
|
46941
47083
|
} catch (error) {
|
|
46942
47084
|
if (error instanceof SyntaxError) {
|
|
46943
47085
|
return null;
|
|
@@ -47036,6 +47178,10 @@ async function readPaneFeatures(path, permissionMode) {
|
|
|
47036
47178
|
const content = await readSecretFile(path);
|
|
47037
47179
|
return content === null ? null : parsePaneFeatures(content, permissionMode);
|
|
47038
47180
|
}
|
|
47181
|
+
async function readCliConfig(path) {
|
|
47182
|
+
const content = await readSecretFile(path);
|
|
47183
|
+
return content === null ? { ok: false, key: undefined } : parseCliConfig(content);
|
|
47184
|
+
}
|
|
47039
47185
|
async function readFileOrNull(path) {
|
|
47040
47186
|
return readFile3(path, "utf8").catch((error) => {
|
|
47041
47187
|
if (error.code === "ENOENT" || error.code === "EISDIR") {
|
|
@@ -47059,7 +47205,7 @@ async function removeFile(path) {
|
|
|
47059
47205
|
});
|
|
47060
47206
|
}
|
|
47061
47207
|
function decisionFrom(body) {
|
|
47062
|
-
const status =
|
|
47208
|
+
const status = isRecord2(body) ? body.status : undefined;
|
|
47063
47209
|
switch (status) {
|
|
47064
47210
|
case "pending":
|
|
47065
47211
|
return "pending";
|
|
@@ -47068,7 +47214,7 @@ function decisionFrom(body) {
|
|
|
47068
47214
|
case "denied":
|
|
47069
47215
|
return {
|
|
47070
47216
|
behavior: "deny",
|
|
47071
|
-
message: (
|
|
47217
|
+
message: (isRecord2(body) ? text(body.message) : undefined) ?? "Denied by the operator."
|
|
47072
47218
|
};
|
|
47073
47219
|
case "expired":
|
|
47074
47220
|
return {
|
|
@@ -47178,7 +47324,7 @@ function sameJson(left, right) {
|
|
|
47178
47324
|
function parseRequest(line) {
|
|
47179
47325
|
try {
|
|
47180
47326
|
const value = JSON.parse(line);
|
|
47181
|
-
return
|
|
47327
|
+
return isRecord2(value) ? value : null;
|
|
47182
47328
|
} catch (error) {
|
|
47183
47329
|
if (error instanceof SyntaxError) {
|
|
47184
47330
|
return null;
|
|
@@ -47187,7 +47333,7 @@ function parseRequest(line) {
|
|
|
47187
47333
|
}
|
|
47188
47334
|
}
|
|
47189
47335
|
function stringArgs(value) {
|
|
47190
|
-
if (!
|
|
47336
|
+
if (!isRecord2(value)) {
|
|
47191
47337
|
return {};
|
|
47192
47338
|
}
|
|
47193
47339
|
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
@@ -47219,6 +47365,7 @@ var DAEMON_VERSION, HEARTBEAT_INTERVAL_MS = 20000, WATCHDOG_QUIET_MS = 30000, CA
|
|
|
47219
47365
|
var init_daemon = __esm(() => {
|
|
47220
47366
|
init_package();
|
|
47221
47367
|
init_logger();
|
|
47368
|
+
init_cli_config();
|
|
47222
47369
|
init_events2();
|
|
47223
47370
|
init_hooks();
|
|
47224
47371
|
init_input();
|
|
@@ -47481,8 +47628,13 @@ Commands:
|
|
|
47481
47628
|
ctl <verb> [flags] Drive a Live pane through the daemon; prints one JSON line.
|
|
47482
47629
|
Verbs: start, prompt, command, cancel, stop, rotate-token, status.
|
|
47483
47630
|
start also takes --permission-mode default|dontAsk, --one-shot 0|1,
|
|
47484
|
-
--deadline-seconds N, --retain-failed-seconds N
|
|
47485
|
-
--
|
|
47631
|
+
--deadline-seconds N, --retain-failed-seconds N,
|
|
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.
|
|
47486
47638
|
hook <Event> --pane <id> --socket <path> Hook helper the pane settings run; reads the payload on stdin.
|
|
47487
47639
|
daemon Run the daemon in the foreground; ctl start spawns it detached.
|
|
47488
47640
|
|
|
@@ -47503,7 +47655,9 @@ Environment:
|
|
|
47503
47655
|
"token-file",
|
|
47504
47656
|
"mcp-config",
|
|
47505
47657
|
"tool-policy",
|
|
47506
|
-
"system-prompt-file"
|
|
47658
|
+
"system-prompt-file",
|
|
47659
|
+
"features",
|
|
47660
|
+
"cli-config-file"
|
|
47507
47661
|
]);
|
|
47508
47662
|
HANDOFF_FLAGS = new Map([
|
|
47509
47663
|
["start", START_FILE_FLAGS],
|