aligndev 0.23.0 → 0.23.1

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.
@@ -1,7 +1,11 @@
1
1
  import { isCompacted } from "./run-agent.js";
2
+ // After the agent's turn, `claude -p` waits for its background work, but stops it after 10 minutes
3
+ // of idle waiting by default. `0` waits until the work ends.
4
+ const CLAUDE_ENV = { CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS: "0" };
2
5
  export function createClaudeAdapter() {
3
6
  return {
4
7
  executable: "claude",
8
+ env: CLAUDE_ENV,
5
9
  buildArgs: buildClaudeArgs,
6
10
  createState: createClaudeState,
7
11
  interpretLine: interpretClaudeLine,
@@ -52,9 +56,7 @@ export function interpretClaudeLine(line, state) {
52
56
  case "result":
53
57
  state.protocolComplete = true;
54
58
  state.protocolFailed = event.is_error === true;
55
- state.result = asString(event.result);
56
- if (state.protocolFailed)
57
- state.failure = state.result;
59
+ captureResult(asString(event.result), state);
58
60
  return;
59
61
  case "unparsed":
60
62
  return asString(event.raw);
@@ -73,6 +75,15 @@ export function assessClaudeState(state) {
73
75
  contextCompacted: isCompacted(state),
74
76
  };
75
77
  }
78
+ // Background work wakes the agent for more turns, each closed by its own `result` event. A turn
79
+ // with nothing to report closes with an empty one, which must not erase the previous result.
80
+ function captureResult(result, state) {
81
+ if (state.protocolFailed)
82
+ state.failure = result;
83
+ if (result === "" && state.result !== undefined)
84
+ return;
85
+ state.result = result;
86
+ }
76
87
  // What the newest assistant response holds in the context window. Claude reports cache reads and
77
88
  // writes beside `input_tokens`, so the occupancy is their sum plus the response itself. A subagent
78
89
  // message carries `parent_tool_use_id` and measures its own context, not the main conversation's.
@@ -54,7 +54,7 @@ export interface SessionArgs {
54
54
  export declare function runCode(tokens: string[], config: LoadedConfig, ctx: CodeContext): Promise<number>;
55
55
  export declare function parseCodeArgs(tokens: string[], aligndev: string): CodeCommand;
56
56
  export declare function validateSessionArgs(args: SessionArgs, models: readonly string[]): string | undefined;
57
- export declare function checkLaunchGuards(args: SessionArgs, agent: CodingAgent, realCwd: string, records: SessionRecord[]): string | undefined;
57
+ export declare function checkLaunchGuards(args: SessionArgs, agent: CodingAgent, realCwd: string, ticket: string | undefined, records: SessionRecord[]): string | undefined;
58
58
  export declare function resolveTicket(args: SessionArgs, records: SessionRecord[]): string | undefined;
59
59
  export interface RunInput {
60
60
  args: SessionArgs;
@@ -332,15 +332,14 @@ async function runSession(args, code, ctx) {
332
332
  return 1;
333
333
  }
334
334
  const records = listSessionRecords(tree.sessionsDir);
335
- const guardError = checkLaunchGuards(args, agent, tree.cwd, records);
335
+ const resolvedTicket = args.noTicket ? undefined : resolveTicket(args, records);
336
+ const guardError = checkLaunchGuards(args, agent, tree.cwd, resolvedTicket, records);
336
337
  if (guardError) {
337
338
  stderr.write(`${guardError}\n`);
338
339
  return 1;
339
340
  }
340
341
  const now = new Date();
341
- const ticket = args.noTicket
342
- ? reserveSideTicket(alignfirstCommand, cwd, env)
343
- : resolveTicket(args, records);
342
+ const ticket = args.noTicket ? reserveSideTicket(alignfirstCommand, cwd, env) : resolvedTicket;
344
343
  if (ticket !== undefined && !args.noTicket && args.resume === undefined) {
345
344
  openTicket(alignfirstCommand, cwd, ticket, env);
346
345
  }
@@ -404,7 +403,7 @@ async function runSession(args, code, ctx) {
404
403
  }
405
404
  // Fail-fast launch guards, run against the (healed) session records before anything is written.
406
405
  // Returns the error to print, or `undefined` when the launch may proceed.
407
- export function checkLaunchGuards(args, agent, realCwd, records) {
406
+ export function checkLaunchGuards(args, agent, realCwd, ticket, records) {
408
407
  if (args.resume !== undefined) {
409
408
  // A resumed run writes a new session file carrying the same sessionId as the original, so one
410
409
  // id can match several records — a running status on any of them blocks.
@@ -426,16 +425,24 @@ export function checkLaunchGuards(args, agent, realCwd, records) {
426
425
  `selected agent is ${agent}.`);
427
426
  }
428
427
  }
429
- // Protocol runs only: plain messages (answers, questions, plan executions) may run at any time.
428
+ // Protocol runs only, against other protocol runs: they share the working tree, and
429
+ // `alignfirst ticket --next` reserves no work-file prefix within a ticket.
430
430
  if (args.protocol !== undefined) {
431
- const busy = records.find((r) => r.frontmatter.status === "running" && r.frontmatter.cwd === realCwd);
432
- if (busy) {
433
- return (`Error: a protocol run is already active in this worktree (${busy.path}, ` +
434
- `pid ${busy.frontmatter.pid}); one protocol run at a time per worktree.`);
435
- }
431
+ const active = records.filter((r) => r.frontmatter.status === "running" && r.frontmatter.protocol !== null);
432
+ const sameWorktree = active.find((r) => r.frontmatter.cwd === realCwd);
433
+ if (sameWorktree)
434
+ return busyProtocolError(sameWorktree, "in this worktree");
435
+ const sameTicket = ticket === undefined ? undefined : active.find((r) => r.frontmatter.ticket === ticket);
436
+ if (sameTicket)
437
+ return busyProtocolError(sameTicket, `on ticket ${ticket}`);
436
438
  }
437
439
  return;
438
440
  }
441
+ function busyProtocolError(record, scope) {
442
+ return (`Error: a ${record.frontmatter.protocol} protocol run is already active ${scope} ` +
443
+ `(${record.path}, pid ${record.frontmatter.pid}); one protocol run at a time per worktree ` +
444
+ "and per ticket.");
445
+ }
439
446
  // The newest record of a non-empty list: a resumed session has one record per run.
440
447
  function latestRecord(records) {
441
448
  return [...records].sort((a, b) => b.frontmatter.startedAt.localeCompare(a.frontmatter.startedAt))[0];
@@ -550,6 +557,7 @@ export function buildRunConfig(input) {
550
557
  protocol: args.protocol,
551
558
  ticket: input.ticket,
552
559
  message: args.message,
560
+ newSession: args.resume === undefined,
553
561
  catchupContent: input.catchupContent,
554
562
  contextContent: input.contextContent,
555
563
  alignfirst: input.alignfirst,
@@ -1,9 +1,11 @@
1
1
  export declare const PROTOCOLS: readonly ["spec", "plan", "aad", "description", "review", "merge"];
2
+ export declare const RUN_CONTEXT: string;
2
3
  export type Protocol = (typeof PROTOCOLS)[number];
3
4
  export interface PromptInput {
4
5
  protocol?: string;
5
6
  ticket?: string;
6
7
  message?: string;
8
+ newSession: boolean;
7
9
  catchupContent?: string;
8
10
  contextContent?: string;
9
11
  alignfirst: string;
@@ -1,14 +1,20 @@
1
1
  export const PROTOCOLS = ["spec", "plan", "aad", "description", "review", "merge"];
2
+ // Opens every new session. Codex kills its subagents when its turn ends; Claude waits for them.
3
+ export const RUN_CONTEXT = "You run non-interactively. When your turn ends, the process exits and kills every subagent " +
4
+ "and background command still running. Before ending your turn, wait for each one you started " +
5
+ "and check its result.";
2
6
  export function buildPrompt(input) {
3
- const { protocol, ticket, message, catchupContent, contextContent, alignfirst } = input;
7
+ const { protocol, ticket, message, newSession, catchupContent, contextContent, alignfirst } = input;
4
8
  const instruction = protocol === undefined ? message : buildProtocolPrompt(alignfirst, protocol, ticket, message);
5
- if (catchupContent === undefined && contextContent === undefined)
6
- return instruction ?? "";
7
9
  const sections = [];
10
+ if (newSession)
11
+ sections.push("## Run context", RUN_CONTEXT);
8
12
  if (contextContent !== undefined)
9
13
  sections.push("## Project context", contextContent.trimEnd());
10
14
  if (catchupContent !== undefined)
11
15
  sections.push("## Ticket history", catchupContent);
16
+ if (sections.length === 0)
17
+ return instruction ?? "";
12
18
  sections.push("## Current instruction", currentInstruction(instruction, catchupContent));
13
19
  return sections.join("\n\n");
14
20
  }
@@ -41,6 +41,7 @@ export interface AgentAssessment {
41
41
  }
42
42
  export interface AgentAdapter {
43
43
  executable: string;
44
+ env?: Readonly<Record<string, string>>;
44
45
  buildArgs(config: RunConfig): string[];
45
46
  createState(): AgentProtocolState;
46
47
  interpretLine(line: string, state: AgentProtocolState): string | undefined;
@@ -63,7 +63,7 @@ function selectResult(adapter, state, assessment, outcome, authRequired) {
63
63
  function spawnAgent(config, adapter, state, out, spawnProcess) {
64
64
  const child = spawnProcess(adapter.executable, adapter.buildArgs(config), {
65
65
  cwd: config.cwd,
66
- env: buildAgentEnv(config.env, config.unset),
66
+ env: { ...buildAgentEnv(config.env, config.unset), ...adapter.env },
67
67
  stdio: ["pipe", "pipe", "pipe"],
68
68
  });
69
69
  const detachChildGuards = guardChildLifecycle(child, config.sessionFilePath, state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aligndev",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "license": "CC0-1.0",
5
5
  "author": "Thomas MUR",
6
6
  "description": "The AlignDev CLI: the assistant's playbook, coding-agent delegation, and project inventory.",
@@ -37,7 +37,7 @@ As soon as the run is backgrounded, tell the user — in the user's language —
37
37
 
38
38
  Each ticketed run writes `.plans/<ticket>/_aligndev/<stamp>.md`. This file is the durable record of the run. It may live in the project's companion directory; the `sessionFile:` line of `{{ALIGNDEV}} code status` gives the actual path. Its frontmatter carries `status` (`running` → `succeeded`/`failed`) and the `sessionId`, and the `---- Result ----` block holds the outcome.
39
39
 
40
- **One protocol run at a time per workspace** — protocol runs share the working tree. Finish (or kill) the current protocol run before launching or resuming another. Plain messages (answers, questions) can be sent at any time.
40
+ **One protocol run at a time per workspace and per ticket** — protocol runs share the working tree, and the ticket's work files. Finish (or kill) the current protocol run before launching or resuming another. Plain messages (answers, questions) can be sent at any time.
41
41
 
42
42
  ## After a background run completes
43
43
 
@@ -74,7 +74,7 @@ Coding runs can be long (several hours is fine), and a foreground command is sub
74
74
 
75
75
  Run `{{ALIGNDEV}} code` outside your sandbox: the agent needs network access, and it writes outside the project, to its own session storage and possibly to the companion directory. In Codex, request escalated permissions for the command. In Claude Code with sandboxing enabled, run it with the sandbox disabled.
76
76
 
77
- **One protocol run at a time per worktree** — protocol runs share the working tree. Finish (or kill) the current protocol run before launching or resuming another. Plain messages (answers, questions) can be sent at any time.
77
+ **One protocol run at a time per worktree and per ticket** — protocol runs share the working tree, and the ticket's work files. Finish (or kill) the current protocol run before launching or resuming another. Plain messages (answers, questions) can be sent at any time.
78
78
 
79
79
  ## Background runs and reporting
80
80