aligndev 0.24.0 → 0.26.0
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/README.md +73 -15
- package/dist/alignfirst-cli.d.ts +2 -0
- package/dist/alignfirst-cli.js +62 -1
- package/dist/cli.js +8 -14
- package/dist/code/claude-agent.d.ts +1 -1
- package/dist/code/claude-agent.js +25 -11
- package/dist/code/code-cli.d.ts +6 -3
- package/dist/code/code-cli.js +136 -63
- package/dist/code/codex-agent.d.ts +2 -2
- package/dist/code/codex-agent.js +24 -8
- package/dist/code/codex-rollout.d.ts +1 -1
- package/dist/code/codex-rollout.js +9 -5
- package/dist/code/coding-agent.js +1 -1
- package/dist/code/models.d.ts +2 -2
- package/dist/code/models.js +20 -15
- package/dist/code/native-context.d.ts +2 -0
- package/dist/code/native-context.js +21 -0
- package/dist/code/pi-agent.js +12 -1
- package/dist/code/quota-process.d.ts +9 -0
- package/dist/code/quota-process.js +165 -0
- package/dist/code/quota.d.ts +2 -3
- package/dist/code/quota.js +91 -100
- package/dist/code/run-agent.d.ts +8 -2
- package/dist/code/run-agent.js +33 -16
- package/dist/code/session-file.d.ts +3 -0
- package/dist/code/session-file.js +32 -9
- package/dist/config.d.ts +44 -7
- package/dist/config.js +210 -44
- package/dist/guide/code-guide.d.ts +2 -2
- package/dist/guide/code-guide.js +10 -7
- package/dist/guide/guide-cli.js +16 -7
- package/dist/json-shape.d.ts +5 -3
- package/dist/json-shape.js +39 -12
- package/dist/package-version.d.ts +1 -0
- package/dist/package-version.js +7 -0
- package/dist/project/layout.d.ts +4 -0
- package/dist/project/layout.js +29 -11
- package/dist/project/render.js +3 -1
- package/dist/project/status.d.ts +2 -1
- package/dist/project/status.js +1 -0
- package/package.json +4 -4
- package/templates/guide/code.md +32 -11
package/README.md
CHANGED
|
@@ -30,13 +30,13 @@ A task can also start at any intermediate step.
|
|
|
30
30
|
|
|
31
31
|
**As an OpenClaw bot.** [AlignDev for OpenClaw](#start-as-an-openclaw-bot) deploys the assistant on a server, under its own name in Slack or Discord. It works on every project of the host, one thread per task.
|
|
32
32
|
|
|
33
|
-
For a coding-agent assistant, parent host and delegated child are independent:
|
|
33
|
+
For a coding-agent assistant, parent host and delegated child are independent: a coding profile selects Claude Code, Codex or Pi. Without a named selection, the detected parent kind selects a matching profile or built-in child defaults. OpenClaw deployment templates offer all three agents on Slack or Discord, with explicit profiles and inventoried default/custom native stores. The Pi overlay uses a protected absolute-Node launcher while retaining project PATH. Its [deployment boundary](https://github.com/paleo/alignfirst/blob/main/skills/alignfirst-setup-guide/references/aligndev-openclaw.md#deployment-gate) explicitly permits writable native `auth.json` and adjacent locks for OAuth renewal. That file can persist same-account executable API-key commands; this is account-level persistence, not administrator privilege escalation. Other managed resources and trust retain controlled-maintenance protection. Project trust is not a sandbox, and offline checks do not certify live deployment.
|
|
34
34
|
|
|
35
35
|
## Start in Claude Code, Codex or Pi
|
|
36
36
|
|
|
37
37
|
The project needs an AlignFirst `.plans` directory, in its repository or in a [companion directory](https://github.com/paleo/alignfirst/tree/main/packages/alignfirst#companion-directories). The [setup guide](https://github.com/paleo/alignfirst/blob/main/skills/alignfirst-setup-guide/references/coding-agent-assistant.md) prepares it.
|
|
38
38
|
|
|
39
|
-
The child needs network access and writes outside the repository. Claude Code/Codex parents request their established sandbox bypass or elevation; approve that request when it comes. Pi uses ordinary OS permissions and saved project trust. It has no implied sandbox or per-command approval boundary, and `
|
|
39
|
+
The child needs network access and writes outside the repository. Claude Code/Codex parents request their established sandbox bypass or elevation; approve that request when it comes. Pi uses ordinary OS permissions and saved project trust. It has no implied sandbox or per-command approval boundary, and A profile's `skipPermissions` has no effect on Pi.
|
|
40
40
|
|
|
41
41
|
### With the Skill
|
|
42
42
|
|
|
@@ -74,29 +74,87 @@ Then ask your session to work with aligndev.
|
|
|
74
74
|
### Requirements
|
|
75
75
|
|
|
76
76
|
- Node.js 22.11 or later. The assistant runs `aligndev` through `npx`, so there is nothing to install.
|
|
77
|
-
- The selected child installed and authenticated
|
|
77
|
+
- The selected child installed and authenticated under the same effective environment and cwd as the child. Apply the profile's `unset/env/configDir`, including HOME, PATH and credential routing, before using `claude` then `/login`, `codex login`, or `pi` then `/login <provider>` (or configured provider credentials). A bare login in another shell may select another account. Pi requires Node.js 22.19 or later; the Pi adapter and extensions target Pi 1.3.0.
|
|
78
78
|
- For Pi, select a usable native model, preferably `provider/model` (optional thinking suffix). Authenticate in the same account/configuration used by the child; never expose credential values in diagnostics.
|
|
79
79
|
- Linux or macOS, or Windows through WSL.
|
|
80
80
|
|
|
81
81
|
## Configuration
|
|
82
82
|
|
|
83
|
-
`~/.alignfirst/aligndev.settings.json` is optional. Without it,
|
|
83
|
+
`~/.alignfirst/aligndev.settings.json` is optional. Without it, one detected parent kind supplies built-in child defaults. A minimal singleton setup is:
|
|
84
84
|
|
|
85
85
|
```json
|
|
86
86
|
{
|
|
87
|
-
"code": {
|
|
87
|
+
"code": {
|
|
88
|
+
"profiles": { "work": { "agent": "claude", "configDir": "~/.claude-work" } }
|
|
89
|
+
}
|
|
88
90
|
}
|
|
89
91
|
```
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
- `projectsRoot` — the projects directory of an OpenClaw host. Required by `openclaw`. `~/` expands to the home directory; a relative path resolves against `~/.alignfirst/`.
|
|
93
|
-
- `code.agent` — the child: `claude`, `codex` or `pi`. Default: the coding agent running the assistant, detected from its environment. Set it to choose another child or resolve mixed host markers. It never selects the parent's launch tool.
|
|
94
|
-
- `code.defaultModel` — the model of a new session without `--model`, one of the accepted models. Default: the child's own default. A resumed session keeps its recorded model; Pi resumes require the original worktree.
|
|
95
|
-
- `code.models` — a nonempty list restricts accepted selectors. Defaults: Claude's `fable`, `opus`, `sonnet`, `haiku`, or Codex's `astra`, `sol`, `terra`, `luna`. Pi accepts any nonblank native selector by default, preferably `provider/model`; an absent or empty list adds no allowlist.
|
|
96
|
-
- `code.skipPermissions` — `true` runs Claude Code with `--dangerously-skip-permissions` instead of `--permission-mode auto`, and Codex with `--dangerously-bypass-approvals-and-sandbox` instead of `--sandbox workspace-write`. Default: `false`. Irrelevant to Pi's ordinary OS permissions.
|
|
97
|
-
- `code.unset` — environment variables to hide from the agent, such as an API key meant for another tool on the host.
|
|
93
|
+
A Claude parent selects `work` automatically. With no detected parent, a sole total profile is also selected. A Codex or Pi parent keeps its own built-ins when no profile matches. Multiple detected kinds require a named selection.
|
|
98
94
|
|
|
99
|
-
|
|
95
|
+
For multiple accounts and independent quota sources:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"code": {
|
|
100
|
+
"profile": "codex-personal",
|
|
101
|
+
"profiles": {
|
|
102
|
+
"codex-personal": { "agent": "codex", "configDir": "~/.codex", "defaultModel": "sol" },
|
|
103
|
+
"claude-personal": {
|
|
104
|
+
"agent": "claude", "default": true, "configDir": "~/.claude", "defaultModel": "opus",
|
|
105
|
+
"unset": ["ANTHROPIC_API_KEY"]
|
|
106
|
+
},
|
|
107
|
+
"claude-work": {
|
|
108
|
+
"agent": "claude", "configDir": "~/.claude-work", "defaultModel": "opus",
|
|
109
|
+
"unset": ["ANTHROPIC_API_KEY"]
|
|
110
|
+
},
|
|
111
|
+
"pi-codex": {
|
|
112
|
+
"agent": "pi", "default": true, "configDir": "~/.pi/agent", "defaultModel": "sol",
|
|
113
|
+
"modelAliases": { "sol": "openai/sol" },
|
|
114
|
+
"quota": { "source": "codex", "configDir": "~/.codex" }
|
|
115
|
+
},
|
|
116
|
+
"pi-anthropic": {
|
|
117
|
+
"agent": "pi", "configDir": "~/.pi/anthropic", "defaultModel": "opus",
|
|
118
|
+
"modelAliases": { "opus": "anthropic/opus" },
|
|
119
|
+
"quota": { "source": "claude", "configDir": "~/.claude" }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The Pi targets illustrate native shorthand; availability depends on Pi's catalog and account. Exact provider-qualified IDs pin a model. Provider-qualified fuzzy selectors and thinking suffixes pass unchanged to Pi, which owns their resolution. AlignDev neither guesses providers nor implements newest-family ordering.
|
|
127
|
+
|
|
128
|
+
- `platform` — `codingAgent` (default), or `openclaw`.
|
|
129
|
+
- `projectsRoot` — projects directory, required by the OpenClaw playbook. `~/` uses the configured home; relative paths resolve against the settings directory.
|
|
130
|
+
- `code.profile` — global named child profile, independent of the parent host.
|
|
131
|
+
- `code.profiles` — complete profiles, with required `agent` (`claude`, `codex`, `pi`). Names and references are exact, nonblank strings. Profiles have no inheritance or merging.
|
|
132
|
+
|
|
133
|
+
Remove `code.profile` above to use automatic per-agent selection: the sole Codex profile, the preferred Claude profile or the preferred Pi profile.
|
|
134
|
+
|
|
135
|
+
Each profile accepts:
|
|
136
|
+
|
|
137
|
+
- `default` — optional boolean preference for this profile's agent. With several matching profiles, exactly one true flag selects the preference. Omitted and false are equivalent; a sole matching profile needs no flag. At most one true flag per agent is allowed, even with a named choice. Independent defaults for different agents are valid. The flag never selects an agent kind.
|
|
138
|
+
- `configDir` — native configuration and authentication storage: `CLAUDE_CONFIG_DIR`, `CODEX_HOME`, or `PI_CODING_AGENT_DIR`. `~/` uses the configured home; relative paths resolve against the settings directory. Omission keeps native inherited/default storage.
|
|
139
|
+
- `env` — literal environment values for non-secret configuration. No interpolation or shell expansion. Keep credentials in native stores or separately provisioned process environments.
|
|
140
|
+
- `unset` — inherited variables to remove, including API keys that select an unintended authentication route. A variable cannot occur in both `env` and `unset`. An explicit `configDir` cannot coexist with its native directory variable in either field.
|
|
141
|
+
- `defaultModel` — new-session default, validated against accepted names. Omission uses the native default.
|
|
142
|
+
- `models` — a nonempty list replaces accepted names. Otherwise Claude accepts `fable`, `opus`, `sonnet`, `haiku`, Codex accepts `astra`, `sol`, `terra`, `luna`, and both add configured alias names. Pi accepts every nonblank selector. An empty list adds no override.
|
|
143
|
+
- `modelAliases` — one-step user-facing name → native selector mappings. Validate the chosen name first, expand once, then apply native handling. A Codex alias target such as `sol` still resolves through its bundled catalog.
|
|
144
|
+
- `skipPermissions` — defaults to false. Claude uses `--permission-mode auto`, or `--dangerously-skip-permissions`; Codex uses `--sandbox workspace-write`, or `--dangerously-bypass-approvals-and-sandbox`. Pi ignores this setting.
|
|
145
|
+
- `quota` — independent native usage reader: `source` is `claude`, `codex`, or `none`, with optional `configDir`, `env`, `unset`. `none` disables quota and accepts no other recognized options. Omitted quota uses a native Claude/Codex profile's coding environment; Pi requires an explicit source.
|
|
146
|
+
|
|
147
|
+
Selection for new sessions, help, `guide code`, and quota: `--profile` → project registry selection → `code.profile` → automatic resolution. Resume inserts its latest recorded named profile before the global selection. Named choices bypass parent detection; a missing name fails rather than falling through. Automatic resolution selects a sole matching profile or the unique true flag among several matches; without either, several matches are ambiguous. No matching profile uses the detected agent's built-ins. Without a parent, zero or several profiles require a named choice, regardless of flags. Several detected kinds always require a named choice. Project selections use the actual working directory, matching linked worktrees through AlignFirst; help/guide/quota need no `.plans` or Git repository. `--profile` is rejected on status and unrelated guide topics.
|
|
148
|
+
|
|
149
|
+
`aligndev code quota [--profile <name>]` needs neither a ticket nor `.plans` and starts no coding session. Explicit quota settings start from the original caller environment, apply only their own `unset`, `env` and source-specific `configDir`, then strip parent-session identities. Coding-profile overrides and Pi credentials are not copied into the quota environment. The same path and validation rules apply. For multiple accounts, set quota `configDir` explicitly; omission deliberately keeps the native CLI's inherited/default configuration. Pair each Pi profile with the intended Codex or Claude account, as in the examples above. Reports name the profile and native source; the limits belong to that CLI's account. AlignDev does not verify that it matches Pi's account or infer it from a model. Native requests time out after 30 seconds and await bounded process cleanup.
|
|
150
|
+
|
|
151
|
+
The child inherits the caller environment, removes `unset`, then applies `env` and `configDir`. Parent-session identities are stripped afterward, and required adapter values win. The same finalized environment reaches discovery, execution and native context lookup. Help, guides and failures identify native storage selected through `configDir`, profile environment overrides, inherited variables or profile removal. They show environment-variable names and origins, never their values. Login must reproduce that effective environment and cwd. No environment values are printed or saved in run metadata.
|
|
152
|
+
|
|
153
|
+
Resume requires the same native agent and, for Pi, the same real directory. A selected account must contain the native conversation; failure never falls back to an old profile or accepts a new conversation. `--model` overrides the recorded user-facing model; otherwise that name is retained and validated under the current profile. A disallowed retained name requires an explicit replacement; a recorded null keeps the native conversation's model. Profile defaults apply only to new sessions. Retained aliases use the selected profile's current mappings, so changing a mapping can change the native target. Session metadata records profile, agent, chosen name, native ID and cwd; historical records with blank or missing profiles read as null. Unless an explicit, project or global named choice replaces null, resume uses detected built-ins, ignoring configured profile counts and flags, and records null in the new run. No or several detected parents still fail. Original records remain unchanged. A deleted recorded name needs an explicit or project replacement; global selection and inference cannot rescue it. Status reads durable metadata even when launch settings are invalid or a profile has been deleted.
|
|
154
|
+
|
|
155
|
+
`code.defaultProfiles` is retired and ignored with a warning. Move needed preferences to matching profiles' `default: true`, omit singleton flags and remove the map. Keep profile names unchanged; see [profile-default migration](https://github.com/paleo/alignfirst/blob/main/skills/alignfirst-setup-guide/references/alignfirst-upgrade.md#convert-aligndev-profile-defaults). Unique-profile inference now selects configured native storage, model, environment and permission settings for new runs that previously used built-ins. Historical null-profile resumes retain their built-in fallback. OpenClaw deployments continue to require an explicit valid `code.profile`.
|
|
156
|
+
|
|
157
|
+
Unknown or obsolete keys at the settings root, `code`, each profile and each quota object are ignored with warnings on stderr. Profile names, environment names and model aliases remain dynamic map keys. Warnings omit values, redact dynamic map names and escape control characters. Recognized invalid values and duplicate defaults still fail. The CLI never rewrites the settings file. Direct `code.agent/defaultModel/models/skipPermissions/unset` settings are retired and ignored; they no longer select or configure a child. Move them manually into a named profile and select it with `code.profile`; see the [upgrade reference](https://github.com/paleo/alignfirst/blob/main/skills/alignfirst-setup-guide/references/alignfirst-upgrade.md#convert-aligndev-launch-settings). Authenticate under the selected native configuration before launching. Never retry against another account after an authentication or missing-conversation failure.
|
|
100
158
|
|
|
101
159
|
## Start as an OpenClaw Bot
|
|
102
160
|
|
|
@@ -105,7 +163,7 @@ AlignDev for OpenClaw runs the assistant as an OpenClaw bot. One deployment is a
|
|
|
105
163
|
```mermaid
|
|
106
164
|
flowchart TD
|
|
107
165
|
U([User]) -->|Slack or Discord| O[OpenClaw]
|
|
108
|
-
O -->|aligndev guide and aligndev code| CA[Claude Code or
|
|
166
|
+
O -->|aligndev guide and aligndev code| CA[Claude Code, Codex or Pi]
|
|
109
167
|
CA -->|AlignFirst protocols| FS[(Managed project)]
|
|
110
168
|
```
|
|
111
169
|
|
|
@@ -115,7 +173,7 @@ Install the setup skill where your agent will assemble the deployment's private
|
|
|
115
173
|
npx -y skills add https://github.com/paleo/alignfirst --global --skill alignfirst-setup-guide
|
|
116
174
|
```
|
|
117
175
|
|
|
118
|
-
Then ask the agent to create an assistant. The skill collects the deployment values, renders one Slack or Discord variant and one Claude Code or
|
|
176
|
+
Then ask the agent to create an assistant. The skill collects the deployment values, renders one Slack or Discord variant and one Claude Code, Codex or Pi variant, and writes the installation, security, operation and recovery runbooks. Each managed project receives the full preparation contract: the `alignfirst context` section in its `AGENTS.md`, an optional work-files repository, docmap, isolated workspaces and a project-specific `DEVELOPERS.md`.
|
|
119
177
|
|
|
120
178
|
## Under the Hood
|
|
121
179
|
|
package/dist/alignfirst-cli.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface AlignfirstResult {
|
|
|
4
4
|
stderr: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function runAlignfirst(command: string[], args: string[], cwd: string, env?: NodeJS.ProcessEnv): AlignfirstResult;
|
|
7
|
+
export declare function forwardSettingsWarnings(stderr: string): string;
|
|
8
|
+
export declare function describeAlignfirst(command: string[], cwd: string, env: NodeJS.ProcessEnv): string;
|
|
7
9
|
export declare function reserveSideTicket(command: string[], cwd: string, env: NodeJS.ProcessEnv): string;
|
|
8
10
|
export declare function openTicket(command: string[], cwd: string, ticket: string, env: NodeJS.ProcessEnv): void;
|
|
9
11
|
export declare function loadCatchup(command: string[], cwd: string, ticket: string, env: NodeJS.ProcessEnv): string;
|
package/dist/alignfirst-cli.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { accessSync, constants, existsSync, statSync } from "node:fs";
|
|
3
|
+
import { delimiter, resolve, sep } from "node:path";
|
|
4
|
+
import { readPackageVersion } from "./package-version.js";
|
|
2
5
|
export function runAlignfirst(command, args, cwd, env = process.env) {
|
|
3
6
|
const result = spawnSync(command[0], [...command.slice(1), ...args], {
|
|
4
7
|
cwd,
|
|
@@ -7,16 +10,74 @@ export function runAlignfirst(command, args, cwd, env = process.env) {
|
|
|
7
10
|
});
|
|
8
11
|
if (result.error && isErrnoException(result.error) && result.error.code === "ENOENT") {
|
|
9
12
|
throw new Error("alignfirst is not installed. Install it globally (`npm install -g alignfirst`), or run " +
|
|
10
|
-
|
|
13
|
+
`aligndev through npx (\`npx -y aligndev\`). ${describeAlignfirst(command, cwd, env)}`);
|
|
11
14
|
}
|
|
12
15
|
if (result.error)
|
|
13
16
|
throw result.error;
|
|
17
|
+
if (result.status === 0)
|
|
18
|
+
forwardSettingsWarnings(result.stderr);
|
|
14
19
|
return {
|
|
15
20
|
status: result.status ?? 1,
|
|
16
21
|
stdout: result.stdout,
|
|
17
22
|
stderr: result.stderr,
|
|
18
23
|
};
|
|
19
24
|
}
|
|
25
|
+
// Forward only recognized settings warnings, leaving other diagnostics to the caller.
|
|
26
|
+
export function forwardSettingsWarnings(stderr) {
|
|
27
|
+
const diagnostics = [];
|
|
28
|
+
for (const line of stderr.split(/\r?\n/)) {
|
|
29
|
+
if (isSettingsWarning(line))
|
|
30
|
+
console.warn(line);
|
|
31
|
+
else
|
|
32
|
+
diagnostics.push(line);
|
|
33
|
+
}
|
|
34
|
+
return diagnostics.join("\n");
|
|
35
|
+
}
|
|
36
|
+
function isSettingsWarning(line) {
|
|
37
|
+
if (/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(line))
|
|
38
|
+
return false;
|
|
39
|
+
return (/^Warning: ignoring unknown (?:\.alignfirst\.json|companion registry) setting /u.test(line) ||
|
|
40
|
+
/^Warning: .+: plans\.folder is deprecated; rename it to plans\.repositoryFolder\. See "Rename the Work-Files Folder Setting" in the setup guide's alignfirst-upgrade reference\.$/u.test(line));
|
|
41
|
+
}
|
|
42
|
+
export function describeAlignfirst(command, cwd, env) {
|
|
43
|
+
const npx = command[0] === "npx";
|
|
44
|
+
const reason = npx
|
|
45
|
+
? "aligndev was launched through npm/npx; npx prefers the project's local alignfirst dependency"
|
|
46
|
+
: "aligndev runs alignfirst from PATH when launched directly";
|
|
47
|
+
const facts = [`\`${command.join(" ")}\` (${reason})`];
|
|
48
|
+
if (!npx)
|
|
49
|
+
facts.push(describeExecutable(command[0], cwd, env));
|
|
50
|
+
const version = spawnSync(command[0], [...command.slice(1), "--version"], {
|
|
51
|
+
cwd,
|
|
52
|
+
env,
|
|
53
|
+
encoding: "utf8",
|
|
54
|
+
timeout: 10_000,
|
|
55
|
+
});
|
|
56
|
+
const line = version.stdout?.split(/\r?\n/, 1)[0]?.trim();
|
|
57
|
+
if (version.status === 0 && line !== undefined && line !== "" && line.length <= 80) {
|
|
58
|
+
facts.push(`version ${line}`);
|
|
59
|
+
}
|
|
60
|
+
const entry = process.argv[1] === undefined ? "" : ` at ${process.argv[1]}`;
|
|
61
|
+
facts.push(`aligndev ${readPackageVersion()}${entry}`);
|
|
62
|
+
return `alignfirst: ${facts.join("; ")}`.replace(/[\p{Cc}\p{Zl}\p{Zp}]/gu, " ");
|
|
63
|
+
}
|
|
64
|
+
function describeExecutable(command, cwd, env) {
|
|
65
|
+
if (command.includes(sep)) {
|
|
66
|
+
return `executable ${command}${existsSync(resolve(cwd, command)) ? "" : " (not found)"}`;
|
|
67
|
+
}
|
|
68
|
+
for (const dir of env.PATH?.split(delimiter) ?? []) {
|
|
69
|
+
const path = resolve(cwd, dir, command);
|
|
70
|
+
try {
|
|
71
|
+
accessSync(path, constants.X_OK);
|
|
72
|
+
if (statSync(path).isFile())
|
|
73
|
+
return `executable ${path}`;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Continue through PATH when an entry is missing or not executable.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return "not found on PATH";
|
|
80
|
+
}
|
|
20
81
|
export function reserveSideTicket(command, cwd, env) {
|
|
21
82
|
const result = runAlignfirst(command, ["ticket", "--side", "--json"], cwd, env);
|
|
22
83
|
if (result.status !== 0) {
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
1
|
import { homedir } from "node:os";
|
|
3
2
|
import { runCode } from "./code/code-cli.js";
|
|
4
|
-
import {
|
|
5
|
-
import { resolveExecutableModel } from "./code/models.js";
|
|
3
|
+
import { createExecutableModelResolver } from "./code/models.js";
|
|
6
4
|
import { readQuota } from "./code/quota.js";
|
|
7
5
|
import { resolveCommandForms } from "./command-form.js";
|
|
8
6
|
import { loadConfig, PLATFORMS } from "./config.js";
|
|
9
7
|
import { errorMessage } from "./errors.js";
|
|
10
8
|
import { runGuide } from "./guide/guide-cli.js";
|
|
9
|
+
import { readPackageVersion } from "./package-version.js";
|
|
11
10
|
import { runProject } from "./project/project-cli.js";
|
|
12
11
|
export async function main(options) {
|
|
13
12
|
const ctx = resolveContext(options);
|
|
@@ -26,11 +25,11 @@ export async function main(options) {
|
|
|
26
25
|
return 1;
|
|
27
26
|
}
|
|
28
27
|
try {
|
|
28
|
+
if (command === "code")
|
|
29
|
+
return await runCode(tokens, () => loadConfig(ctx.home), ctx);
|
|
29
30
|
const config = loadConfig(ctx.home);
|
|
30
31
|
if (command === "project")
|
|
31
32
|
return runProject(tokens, config, ctx);
|
|
32
|
-
if (command === "code")
|
|
33
|
-
return await runCode(tokens, config, ctx);
|
|
34
33
|
return runGuide(tokens, config, ctx);
|
|
35
34
|
}
|
|
36
35
|
catch (error) {
|
|
@@ -57,8 +56,9 @@ ${usage}
|
|
|
57
56
|
Run \`${aligndev} <command> --help\` for the usage of a command.
|
|
58
57
|
|
|
59
58
|
Config (optional): ~/.alignfirst/aligndev.settings.json. "platform" (${PLATFORMS.join(" or ")})
|
|
60
|
-
defaults to codingAgent.
|
|
61
|
-
|
|
59
|
+
defaults to codingAgent. Named code.profiles select child agents and native configuration.
|
|
60
|
+
Use code.profile for a global selection. A sole matching profile is inferred; with several,
|
|
61
|
+
set one profile's default: true per agent. Without a parent, only a sole total profile is inferred.
|
|
62
62
|
`;
|
|
63
63
|
}
|
|
64
64
|
// Each row is a command, optionally followed by its description in an aligned column.
|
|
@@ -79,13 +79,7 @@ function resolveContext(options) {
|
|
|
79
79
|
stderr: options?.stderr ?? process.stderr,
|
|
80
80
|
forms,
|
|
81
81
|
alignfirstCommand: options?.alignfirstCommand ?? forms.alignfirst.split(" "),
|
|
82
|
-
modelResolver: options?.modelResolver ??
|
|
82
|
+
modelResolver: options?.modelResolver ?? createExecutableModelResolver(),
|
|
83
83
|
quotaReader: options?.quotaReader ?? readQuota,
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
function readPackageVersion() {
|
|
87
|
-
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
88
|
-
if (pkg.version === undefined)
|
|
89
|
-
throw new Error("aligndev: package.json is missing 'version'");
|
|
90
|
-
return pkg.version;
|
|
91
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentAdapter, AgentProtocolState, RunConfig } from "./run-agent.js";
|
|
2
2
|
export declare function createClaudeAdapter(): AgentAdapter;
|
|
3
3
|
export declare function buildClaudeArgs(config: RunConfig): string[];
|
|
4
|
-
export declare function createClaudeState(): AgentProtocolState;
|
|
4
|
+
export declare function createClaudeState(config?: RunConfig): AgentProtocolState;
|
|
5
5
|
export declare function interpretClaudeLine(line: string, state: AgentProtocolState): string | undefined;
|
|
6
6
|
export declare function assessClaudeState(state: AgentProtocolState): {
|
|
7
7
|
succeeded: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCompacted } from "./run-agent.js";
|
|
1
|
+
import { captureNativeSession, isCompacted } from "./run-agent.js";
|
|
2
2
|
// After the agent's turn, `claude -p` waits for its background work, but stops it after 10 minutes
|
|
3
3
|
// of idle waiting by default. `0` waits until the work ends.
|
|
4
4
|
const CLAUDE_ENV = { CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS: "0" };
|
|
@@ -31,8 +31,10 @@ export function buildClaudeArgs(config) {
|
|
|
31
31
|
args.push("--model", config.executableModel);
|
|
32
32
|
return args;
|
|
33
33
|
}
|
|
34
|
-
export function createClaudeState() {
|
|
34
|
+
export function createClaudeState(config) {
|
|
35
35
|
return {
|
|
36
|
+
expectedSessionId: config?.resume,
|
|
37
|
+
earlierResults: [],
|
|
36
38
|
protocolComplete: false,
|
|
37
39
|
protocolFailed: false,
|
|
38
40
|
authEvidence: false,
|
|
@@ -66,23 +68,34 @@ export function interpretClaudeLine(line, state) {
|
|
|
66
68
|
}
|
|
67
69
|
export function assessClaudeState(state) {
|
|
68
70
|
return {
|
|
69
|
-
succeeded: state.
|
|
71
|
+
succeeded: state.sessionId !== undefined &&
|
|
72
|
+
state.identityFailure === undefined &&
|
|
73
|
+
state.protocolComplete &&
|
|
74
|
+
!state.protocolFailed &&
|
|
75
|
+
state.result !== undefined,
|
|
70
76
|
sessionId: state.sessionId,
|
|
71
77
|
result: state.result,
|
|
72
|
-
error: state.
|
|
78
|
+
error: state.identityFailure ??
|
|
79
|
+
state.failure ??
|
|
80
|
+
(state.sessionId === undefined &&
|
|
81
|
+
(state.protocolComplete || state.expectedSessionId !== undefined)
|
|
82
|
+
? "Claude reported no native session identity in the selected native configuration."
|
|
83
|
+
: undefined),
|
|
73
84
|
authEvidence: state.authEvidence,
|
|
74
85
|
contextTokens: state.contextTokens,
|
|
75
86
|
contextCompacted: isCompacted(state),
|
|
76
87
|
};
|
|
77
88
|
}
|
|
78
|
-
// Background
|
|
79
|
-
// with nothing to report closes with an empty one, which must not erase the previous result.
|
|
89
|
+
// Background turns each close with a result. Keep superseded responses; empty turns erase none.
|
|
80
90
|
function captureResult(result, state) {
|
|
81
91
|
if (state.protocolFailed)
|
|
82
92
|
state.failure = result;
|
|
83
|
-
if (result === ""
|
|
93
|
+
if (result === "" || result === undefined)
|
|
84
94
|
return;
|
|
95
|
+
if (state.result !== undefined)
|
|
96
|
+
state.earlierResults.push(state.result);
|
|
85
97
|
state.result = result;
|
|
98
|
+
state.resultComplete = !state.protocolFailed;
|
|
86
99
|
}
|
|
87
100
|
// What the newest assistant response holds in the context window. Claude reports cache reads and
|
|
88
101
|
// writes beside `input_tokens`, so the occupancy is their sum plus the response itself. A subagent
|
|
@@ -112,9 +125,9 @@ function parseEventLine(line) {
|
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
function captureSessionId(event, state) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
if (event.session_id !== undefined || (event.type === "system" && event.subtype === "init")) {
|
|
129
|
+
captureNativeSession(state, event.session_id, "Claude");
|
|
130
|
+
}
|
|
118
131
|
}
|
|
119
132
|
function renderMessageContent(event) {
|
|
120
133
|
const message = event.message;
|
|
@@ -152,7 +165,8 @@ function renderToolResult(content) {
|
|
|
152
165
|
}
|
|
153
166
|
function claudeAuthenticationMessage(detail) {
|
|
154
167
|
const base = "Coding agent not authenticated (authentication_failed): the host session is missing, " +
|
|
155
|
-
"expired, or rejected. An administrator must re-login
|
|
168
|
+
"expired, or rejected. An administrator must re-login with the same effective environment and cwd as the child " +
|
|
169
|
+
"(apply profile unset/env/configDir, including HOME, PATH and credential routing; run `claude`, then " +
|
|
156
170
|
"`/login`) before `aligndev code` can run again.";
|
|
157
171
|
const reason = detail?.trim();
|
|
158
172
|
return reason === undefined || reason === "" ? base : `${base}\n\n${reason}`;
|
package/dist/code/code-cli.d.ts
CHANGED
|
@@ -19,12 +19,15 @@ export interface CodeContext {
|
|
|
19
19
|
}
|
|
20
20
|
export type CodeCommand = {
|
|
21
21
|
kind: "help";
|
|
22
|
+
profile?: string;
|
|
23
|
+
status?: boolean;
|
|
22
24
|
} | {
|
|
23
25
|
kind: "status";
|
|
24
26
|
target: StatusTarget;
|
|
25
27
|
includeResult: boolean;
|
|
26
28
|
} | {
|
|
27
29
|
kind: "quota";
|
|
30
|
+
profile?: string;
|
|
28
31
|
} | {
|
|
29
32
|
kind: "session";
|
|
30
33
|
args: SessionArgs;
|
|
@@ -42,6 +45,7 @@ export type StatusTarget = {
|
|
|
42
45
|
meta: string;
|
|
43
46
|
};
|
|
44
47
|
export interface SessionArgs {
|
|
48
|
+
profile?: string;
|
|
45
49
|
resume?: string;
|
|
46
50
|
ticket?: string;
|
|
47
51
|
noTicket: boolean;
|
|
@@ -53,10 +57,10 @@ export interface SessionArgs {
|
|
|
53
57
|
meta?: string;
|
|
54
58
|
quiet?: boolean;
|
|
55
59
|
}
|
|
56
|
-
export declare function runCode(tokens: string[],
|
|
60
|
+
export declare function runCode(tokens: string[], loadSettings: () => LoadedConfig, ctx: CodeContext): Promise<number>;
|
|
57
61
|
export declare function parseCodeArgs(tokens: string[], aligndev: string): CodeCommand;
|
|
58
62
|
export declare function validateSessionArgs(args: SessionArgs, models: readonly string[] | undefined): string | undefined;
|
|
59
|
-
export declare function checkLaunchGuards(args: SessionArgs, agent: CodingAgent, realCwd: string, ticket: string | undefined, records: SessionRecord[]): string | undefined;
|
|
63
|
+
export declare function checkLaunchGuards(args: SessionArgs, agent: CodingAgent, realCwd: string, ticket: string | undefined, records: SessionRecord[], previous?: SessionRecord): string | undefined;
|
|
60
64
|
export declare function resolveTicket(args: SessionArgs, records: SessionRecord[]): string | undefined;
|
|
61
65
|
export interface RunInput {
|
|
62
66
|
args: SessionArgs;
|
|
@@ -65,7 +69,6 @@ export interface RunInput {
|
|
|
65
69
|
ticket: string | undefined;
|
|
66
70
|
cwd: string;
|
|
67
71
|
sessionFilePath: string;
|
|
68
|
-
env: NodeJS.ProcessEnv;
|
|
69
72
|
executableModel: string | undefined;
|
|
70
73
|
catchupContent?: string;
|
|
71
74
|
contextContent?: string;
|