@rse/ase 2.0.5 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dst/ase-agent-definition-api.d.ts +2 -0
  2. package/dst/ase-agent-definition-core.js +24 -3
  3. package/dst/ase-agent-fleet.js +2 -1
  4. package/dst/ase-agent-runtime-engine.js +22 -4
  5. package/dst/ase-agent-runtime-tool.js +10 -8
  6. package/dst/ase-agent-runtime.js +8 -4
  7. package/dst/ase-config-schema.js +1 -1
  8. package/dst/ase-man-catalog.js +1 -1
  9. package/dst/ase-setup-settings.js +111 -1
  10. package/dst/ase-setup.js +19 -7
  11. package/dst/ase-spec.js +184 -49
  12. package/dst/ase-task-board-tui-model.js +8 -1
  13. package/dst/ase-task-board-tui.js +26 -2
  14. package/dst/ase-task-board-web-client.js +10 -10
  15. package/dst/ase-task-store-plugin-gitea.js +3 -3
  16. package/dst/man/ase-agent-adhoc.md +25 -6
  17. package/dst/man/ase-agent-condenser.md +7 -0
  18. package/dst/man/ase-agent-editor.md +7 -0
  19. package/dst/man/ase-agent-estimator.md +7 -0
  20. package/dst/man/ase-agent-fleet.md +7 -4
  21. package/dst/man/ase-agent-implementer.md +7 -0
  22. package/dst/man/ase-agent-integrator.md +7 -0
  23. package/dst/man/ase-agent-qualifier.md +7 -0
  24. package/dst/man/ase-agent-rebooter.md +7 -0
  25. package/dst/man/ase-agent-researcher.md +7 -0
  26. package/dst/man/ase-artifact.md +1 -1
  27. package/dst/man/ase-config.md +5 -3
  28. package/dst/man/ase-mcp.md +1 -1
  29. package/dst/man/ase-setup-install.md +10 -1
  30. package/dst/man/ase-setup-status.md +6 -0
  31. package/dst/man/ase-setup-uninstall.md +3 -1
  32. package/dst/man/ase-setup-update.md +3 -0
  33. package/dst/man/ase-setup.md +4 -4
  34. package/dst/man/ase-spec-export.md +14 -3
  35. package/dst/man/ase-spec-init.md +10 -1
  36. package/dst/man/ase-spec-lint.md +2 -1
  37. package/dst/man/ase-spec-preview.md +10 -1
  38. package/dst/man/ase-spec-query.md +96 -0
  39. package/dst/man/ase-spec.md +32 -11
  40. package/dst/man/ase.md +3 -3
  41. package/package.json +20 -17
  42. package/plugin/.claude-plugin/icon.png +0 -0
  43. package/plugin/.claude-plugin/plugin.json +1 -1
  44. package/plugin/.codex-plugin/plugin.json +1 -1
  45. package/plugin/.github/plugin/plugin.json +1 -1
  46. package/plugin/meta/ase-common-task.md +9 -1
  47. package/plugin/meta/ase-control.md +14 -0
  48. package/plugin/meta/ase-format-spec.md +29 -5
  49. package/plugin/meta/ase-format-specbook.md +427 -47
  50. package/plugin/meta/ase-format-specbook.yaml +189 -87
  51. package/plugin/meta/ase-skill.md +7 -0
  52. package/plugin/mods/ase-mods-common.ts +36 -6
  53. package/plugin/mods/ase-mods-evaluate.ts +227 -0
  54. package/plugin/mods/ase-mods-grill.ts +1 -30
  55. package/plugin/mods/ase-mods-help-browse.ts +18 -13
  56. package/plugin/mods/ase-mods-help-find.ts +17 -9
  57. package/plugin/mods/ase-mods-help-hint.ts +1 -1
  58. package/plugin/mods/ase-mods.ts +23 -17
  59. package/plugin/skills/ase-code-edit/SKILL.md +53 -16
  60. package/plugin/skills/ase-code-edit/help.md +26 -13
  61. package/plugin/skills/ase-code-lint/SKILL.md +7 -3
  62. package/plugin/skills/ase-help-intent/data.md +170 -28
  63. package/plugin/skills/ase-help-skill/catalog.md +1 -0
  64. package/plugin/skills/ase-meta-workflow/workflow.txt +2 -0
  65. package/plugin/skills/ase-repo-changelog/SKILL.md +29 -10
  66. package/plugin/skills/ase-repo-changelog/help.md +5 -1
  67. package/plugin/skills/ase-repo-commit/SKILL.md +4 -1
  68. package/plugin/skills/ase-repo-dissect/help.md +2 -1
  69. package/plugin/skills/ase-repo-stage/SKILL.md +459 -0
  70. package/plugin/skills/ase-repo-stage/help.md +120 -0
  71. package/plugin/skills/ase-spec-activate/SKILL.md +4 -1
  72. package/plugin/skills/ase-spec-edit/SKILL.md +20 -12
  73. package/plugin/skills/ase-spec-edit/help.md +22 -14
  74. package/plugin/mods/claude-code.d.ts +0 -13440
@@ -18,6 +18,7 @@ export interface AgentDefinition {
18
18
  lifecycle?: Many<string>;
19
19
  serial?: boolean;
20
20
  unclaimed?: boolean;
21
+ model?: string;
21
22
  state?: {
22
23
  incoming?: Many<string>;
23
24
  activity?: string;
@@ -175,6 +176,7 @@ export interface AgentHooks {
175
176
  ready?: (task: AgentHookTask, ctx: AgentHookContext) => Async<boolean | string>;
176
177
  prepare?: (task: AgentHookTask, job: AgentHookJob, ctx: AgentHookContext) => Async<void>;
177
178
  prompt?: (task: AgentHookTask, prompt: AgentHookPrompt, job: AgentHookJob, ctx: AgentHookContext) => Async<AgentHookPrompt | string | undefined>;
179
+ model?: (task: AgentHookTask, model: string, job: AgentHookJob, ctx: AgentHookContext) => Async<string | undefined>;
178
180
  verdict?: (task: AgentHookTask, result: AgentHookResult, ctx: AgentHookContext) => Async<string | undefined>;
179
181
  success?: (task: AgentHookTask, result: AgentHookResult, ctx: AgentHookContext) => Async<boolean | string>;
180
182
  settle?: (task: AgentHookTask, outcome: AgentHookOutcome, ctx: AgentHookContext) => Async<AgentHookSettlement | undefined>;
@@ -92,6 +92,9 @@ export const definitionOptions = [
92
92
  opt("unclaimed", "flag", "", "process the tasks of the incoming states (each adapted onto the " +
93
93
  "task lifecycle model) without claiming them, independent of their assignee and predecessors, " +
94
94
  "and without ever changing their status and assignee (for \"phase\" only)"),
95
+ opt("model", "value", "model", "model of the agent tool: a model for all tasks, or comma-separated " +
96
+ "\"<size>=<model>\" pairs per \"Effort:\" size (\"XS\", \"S\", \"M\", \"L\", \"XL\", or \"*\" for all other tasks) " +
97
+ "(default: the default model of the agent tool)"),
95
98
  opt("params", "list", "name=value", "value of a parameter declared by the definition (repeatable)"),
96
99
  opt("state-incoming", "list", "state", "state of the tasks to claim (mandatory for \"phase\", " +
97
100
  "repeatable with \"--unclaimed\" or \"--state-activity\" only)"),
@@ -272,7 +275,7 @@ export const flattenDefinition = (data, where) => {
272
275
  return flat;
273
276
  };
274
277
  /* the names of the hooks of a definition (see "AgentHooks") */
275
- const hookNames = ["start", "order", "passes", "ready", "prepare", "prompt", "verdict", "success", "settle", "finish", "stop"];
278
+ const hookNames = ["start", "order", "passes", "ready", "prepare", "prompt", "model", "verdict", "success", "settle", "finish", "stop"];
276
279
  /* normalize the parameter declarations <spec> of a definition (see "AgentParam"),
277
280
  where <where> names the definition in errors */
278
281
  const definitionParams = (spec, where) => {
@@ -741,6 +744,24 @@ export const resolveDefinition = async (opts, name) => {
741
744
  if (loaded.hooks.passes !== undefined)
742
745
  fail("definition", "hook \"passes\" is not for \"--unclaimed\" (as an unclaimed task never waits for its predecessors)");
743
746
  }
747
+ /* the model of the agent tool: a plain model (for all tasks, as size "*"),
748
+ or the models per "Effort:" size, where none means the default of the tool */
749
+ const modelSpec = str("model").trim();
750
+ const sizes = {};
751
+ if (modelSpec !== "" && !modelSpec.includes("="))
752
+ sizes["*"] = modelSpec;
753
+ else if (modelSpec !== "") {
754
+ for (const pair of modelSpec.split(",").map((item) => item.trim())) {
755
+ const m = /^(XS|S|M|L|XL|\*)=(\S+)$/.exec(pair);
756
+ if (m === null)
757
+ fail("model", `invalid pair "${pair}" (expected "<size>=<model>" with size "XS", "S", "M", "L", "XL", or "*")`);
758
+ else if (Object.hasOwn(sizes, m[1]))
759
+ fail("model", `size "${m[1]}" given twice`);
760
+ else
761
+ sizes[m[1]] = m[2];
762
+ }
763
+ }
764
+ const model = { spec: modelSpec, sizes };
744
765
  /* whether a verdict is determined (by "--verdict-label" or the hook "verdict") */
745
766
  const verdicting = has("verdict-label") || loaded.hooks.verdict !== undefined;
746
767
  /* the states (see "resolveStates") */
@@ -821,10 +842,10 @@ export const resolveDefinition = async (opts, name) => {
821
842
  hence the prompt of the request), resp. uses them optionally by "{prompt}" used only
822
843
  within the conditional "{?prompt:...}", else ignores them */
823
844
  const consumes = type === "request" && (template.required.has("prompt")
824
- || ["prepare", "prompt", "finish"].some((hook) => loaded.hooks[hook] !== undefined)) ? "required" :
845
+ || ["prepare", "prompt", "model", "finish"].some((hook) => loaded.hooks[hook] !== undefined)) ? "required" :
825
846
  type === "request" && template.names.has("prompt") ? "optional" : "ignored";
826
847
  return {
827
- name, title, description, type, workdir, lifecycles, unclaimed,
848
+ name, title, description, type, workdir, lifecycles, unclaimed, model,
828
849
  serial: flag("serial"),
829
850
  state: { incoming, activity, success, failure, phase, passed, verdict: verdicts },
830
851
  tag: {
@@ -45,7 +45,7 @@ const logLevelRe = /^([^|]*\| [^:]+: \[[^\]]+\]: )\[(ERROR|WARNING|INFO|DEBUG)\]
45
45
  agents, and applied to an agent only if it supports them) */
46
46
  const fleetKeys = ["foreground"];
47
47
  const relayKeys = ["address", "port", "token", "cors", "tls-cert", "tls-key"];
48
- const defaultKeys = ["tool", "parallel", "timeout", "repo", "tempdir", "agent-relay"];
48
+ const defaultKeys = ["tool", "model", "parallel", "timeout", "repo", "tempdir", "agent-relay"];
49
49
  /* the options not allowed in the section of an agent, as the fleet decides on them */
50
50
  const deniedKeys = ["name", "one-shot", "foreground", "help"];
51
51
  /* the state of the planned tasks per task lifecycle model, as estimated by the estimator */
@@ -76,6 +76,7 @@ const initConfig = (tool, lifecycle) => [
76
76
  # (each applied only to the agents supporting it, where an empty value omits it)
77
77
  default:
78
78
  tool: ${tool.padEnd(16)}# agent tool ("claude", "copilot", or "codex")
79
+ #model: <model> # model of the agent tool (or "<size>=<model>" pairs per "Effort:" size)
79
80
  parallel: 1 # maximum number of tasks processed in parallel
80
81
  timeout: 60m # maximum duration of processing a task (<number><unit> with unit "s", "m", or "h")
81
82
  #repo: <url> # Git repository to clone temporarily for the tasks without "worktree"
@@ -45,6 +45,15 @@ const promptOf = (value, configured) => {
45
45
  }
46
46
  throw new Error("invalid prompt (expected a string, \"{ text }\", or \"{ skill, args }\")");
47
47
  };
48
+ /* the model returned by the hook "model", validated, where undefined
49
+ keeps the configured model <configured> */
50
+ const modelOf = (value, configured) => {
51
+ if (value === undefined)
52
+ return configured;
53
+ else if (typeof value !== "string")
54
+ throw new Error("invalid model (expected a string)");
55
+ return value.trim();
56
+ };
48
57
  /* whether a record of an agent of a definition succeeded (where a missing one counts as failure) */
49
58
  const recordSuccess = (record) => record !== undefined && record.fixed === "" && record.checks.every((check) => check.ok);
50
59
  /* escape a text for its literal use in a regular expression */
@@ -331,7 +340,7 @@ class DefinedCore {
331
340
  }
332
341
  /* prepare the job of a task in its work <work>: render the prompt (with the request
333
342
  prompt <prompt> of a request agent), run the preparing commands, and run the hooks
334
- "prepare" and "prompt", where the work is cleaned up again on a failure, and where
343
+ "prepare", "prompt", and "model", where the work is cleaned up again on a failure, and where
335
344
  <changed> decides preliminarily whether the plan content of a request agent changed */
336
345
  async prepare(task, log, work, prompt, changed) {
337
346
  try {
@@ -374,7 +383,7 @@ class DefinedCore {
374
383
  throw err;
375
384
  }
376
385
  }
377
- /* run the hooks "prepare" and "prompt", where a failed hook fails the processing */
386
+ /* run the hooks "prepare", "prompt", and "model", where a failed hook fails the processing */
378
387
  const job = Object.freeze({
379
388
  dir: work.cwd,
380
389
  dirs: Object.freeze([...work.dirs]),
@@ -392,7 +401,7 @@ class DefinedCore {
392
401
  throw new Error(`agent: hook "${name}" failed: ${reason(err)}`, { cause: err });
393
402
  }
394
403
  };
395
- const { prepare: prepareHook, prompt: promptHook } = this.def.hooks;
404
+ const { prepare: prepareHook, prompt: promptHook, model: modelHook } = this.def.hooks;
396
405
  if (prepareHook !== undefined)
397
406
  await hooked("prepare", async () => prepareHook(this.task(task), job, ctx));
398
407
  let spec = this.def.prompt.skill !== "" ?
@@ -401,10 +410,17 @@ class DefinedCore {
401
410
  const configured = Object.freeze(spec);
402
411
  spec = await hooked("prompt", async () => promptOf(await promptHook(this.task(task), configured, job, ctx), configured));
403
412
  }
413
+ const { sizes } = this.def.model;
414
+ let model = sizes[TaskFormat.parseEffort(task.keys.get("Effort") ?? "")?.size ?? "*"] ?? sizes["*"] ?? "";
415
+ if (modelHook !== undefined) {
416
+ const configured = model;
417
+ model = await hooked("model", async () => modelOf(await modelHook(this.task(task), configured, job, ctx), configured));
418
+ }
404
419
  return {
405
420
  ...("skill" in spec ?
406
421
  { cmd: `${spec.skill}${spec.args !== "" ? ` ${spec.args}` : ""}` } :
407
422
  { prompt: spec.text }),
423
+ model,
408
424
  cwd: work.cwd,
409
425
  dirs: work.dirs,
410
426
  finish: (log, result) => this.finish(task, log, result, work, job, env, before, changed),
@@ -714,6 +730,7 @@ class DefinedPhaseAgent extends PhaseAgent {
714
730
  };
715
731
  this.presenceTitle = def.title;
716
732
  this.presenceDesc = def.description;
733
+ this.modelSpec = def.model.spec;
717
734
  this.assigned = def.assign.required;
718
735
  this.finishing = def.finish.commit || def.finish.success !== "" || def.workdir === "target"
719
736
  || def.hooks.finish !== undefined;
@@ -858,6 +875,7 @@ class DefinedRequestAgent extends RequestAgent {
858
875
  this.presencePrompt = def.request.prompt;
859
876
  this.presenceTitle = def.title;
860
877
  this.presenceDesc = def.description;
878
+ this.modelSpec = def.model.spec;
861
879
  this.serial = def.serial;
862
880
  this.worktree = def.workdir !== "project";
863
881
  this.lifecycles = def.lifecycles;
@@ -950,7 +968,7 @@ export class DefinedAgent extends Agent {
950
968
  for (const option of definitionOptions) {
951
969
  if (option.key === "definition" && !definition)
952
970
  continue;
953
- const flags = (option.key === "definition" ? "-D, " : "") + `--${option.key}` +
971
+ const flags = (option.key === "definition" ? "-D, " : option.key === "model" ? "-M, " : "") + `--${option.key}` +
954
972
  (option.kind !== "flag" ? ` <${option.arg}>` : "");
955
973
  if (option.kind === "list")
956
974
  cmd.option(flags, option.desc, (value, prev) => [...(prev ?? []), value]);
@@ -8,20 +8,22 @@ import { stripVTControlCharacters } from "node:util";
8
8
  of the task (as an agent message can be huge, e.g. the rendering of the whole task plan,
9
9
  which would otherwise be fed back into the next rendering of the task plan) */
10
10
  const TEXT_MAX = 20;
11
+ /* the "--model" option of all tools for the model <model> (none for the default model) */
12
+ const modelArgs = (model) => model !== "" ? ["--model", model] : [];
11
13
  /* the per-tool headless invocation of the rendered prompt <prompt> with access to the
12
- additional directories <add> (the "--add-dir" options), streaming JSONL events,
13
- where risky actions are denied or automatically reviewed instead of being prompted for
14
+ additional directories <add> (the "--add-dir" options) and the model <model>, streaming JSONL
15
+ events, where risky actions are denied or automatically reviewed instead of being prompted for
14
16
  (the variadic "--add-dir" of Claude has to precede the other options to not consume the prompt) */
15
17
  export const toolArgs = {
16
- "claude": (prompt, add) => [
17
- ...add, "-p", "--output-format", "stream-json", "--verbose", "--disallowedTools", "AskUserQuestion",
18
+ "claude": (prompt, add, model) => [
19
+ ...add, ...modelArgs(model), "-p", "--output-format", "stream-json", "--verbose", "--disallowedTools", "AskUserQuestion",
18
20
  "--permission-mode", "auto", "--permission-prompts", "none", prompt
19
21
  ],
20
- "copilot": (prompt, add) => [
21
- ...add, "--allow-all-tools", "--no-ask-user", "--no-color", "--output-format", "json", "-p", prompt
22
+ "copilot": (prompt, add, model) => [
23
+ ...add, ...modelArgs(model), "--allow-all-tools", "--no-ask-user", "--no-color", "--output-format", "json", "-p", prompt
22
24
  ],
23
- "codex": (prompt, add) => [
24
- "exec", ...add, "--json", "--approve-for-me", "--color", "never", prompt
25
+ "codex": (prompt, add, model) => [
26
+ "exec", ...add, ...modelArgs(model), "--json", "--approve-for-me", "--color", "never", prompt
25
27
  ]
26
28
  };
27
29
  /* the per-tool rendering of the invocation of the skill <skill> with the arguments <args>:
@@ -145,6 +145,8 @@ export class Agent {
145
145
  /* the title and the description of the operation of the agent, as announced in its presence (default: none) */
146
146
  presenceTitle = "";
147
147
  presenceDesc = "";
148
+ /* the configured model of the agent tool, as shown in the start log line (default: none) */
149
+ modelSpec = "";
148
150
  /* whether tasks are processed serially only (clamping "--parallel" to 1, and
149
151
  refusing multiple agents of the kind in a fleet, see "ase agent fleet") */
150
152
  serial = false;
@@ -840,7 +842,8 @@ export class Agent {
840
842
  const cli = toolSpecs[tool].cli;
841
843
  const cmd = job.cmd ?? "";
842
844
  const i = cmd.indexOf(" ");
843
- const args = toolArgs[tool](job.prompt ?? skillPrompt(tool, i < 0 ? cmd : cmd.slice(0, i), i < 0 ? "" : cmd.slice(i + 1)), [...new Set(job.dirs ?? [])].filter((dir) => dir !== cwd).flatMap((dir) => ["--add-dir", dir]));
845
+ const model = job.model ?? "";
846
+ const args = toolArgs[tool](job.prompt ?? skillPrompt(tool, i < 0 ? cmd : cmd.slice(0, i), i < 0 ? "" : cmd.slice(i + 1)), [...new Set(job.dirs ?? [])].filter((dir) => dir !== cwd).flatMap((dir) => ["--add-dir", dir]), model);
844
847
  await log("info", `running: ${cli} ${args.map((arg) => arg.includes(" ") ? `"${arg}"` : arg).join(" ")}`);
845
848
  const started = Date.now();
846
849
  const costs = { costToken: null, costUSD: null, cread: 0, cwrite: 0, input: 0, apiMs: null };
@@ -881,7 +884,7 @@ export class Agent {
881
884
  this.presence?.used(usage);
882
885
  /* book the usage onto the task, if the AI usage accounting is enabled ("telemetry.enabled"),
883
886
  (the AI request time falling back to the wall time and an unreported cost to the price
884
- table entry of the tool, as its model is unknown), without any human time and costs,
887
+ table entry of the given model, else of the tool), without any human time and costs,
885
888
  as the headless agent tool runs unattended; the times are booked in rounded minutes,
886
889
  with the (signed) rounding remainder carried over to the next booking onto the task,
887
890
  where a failed booking is only reported */
@@ -894,7 +897,8 @@ export class Agent {
894
897
  if (cost === null) {
895
898
  const cfg = new Config("config", configSchema, this.log);
896
899
  cfg.read();
897
- cost = tokenCost(modelPrice(parsePrices(String(cfg.get("telemetry.prices.ai") ?? "")), tool), tokens);
900
+ const prices = parsePrices(String(cfg.get("telemetry.prices.ai") ?? ""));
901
+ cost = tokenCost(modelPrice(prices, model !== "" && prices.has(model) ? model : tool), tokens);
898
902
  }
899
903
  const carry = this.unbooked.get(taskId) ?? { aiMs: 0, realMs: 0 };
900
904
  const aiMs = carry.aiMs + (costs.apiMs ?? walltimeMs);
@@ -1250,7 +1254,7 @@ export class Agent {
1250
1254
  if (this.repo !== "")
1251
1255
  await this.cloneRepo();
1252
1256
  await this.write("info", this.name, `observing ${this.observing()} ` +
1253
- `(tool: ${tool}, parallel: ${parallel}, timeout: ${this.timeoutSpec}${this.oneShot ? ", one-shot" : ""})`);
1257
+ `(tool: ${tool}${this.modelSpec !== "" ? `, model: ${this.modelSpec}` : ""}, parallel: ${parallel}, timeout: ${this.timeoutSpec}${this.oneShot ? ", one-shot" : ""})`);
1254
1258
  let finished = false;
1255
1259
  let failure = null;
1256
1260
  while (!abort.signal.aborted && !finished) {
@@ -61,7 +61,7 @@ export const projectClassificationPresets = {
61
61
  "project.task.effort.line": "0.025",
62
62
  "project.task.effort.iteration": "2.5",
63
63
  "project.artifact.spec.basedir": "docs/specbook",
64
- "project.artifact.spec.files": "*.{md,txt,svg,png,jpg}",
64
+ "project.artifact.spec.files": "**/*.{md,txt,svg,png,jpg}",
65
65
  "project.artifact.spec.schema": "",
66
66
  "project.artifact.code.basedir": "src",
67
67
  "project.artifact.code.files": "** !**/etc/** !**/{.gitignore,.npmignore,package.json}",
@@ -24,7 +24,7 @@ const skillGroups = [
24
24
  ["SPEC", ["ase-spec-lint", "ase-spec-edit", "ase-spec-activate"]],
25
25
  ["CODE", ["ase-code-edit", "ase-code-analyze", "ase-code-insight", "ase-code-explain", "ase-code-lint"]],
26
26
  ["REPO", ["ase-repo-review", "ase-repo-diff", "ase-repo-changelog", "ase-repo-commit",
27
- "ase-repo-dissect", "ase-repo-merge", "ase-repo-resolve"]],
27
+ "ase-repo-dissect", "ase-repo-stage", "ase-repo-merge", "ase-repo-resolve"]],
28
28
  ["SYNC", ["ase-sync-reconcile", "ase-sync-import", "ase-sync-export"]],
29
29
  ["TASK: MANAGE", ["ase-task-list", "ase-task-rename", "ase-task-delete"]],
30
30
  ["TASK: HANDLE", ["ase-task-id", "ase-task-status", "ase-task-assign"]],
@@ -11,7 +11,7 @@ import { mkdirp } from "mkdirp";
11
11
  import JsonAsty from "json-asty";
12
12
  import { toolSpecs } from "./ase-setup-common.js";
13
13
  import { telemetryEndpoint, telemetryEnabled } from "./ase-service-otel.js";
14
- /* settings file handling of "ase setup statusline", "ase setup telemetry", and the output style */
14
+ /* settings file handling of "ase setup statusline", "ase setup telemetry", the output style, and the function hooks */
15
15
  export class SetupSettings {
16
16
  log;
17
17
  constructor(log) {
@@ -358,6 +358,116 @@ export class SetupSettings {
358
358
  }
359
359
  return entries;
360
360
  }
361
+ /* the environment variable enabling the function hooks of the plugin-shipped mods
362
+ (Anthropic Claude Code CLI only, as the other tools have no function hooks concept) */
363
+ functionHooksVar = "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS";
364
+ /* determine the value of the function hooks variable in an "env" object */
365
+ functionHooksValue(env) {
366
+ const val = this.settingsFindMember(env, this.functionHooksVar)?.query("/ * [ pos() == 2 ]")[0];
367
+ return val !== undefined ? String(val.get("value") ?? "") : undefined;
368
+ }
369
+ /* enable the function hooks of the plugin-shipped mods by setting their
370
+ variable in the "env" of the settings file of the scope */
371
+ async functionHooksActivate(action, scope) {
372
+ const file = this.settingsFile("claude", scope);
373
+ const root = await this.settingsReadAst(file);
374
+ /* reject a non-object "env" member */
375
+ let member = this.settingsFindMember(root, "env");
376
+ let env = member?.query("/ * [ pos() == 2 ]")[0];
377
+ if (member !== undefined && (env === undefined || env.type() !== "object")) {
378
+ this.log.write("warning", `setup: ${action}: a non-object "env" ` +
379
+ `is present in ${file}: preserving it (skipped)`);
380
+ return;
381
+ }
382
+ /* leave an ASE variable as is and preserve a foreign value: skip and warn */
383
+ const value = env !== undefined ? this.functionHooksValue(env) : undefined;
384
+ if (value !== undefined) {
385
+ if (value !== "1")
386
+ this.log.write("warning", `setup: ${action}: a non-ASE "${this.functionHooksVar}" ` +
387
+ `is already present in "env" of ${file}: preserving it (skipped)`);
388
+ return;
389
+ }
390
+ /* insert a fresh (still empty) "env" member */
391
+ if (member === undefined || env === undefined) {
392
+ env = root.create("object").set({ prolog: "{", epilog: "}" });
393
+ member = root.create("member").add(root.create("string").set({ body: JSON.stringify("env"), value: "env", epilog: ": " }), env);
394
+ this.settingsAddMember(root, member, false);
395
+ }
396
+ /* add the variable */
397
+ const key = root.create("string").set({
398
+ body: JSON.stringify(this.functionHooksVar),
399
+ value: this.functionHooksVar,
400
+ epilog: ": "
401
+ });
402
+ const val = root.create("string").set({ body: JSON.stringify("1"), value: "1" });
403
+ env.add(root.create("member").add(key, val));
404
+ this.settingsNormalizeObject(env, 1, this.settingsTrailing(root, member));
405
+ await this.settingsWriteAst(file, root);
406
+ this.log.write("info", `setup: ${action}: enabling function hooks in "env" of ${file}`);
407
+ }
408
+ /* disable the function hooks of the plugin-shipped mods by removing
409
+ their variable from the "env" of the settings file of the scope */
410
+ async functionHooksDeactivate(action, scope) {
411
+ const file = this.settingsFile("claude", scope);
412
+ /* a missing settings file means nothing to remove */
413
+ try {
414
+ await fs.access(file);
415
+ }
416
+ catch {
417
+ return;
418
+ }
419
+ const root = await this.settingsReadAst(file);
420
+ const member = this.settingsFindMember(root, "env");
421
+ const env = member?.query("/ * [ pos() == 2 ]")[0];
422
+ if (member === undefined || env === undefined || env.type() !== "object")
423
+ return;
424
+ const target = this.settingsFindMember(env, this.functionHooksVar);
425
+ if (target === undefined)
426
+ return;
427
+ /* preserve a foreign value: skip and warn */
428
+ if (this.functionHooksValue(env) !== "1") {
429
+ this.log.write("warning", `setup: ${action}: a non-ASE "${this.functionHooksVar}" ` +
430
+ `is present in "env" of ${file}: preserving it (skipped)`);
431
+ return;
432
+ }
433
+ /* remove the variable and, if it became empty, the "env" member */
434
+ env.del(target);
435
+ if (env.query("/ member").length === 0)
436
+ this.settingsRemoveMember(root, member);
437
+ else
438
+ this.settingsNormalizeObject(env, 1, this.settingsTrailing(root, member));
439
+ await this.settingsWriteAst(file, root);
440
+ this.log.write("info", `setup: ${action}: disabling function hooks in "env" of ${file}`);
441
+ }
442
+ /* probe the function hooks variables by inspecting the tool
443
+ settings files of all installation scopes (Anthropic Claude Code CLI only) */
444
+ async functionHooksStatus(tool) {
445
+ if (tool !== "claude")
446
+ return [];
447
+ const scopes = ["user", "project", "local"];
448
+ const entries = [];
449
+ for (const scope of scopes) {
450
+ const file = this.settingsFile(tool, scope);
451
+ let root;
452
+ try {
453
+ root = await this.settingsReadAst(file);
454
+ }
455
+ catch {
456
+ /* an unparsable settings file carries no usable state */
457
+ continue;
458
+ }
459
+ const env = this.settingsFindMember(root, "env")?.query("/ * [ pos() == 2 ]")[0];
460
+ const value = env !== undefined && env.type() === "object" ? this.functionHooksValue(env) : undefined;
461
+ if (value === undefined)
462
+ continue;
463
+ entries.push({
464
+ file: this.fileDisplay(file),
465
+ scope,
466
+ status: value === "1" ? "enabled" : "foreign"
467
+ });
468
+ }
469
+ return entries;
470
+ }
361
471
  /* auto-detect the scope in which the ASE plugin is currently
362
472
  installed, so an omitted --scope targets the existing installation
363
473
  instead of blindly assuming the per-user scope; only the Anthropic
package/dst/ase-setup.js CHANGED
@@ -38,9 +38,12 @@ export default class SetupCommand {
38
38
  const scopeArgs = tool === "claude" && scope !== "user" ? ["--scope", scope] : [];
39
39
  await this.runner.run(spec.cli, ["plugin", "marketplace", "add", source, ...scopeArgs]);
40
40
  await this.runner.run(spec.cli, ["plugin", spec.pInstall, "ase@ase", ...scopeArgs], { retries: 3 });
41
- /* select the plugin-shipped ASE output style (Anthropic Claude Code CLI only) */
42
- if (tool === "claude")
41
+ /* select the plugin-shipped ASE output style and enable the function
42
+ hooks of the plugin-shipped mods (Anthropic Claude Code CLI only) */
43
+ if (tool === "claude") {
43
44
  await this.settings.outputStyleActivate(`install${dev ? "[dev]" : ""}`, scope);
45
+ await this.settings.functionHooksActivate(`install${dev ? "[dev]" : ""}`, scope);
46
+ }
44
47
  return 0;
45
48
  }
46
49
  /* handler for "ase setup update" (all tools) */
@@ -97,9 +100,12 @@ export default class SetupCommand {
97
100
  await this.runner.run(spec.cli, ["plugin", spec.pInstall, "ase@ase", ...scopeArgs], { retries: 3 });
98
101
  }
99
102
  }
100
- /* select the plugin-shipped ASE output style (Anthropic Claude Code CLI only) */
101
- if (tool === "claude")
103
+ /* select the plugin-shipped ASE output style and enable the function
104
+ hooks of the plugin-shipped mods (Anthropic Claude Code CLI only) */
105
+ if (tool === "claude") {
102
106
  await this.settings.outputStyleActivate(`update${dev ? "[dev]" : ""}`, scope);
107
+ await this.settings.functionHooksActivate(`update${dev ? "[dev]" : ""}`, scope);
108
+ }
103
109
  return 0;
104
110
  }
105
111
  /* handler for "ase setup enable|disable" (all tools) */
@@ -130,9 +136,12 @@ export default class SetupCommand {
130
136
  this.log.write("info", `setup: uninstall${dev ? "[dev]" : ""}: ` +
131
137
  "stopping potentially running ASE service");
132
138
  await this.runner.run("ase", ["service", "stop"], { quiet: true, ignoreError: "ASE service not running" });
133
- /* deselect the plugin-shipped ASE output style (Anthropic Claude Code CLI only) */
134
- if (tool === "claude")
139
+ /* deselect the plugin-shipped ASE output style and disable the function
140
+ hooks of the plugin-shipped mods (Anthropic Claude Code CLI only) */
141
+ if (tool === "claude") {
135
142
  await this.settings.outputStyleDeactivate(`uninstall${dev ? "[dev]" : ""}`, scope);
143
+ await this.settings.functionHooksDeactivate(`uninstall${dev ? "[dev]" : ""}`, scope);
144
+ }
136
145
  /* uninstall ASE plugin */
137
146
  this.log.write("info", `setup: uninstall${dev ? "[dev]" : ""}: ` +
138
147
  `uninstalling ASE ${spec.label} plugin (origin: ${dev ? "local" : "remote/bundled"})`);
@@ -172,6 +181,9 @@ export default class SetupCommand {
172
181
  /* report the ASE output style selections */
173
182
  for (const outputStyle of await this.settings.outputStyleStatus(tool))
174
183
  rows.push(["OUTPUTSTYLE", chalk.bold(outputStyle.file), outputStyle.scope, outputStyle.status]);
184
+ /* report the function hooks enablements */
185
+ for (const functionHooks of await this.settings.functionHooksStatus(tool))
186
+ rows.push(["FUNCTIONHOOKS", chalk.bold(functionHooks.file), functionHooks.scope, functionHooks.status]);
175
187
  /* report the ASE statusline registrations */
176
188
  for (const statusline of await this.settings.statuslineStatus(tool))
177
189
  rows.push(["STATUSLINE", chalk.bold(statusline.file), statusline.scope, statusline.status]);
@@ -307,7 +319,7 @@ export default class SetupCommand {
307
319
  /* register CLI sub-command "ase setup status" */
308
320
  setupCmd
309
321
  .command("status")
310
- .description("report the ASE plugin, MCP server, output style, statusline, and telemetry registrations for a tool")
322
+ .description("report the ASE plugin, MCP server, output style, function hooks, statusline, and telemetry registrations for a tool")
311
323
  .option("-t, --tool <tool>", "target tool (\"claude\", \"copilot\", or \"codex\")", toolDflt)
312
324
  .action(async (opts) => {
313
325
  process.exit(await this.doStatus(parseTool(opts.tool)));