@anhlp/alp-core 0.0.0-beta.1 → 0.10.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/dist/hook-run.d.ts +1 -1
- package/dist/hook-run.js +9 -3
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -10
- package/dist/library-edit.js +1 -11
- package/dist/library.js +2 -4
- package/dist/permissions.js +6 -9
- package/dist/providers.d.ts +0 -12
- package/dist/providers.js +0 -18
- package/dist/task-rows.d.ts +0 -1
- package/dist/task-rows.js +0 -1
- package/dist/tasks.d.ts +1 -2
- package/dist/tasks.js +10 -25
- package/dist/trust.js +2 -3
- package/dist/user-settings.js +5 -6
- package/dist/verify.js +15 -3
- package/package.json +6 -53
- package/src/hook-run.js +4 -4
- package/src/index.js +0 -5
- package/src/library-edit.js +1 -14
- package/src/library.js +2 -4
- package/src/permissions.js +6 -9
- package/src/providers.js +0 -28
- package/src/task-rows.js +1 -1
- package/src/tasks.d.ts +1 -2
- package/src/tasks.js +9 -28
- package/src/trust.js +2 -3
- package/src/user-settings.js +5 -6
- package/src/verify.js +6 -3
- package/LICENSE +0 -202
- package/NOTICE +0 -7
- package/dist/atomic.d.ts +0 -2
- package/dist/atomic.js +0 -28
- package/dist/backup.d.ts +0 -27
- package/dist/backup.js +0 -582
- package/dist/log.d.ts +0 -37
- package/dist/log.js +0 -156
- package/dist/migrations.d.ts +0 -9
- package/dist/migrations.js +0 -95
- package/dist/safe-path.d.ts +0 -2
- package/dist/safe-path.js +0 -24
- package/dist/shell.d.ts +0 -16
- package/dist/shell.js +0 -22
- package/dist/state-schema.d.ts +0 -9
- package/dist/state-schema.js +0 -54
- package/src/atomic.d.ts +0 -2
- package/src/atomic.js +0 -28
- package/src/backup.d.ts +0 -27
- package/src/backup.js +0 -570
- package/src/log.d.ts +0 -37
- package/src/log.js +0 -177
- package/src/migrations.d.ts +0 -9
- package/src/migrations.js +0 -111
- package/src/safe-path.js +0 -20
- package/src/shell.js +0 -28
- package/src/state-schema.d.ts +0 -9
- package/src/state-schema.js +0 -60
package/src/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// Stable module namespaces avoid collisions between domain exports.
|
|
2
2
|
export * as adapter from './adapter.js';
|
|
3
|
-
export * as atomic from './atomic.js';
|
|
4
|
-
export * as backup from './backup.js';
|
|
5
3
|
export * as beads from './beads.js';
|
|
6
4
|
export * as delegation from './delegation.js';
|
|
7
5
|
export * as errors from './errors.js';
|
|
@@ -11,15 +9,12 @@ export * as hooks from './hooks.js';
|
|
|
11
9
|
export * as init from './init.js';
|
|
12
10
|
export * as library_edit from './library-edit.js';
|
|
13
11
|
export * as library from './library.js';
|
|
14
|
-
export * as log from './log.js';
|
|
15
|
-
export * as migrations from './migrations.js';
|
|
16
12
|
export * as models from './models.js';
|
|
17
13
|
export * as permissions from './permissions.js';
|
|
18
14
|
export * as profiles from './profiles.js';
|
|
19
15
|
export * as promptsafe from './promptsafe.js';
|
|
20
16
|
export * as providers from './providers.js';
|
|
21
17
|
export * as resolver from './resolver.js';
|
|
22
|
-
export * as state_schema from './state-schema.js';
|
|
23
18
|
export * as task_rows from './task-rows.js';
|
|
24
19
|
export * as tasks from './tasks.js';
|
|
25
20
|
export * as teams from './teams.js';
|
package/src/library-edit.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { moveFile } from './atomic.js';
|
|
5
4
|
import { AlpError } from './errors.js';
|
|
6
|
-
import { assertNoSymlinks } from './safe-path.js';
|
|
7
5
|
import { agentSources, builtinText, jsonObject, libraryEntries, optionalText } from './resolver.js';
|
|
8
6
|
import { teamSources, validateTeam } from './teams.js';
|
|
9
7
|
import { normalizeMcp, validateAgentConfig, validateHook } from './validation.js';
|
|
@@ -60,17 +58,8 @@ function base(scope, { root, library }, kind) {
|
|
|
60
58
|
}
|
|
61
59
|
const revisionOf = content => content === undefined ? null : createHash('sha256').update(JSON.stringify(content)).digest('hex').slice(0, 16);
|
|
62
60
|
|
|
63
|
-
/** Reject repository-controlled links before any entry read or mutation. This is
|
|
64
|
-
* a preflight for static repository input, not a sandbox against same-user races. */
|
|
65
|
-
async function safeEntryPaths(directory, kind, name) {
|
|
66
|
-
for (const [file] of FILES[kind](name)) {
|
|
67
|
-
await assertNoSymlinks(directory, path.join(kind, file));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
61
|
/** An entry's content as one layer holds it, or undefined when that layer has none. */
|
|
72
62
|
async function readLayer(kind, name, directory) {
|
|
73
|
-
await safeEntryPaths(directory, kind, name);
|
|
74
63
|
const content = {};
|
|
75
64
|
let found = false;
|
|
76
65
|
for (const [file, key, type] of FILES[kind](name)) {
|
|
@@ -264,7 +253,7 @@ async function writeAtomic(file, text) {
|
|
|
264
253
|
await mkdir(path.dirname(file), { recursive: true });
|
|
265
254
|
const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
|
|
266
255
|
await writeFile(temporary, text);
|
|
267
|
-
await
|
|
256
|
+
await rename(temporary, file);
|
|
268
257
|
}
|
|
269
258
|
|
|
270
259
|
const exists = target => stat(target).then(() => true, () => false);
|
|
@@ -277,13 +266,11 @@ const exists = target => stat(target).then(() => true, () => false);
|
|
|
277
266
|
export async function saveEntry(kind, name, content, { scope, root, library, templates, revision } = {}) {
|
|
278
267
|
kindOf(kind); nameOf(name);
|
|
279
268
|
const directory = base(scope, { root, library }, kind);
|
|
280
|
-
await safeEntryPaths(directory, kind, name);
|
|
281
269
|
await check(kind, name, content, { scope, root, library, templates });
|
|
282
270
|
const current = await readLayer(kind, name, directory);
|
|
283
271
|
if (revision !== undefined && revision !== revisionOf(current)) {
|
|
284
272
|
fail('REVISION_CONFLICT', current === undefined ? `${kind} '${name}' was removed from the ${scope} since you opened it` : revision === null ? `${kind} '${name}' already exists in the ${scope}` : `${kind} '${name}' changed in the ${scope} since you opened it; reload it and apply your change again`);
|
|
285
273
|
}
|
|
286
|
-
if (scope === 'library') await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
287
274
|
for (const [file, key, type] of FILES[kind](name)) {
|
|
288
275
|
const target = path.join(directory, kind, file);
|
|
289
276
|
const value = content[key];
|
package/src/library.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { shippedTemplateRoot } from './template-path.js';
|
|
2
|
-
import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { moveFile } from './atomic.js';
|
|
2
|
+
import { mkdir, readFile, readdir, rename, writeFile } from 'node:fs/promises';
|
|
4
3
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
4
|
import os from 'node:os';
|
|
6
5
|
import path from 'node:path';
|
|
@@ -50,7 +49,6 @@ async function shippedFiles({ templateRoot, templates }) {
|
|
|
50
49
|
*/
|
|
51
50
|
export async function seedLibrary(home, options = {}) {
|
|
52
51
|
const shipped = await shippedFiles(options);
|
|
53
|
-
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
54
52
|
const manifestPath = path.join(home, MANIFEST);
|
|
55
53
|
const manifestText = await optional(manifestPath);
|
|
56
54
|
const manifest = manifestText ? JSON.parse(manifestText) : { files: {} };
|
|
@@ -78,7 +76,7 @@ export async function seedLibrary(home, options = {}) {
|
|
|
78
76
|
await mkdir(home, { recursive: true });
|
|
79
77
|
const temporary = `${manifestPath}.${randomUUID().slice(0, 8)}.tmp`;
|
|
80
78
|
await writeFile(temporary, JSON.stringify(manifest, null, 2) + '\n');
|
|
81
|
-
await
|
|
79
|
+
await rename(temporary, manifestPath);
|
|
82
80
|
}
|
|
83
81
|
return { created, updated };
|
|
84
82
|
}
|
package/src/permissions.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { moveFile } from './atomic.js';
|
|
3
|
+
import { readFile, rename, writeFile } from 'node:fs/promises';
|
|
5
4
|
import { AlpError } from './errors.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -33,8 +32,6 @@ const RULE = /^([A-Za-z][\w-]*)(?:\((.*)\))?$/s;
|
|
|
33
32
|
/** Tools a rule may name; a misspelt one would silently match nothing. MCP tools are mcp__<server>__<tool>. */
|
|
34
33
|
export const TOOLS = ['Bash', 'Read', 'Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'Glob', 'Grep', 'WebFetch', 'WebSearch', 'Skill'];
|
|
35
34
|
|
|
36
|
-
const own = (value, key) => Object.hasOwn(value, key) ? value[key] : undefined;
|
|
37
|
-
const setOwn = (value, key, entry) => Object.defineProperty(value, key, { value: entry, enumerable: true, writable: true, configurable: true });
|
|
38
35
|
const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
39
36
|
const fail = (source, message) => { throw new AlpError('INVALID_SETTINGS', `${source}: ${message}`); };
|
|
40
37
|
|
|
@@ -73,7 +70,7 @@ export function validatePermissions(value, source) {
|
|
|
73
70
|
for (const rule of list) parseRule(rule, `${source}: ${where}.${kind}`);
|
|
74
71
|
rules[kind] = list.map(rule => rule.trim());
|
|
75
72
|
}
|
|
76
|
-
|
|
73
|
+
profiles[name] = { ...(profile.base ? { base: profile.base } : {}), ...(profile.beyondMode ? { beyondMode: profile.beyondMode } : {}), ...(profile.workdir ? { workdir: profile.workdir } : {}), ...rules };
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
const agents = {};
|
|
@@ -81,7 +78,7 @@ export function validatePermissions(value, source) {
|
|
|
81
78
|
if (!object(value.agents)) fail(source, 'permissions.agents must be an object');
|
|
82
79
|
for (const [agent, profile] of Object.entries(value.agents)) {
|
|
83
80
|
if (typeof profile !== 'string' || !NAME.test(profile)) fail(source, `permissions.agents.${agent} must name a profile`);
|
|
84
|
-
|
|
81
|
+
agents[agent] = profile;
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
84
|
return { profiles, agents };
|
|
@@ -106,10 +103,10 @@ async function settingsPermissions(file) {
|
|
|
106
103
|
export async function profileFor(projectRoot, home, agent) {
|
|
107
104
|
const project = await settingsPermissions(path.join(projectRoot, '.alp', 'settings.json'));
|
|
108
105
|
const user = home ? await settingsPermissions(path.join(home, 'settings.json')) : { profiles: {}, agents: {} };
|
|
109
|
-
const name =
|
|
106
|
+
const name = project.agents[agent] ?? user.agents[agent];
|
|
110
107
|
const advisor = ADVISORS.includes(agent);
|
|
111
108
|
if (!name) return advisor ? { name: 'read-only', base: 'read-only', allow: [], ask: [], deny: [], beyondMode: 'refuse' } : null;
|
|
112
|
-
const defined = [
|
|
109
|
+
const defined = [project.profiles[name], user.profiles[name]].filter(Boolean);
|
|
113
110
|
if (!defined.length && !BASES.includes(name)) {
|
|
114
111
|
throw new AlpError('INVALID_SETTINGS', `permissions.agents.${agent} names profile '${name}', which no settings file defines`);
|
|
115
112
|
}
|
|
@@ -143,7 +140,7 @@ export async function addAllowRule(projectRoot, home, profileName, rule) {
|
|
|
143
140
|
validatePermissions(settings.permissions, file);
|
|
144
141
|
const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
|
|
145
142
|
await writeFile(temporary, `${JSON.stringify(settings, null, 2)}\n`);
|
|
146
|
-
await
|
|
143
|
+
await rename(temporary, file);
|
|
147
144
|
return file;
|
|
148
145
|
}
|
|
149
146
|
throw new AlpError('INVALID_SETTINGS', `No settings file defines profile ${profileName}`);
|
package/src/providers.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
1
|
import { readdir, readFile } from 'node:fs/promises';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { AlpError } from './errors.js';
|
|
@@ -93,30 +92,3 @@ export function acpModel(model) {
|
|
|
93
92
|
const slash = model.indexOf('/');
|
|
94
93
|
return slash < 0 ? { provider: model, model: undefined } : { provider: model.slice(0, slash), model: model.slice(slash + 1) || undefined };
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* How to start a command without a shell. On Windows a bare name installed with npm is a
|
|
99
|
-
* `<name>.cmd` shim, which spawn refuses to run without one; its target runs instead: the
|
|
100
|
-
* native executable it calls, or the Node script, under this Node. A bare name with an .exe or
|
|
101
|
-
* .com on PATH, any other command, and every command elsewhere are returned as they are.
|
|
102
|
-
* @param {string} command @param {string[]} [args] @param {Record<string, string | undefined>} [env]
|
|
103
|
-
* @returns {{ command: string, args: string[] }}
|
|
104
|
-
*/
|
|
105
|
-
export function launchCommand(command, args = [], env = process.env) {
|
|
106
|
-
if (process.platform !== 'win32' || /[\\/]/.test(command) || path.extname(command)) return { command, args };
|
|
107
|
-
const key = Object.keys(env).find(name => name.toUpperCase() === 'PATH');
|
|
108
|
-
for (const directory of (key ? env[key] ?? '' : '').split(';').filter(Boolean)) {
|
|
109
|
-
if (['.exe', '.com'].some(extension => existsSync(path.join(directory, command + extension)))) break;
|
|
110
|
-
const shim = path.join(directory, `${command}.cmd`);
|
|
111
|
-
if (!existsSync(shim)) continue;
|
|
112
|
-
// npm's cmd-shim ends with `"%dp0%\<target>" %*`, or `"%_prog%" [node flags] "%dp0%\<script>" %*`
|
|
113
|
-
// for a Node script. Anything else (a hand-written batch file) stays refused by spawn, as before.
|
|
114
|
-
const text = readFileSync(shim, 'utf8');
|
|
115
|
-
const script = /"%_prog%"((?:\s+[^\s"]+)*)\s+"%~?dp0%\\?([^"]+)"\s+%\*/i.exec(text);
|
|
116
|
-
if (script) return { command: process.execPath, args: [...script[1].split(/\s+/).filter(Boolean), path.join(directory, script[2]), ...args] };
|
|
117
|
-
const native = /^\s*"%~?dp0%\\?([^"]+\.(?:exe|com))"\s+%\*/im.exec(text);
|
|
118
|
-
if (native) return { command: path.join(directory, native[1]), args };
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
return { command, args };
|
|
122
|
-
}
|
package/src/task-rows.js
CHANGED
|
@@ -23,7 +23,7 @@ export async function taskRows(projectRoot) {
|
|
|
23
23
|
const approvals = task.status === 'closed' ? [] : task.gates.filter(gate => gate.kind === 'human' && !gate.resolved).map(gate => ({ gate: gate.id, note: gate.note ?? '' }));
|
|
24
24
|
const waits = task.status === 'closed' ? [] : gatesOf(task, tasks);
|
|
25
25
|
return {
|
|
26
|
-
id: task.id, title: task.title, type: task.type, priority: task.priority, status: task.status,
|
|
26
|
+
id: task.id, title: task.title, type: task.type, priority: task.priority, status: task.status,
|
|
27
27
|
...(task.parent ? { parent: task.parent } : {}),
|
|
28
28
|
...(task.assignee ? { assignee: task.assignee.agent } : {}),
|
|
29
29
|
ready: ready.has(task.id),
|
package/src/tasks.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export function gateOpen(gate: TaskGate, now?: number): boolean;
|
|
|
108
108
|
export function describeGate(gate: TaskGate): string;
|
|
109
109
|
export function gatesOf(task: Task, tasks: Task[]): string[];
|
|
110
110
|
export function addGate(projectRoot: string, id: string, gate: { kind: GateKind; note?: string; until?: string; ref?: string | number }, by: string): Promise<Task>;
|
|
111
|
-
export function resolveGate(projectRoot: string, id: string, gateId: string, resolve: { by: string; note?: string; remove?: boolean
|
|
111
|
+
export function resolveGate(projectRoot: string, id: string, gateId: string, resolve: { by: string; note?: string; remove?: boolean }): Promise<Task>;
|
|
112
112
|
export function checkGates(projectRoot: string, gh: (args: string[], options: { cwd: string }) => Promise<string>): Promise<{ cleared: Array<{ task: string; gate: string; detail: string }>; pending: Array<{ task: string; gate: string; detail: string }>; errors: Array<{ task: string; gate: string; error: string }> }>;
|
|
113
113
|
export function compactTasks(projectRoot: string, options: { days?: number; dryRun?: boolean }, by: string): Promise<Array<{ id: string; before: number; after: number }>>;
|
|
114
114
|
export type TaskBatch = {
|
|
@@ -125,4 +125,3 @@ export type TaskVerification = { at: string; by: string; passed: boolean; where?
|
|
|
125
125
|
export type EpicReport = { id: string; title: string; status: TaskStatus; tasks: number; closed: number; durationMs: number; reworked: number; verification: { passed: number; failed: number; skipped: number; none: number }; unverified: string[]; lines: string[]; text: string };
|
|
126
126
|
export function epicReport(id: string, tasks: Task[]): EpicReport;
|
|
127
127
|
export function landedParents(tasks: Task[]): Array<{ task: Task; children: number }>;
|
|
128
|
-
export function withTaskLock<T>(projectRoot: string, work: () => Promise<T>): Promise<T>;
|
package/src/tasks.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { mkdir, readFile, readdir, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { moveFile } from './atomic.js';
|
|
1
|
+
import { mkdir, readFile, readdir, rename, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
3
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
4
3
|
import path from 'node:path';
|
|
5
4
|
import { AlpError } from './errors.js';
|
|
6
|
-
import { assertNoSymlinks } from './safe-path.js';
|
|
7
5
|
import { describeVerification } from './verify.js';
|
|
8
6
|
|
|
9
7
|
/**
|
|
@@ -14,8 +12,7 @@ import { describeVerification } from './verify.js';
|
|
|
14
12
|
* module: it holds a lock directory while it reads, checks and writes a task.
|
|
15
13
|
*/
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
export const TASKS_DIR = '.alp/tasks';
|
|
15
|
+
export const TASKS_DIR = path.join('.alp', 'tasks');
|
|
19
16
|
export const TASK_TYPES = ['task', 'bug', 'feature', 'chore', 'epic'];
|
|
20
17
|
export const TASK_STATUSES = ['open', 'in_progress', 'review', 'closed'];
|
|
21
18
|
export const CLOSE_REASONS = ['done', 'wontfix', 'duplicate', 'superseded'];
|
|
@@ -41,23 +38,12 @@ const taskFile = (projectRoot, id) => path.join(tasksDir(projectRoot), `${id}.js
|
|
|
41
38
|
const now = () => new Date().toISOString();
|
|
42
39
|
const fail = (code, message) => { throw new AlpError(code, message); };
|
|
43
40
|
|
|
44
|
-
/**
|
|
45
|
-
async function taskNames(projectRoot) {
|
|
46
|
-
const scope = path.join(path.resolve(projectRoot), '.alp');
|
|
47
|
-
await assertNoSymlinks(scope, 'tasks');
|
|
48
|
-
let names;
|
|
49
|
-
try { names = await readdir(tasksDir(projectRoot)); }
|
|
50
|
-
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
51
|
-
for (const name of [...names.filter(name => name.endsWith('.json')), LOCK, '.gitignore']) {
|
|
52
|
-
await assertNoSymlinks(scope, path.join('tasks', name));
|
|
53
|
-
}
|
|
54
|
-
return names;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Reads every task. Invalid JSON is reported and skipped; unsafe paths are fatal. */
|
|
41
|
+
/** Reads every task. A file that does not parse is reported and skipped, never fatal. */
|
|
58
42
|
export async function loadTasks(projectRoot) {
|
|
59
43
|
const dir = tasksDir(projectRoot);
|
|
60
|
-
|
|
44
|
+
let names;
|
|
45
|
+
try { names = await readdir(dir); }
|
|
46
|
+
catch (error) { if (error.code === 'ENOENT') return { tasks: [], errors: [] }; throw error; }
|
|
61
47
|
const tasks = [];
|
|
62
48
|
const errors = [];
|
|
63
49
|
for (const name of names.filter(name => name.endsWith('.json')).sort()) {
|
|
@@ -246,7 +232,6 @@ async function locked(projectRoot, work) {
|
|
|
246
232
|
const dir = tasksDir(projectRoot);
|
|
247
233
|
const previous = queues.get(dir) ?? Promise.resolve();
|
|
248
234
|
const run = previous.catch(() => {}).then(async () => {
|
|
249
|
-
await taskNames(projectRoot);
|
|
250
235
|
await prepare(dir);
|
|
251
236
|
const lock = path.join(dir, LOCK);
|
|
252
237
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
@@ -267,9 +252,6 @@ async function locked(projectRoot, work) {
|
|
|
267
252
|
return run;
|
|
268
253
|
}
|
|
269
254
|
|
|
270
|
-
/** Runs `work` holding the project's task lock, as every task writer does; backups and restores use it (ALPD §68). */
|
|
271
|
-
export const withTaskLock = (projectRoot, work) => locked(projectRoot, work);
|
|
272
|
-
|
|
273
255
|
/** Creates the directory and its .gitignore on first use, so tasks are ready to commit. */
|
|
274
256
|
async function prepare(dir) {
|
|
275
257
|
await mkdir(dir, { recursive: true });
|
|
@@ -278,10 +260,9 @@ async function prepare(dir) {
|
|
|
278
260
|
|
|
279
261
|
async function save(projectRoot, task) {
|
|
280
262
|
const file = taskFile(projectRoot, task.id);
|
|
281
|
-
await assertNoSymlinks(path.join(path.resolve(projectRoot), ".alp"), path.join("tasks", `${task.id}.json`));
|
|
282
263
|
const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
|
|
283
264
|
await writeFile(temporary, JSON.stringify(task, null, 2) + '\n');
|
|
284
|
-
await
|
|
265
|
+
await rename(temporary, file);
|
|
285
266
|
return task;
|
|
286
267
|
}
|
|
287
268
|
|
|
@@ -709,7 +690,7 @@ export function addGate(projectRoot, id, { kind, note, until, ref } = {}, by) {
|
|
|
709
690
|
}
|
|
710
691
|
|
|
711
692
|
/** Clears a gate by hand, or removes it with `remove`. Only the user clears a human gate; the caller enforces who `by` is. */
|
|
712
|
-
export function resolveGate(projectRoot, id, gateId, { by, note, remove = false
|
|
693
|
+
export function resolveGate(projectRoot, id, gateId, { by, note, remove = false } = {}) {
|
|
713
694
|
return mutate(projectRoot, id, task => {
|
|
714
695
|
const gate = (task.gates ?? []).find(entry => entry.id === gateId) ?? fail('INVALID_TASK', `${id} has no gate ${gateId}`);
|
|
715
696
|
if (remove) {
|
|
@@ -729,7 +710,7 @@ export function resolveGate(projectRoot, id, gateId, { by, note, remove = false,
|
|
|
729
710
|
task.closed = { at: now(), by, reason: 'done', summary };
|
|
730
711
|
addLog(task, by, 'closed', { reason: 'done', summary });
|
|
731
712
|
}
|
|
732
|
-
}
|
|
713
|
+
});
|
|
733
714
|
}
|
|
734
715
|
|
|
735
716
|
/**
|
package/src/trust.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { mkdir, readFile, realpath, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { moveFile } from './atomic.js';
|
|
1
|
+
import { mkdir, readFile, realpath, rename, writeFile } from 'node:fs/promises';
|
|
3
2
|
import { randomUUID } from 'node:crypto';
|
|
4
3
|
import path from 'node:path';
|
|
5
4
|
|
|
@@ -28,7 +27,7 @@ async function store(home, value) {
|
|
|
28
27
|
await mkdir(path.dirname(file(home)), { recursive: true });
|
|
29
28
|
const temporary = `${file(home)}.${randomUUID().slice(0, 8)}.tmp`;
|
|
30
29
|
await writeFile(temporary, JSON.stringify(value, null, 2) + '\n');
|
|
31
|
-
await
|
|
30
|
+
await rename(temporary, file(home));
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/** Whether the user trusts this project's hooks. */
|
package/src/user-settings.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { moveFile } from './atomic.js';
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
2
|
import { randomUUID } from 'node:crypto';
|
|
4
3
|
import path from 'node:path';
|
|
5
4
|
import { AlpError } from './errors.js';
|
|
@@ -52,10 +51,10 @@ export async function setLanguage(home, language) {
|
|
|
52
51
|
const next = { ...settings };
|
|
53
52
|
if (language === null) delete next.language; else next.language = language.trim();
|
|
54
53
|
validateUserSettings(next, file);
|
|
55
|
-
await mkdir(home, { recursive: true
|
|
54
|
+
await mkdir(home, { recursive: true });
|
|
56
55
|
const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
|
|
57
56
|
await writeFile(temporary, JSON.stringify(next, null, 2) + '\n');
|
|
58
|
-
await
|
|
57
|
+
await rename(temporary, file);
|
|
59
58
|
return languageSetting(home);
|
|
60
59
|
}
|
|
61
60
|
|
|
@@ -68,9 +67,9 @@ export async function setWebRelay(home, patch) {
|
|
|
68
67
|
const { file, settings } = await readSettings(home);
|
|
69
68
|
const next = { ...settings, web: { ...settings.web, relay: { ...settings.web?.relay, ...patch } } };
|
|
70
69
|
validateUserSettings(next, file);
|
|
71
|
-
await mkdir(home, { recursive: true
|
|
70
|
+
await mkdir(home, { recursive: true });
|
|
72
71
|
const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
|
|
73
72
|
await writeFile(temporary, JSON.stringify(next, null, 2) + '\n');
|
|
74
|
-
await
|
|
73
|
+
await rename(temporary, file);
|
|
75
74
|
return next.web.relay;
|
|
76
75
|
}
|
package/src/verify.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import { readFile } from 'node:fs/promises';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { AlpError } from './errors.js';
|
|
4
|
-
import { signalShell, spawnShell } from './shell.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The project's verification gate (plans/reference/ALPD.md §28): commands from
|
|
@@ -59,11 +59,14 @@ export async function verifyConfig(projectRoot) {
|
|
|
59
59
|
function runCommand(command, cwd, { timeoutMs, idleMs }, env) {
|
|
60
60
|
return new Promise(resolve => {
|
|
61
61
|
const started = Date.now();
|
|
62
|
-
const
|
|
62
|
+
const windows = process.platform === 'win32';
|
|
63
|
+
const child = spawn(windows ? process.env.ComSpec ?? 'cmd.exe' : '/bin/sh', windows ? ['/d', '/s', '/c', command] : ['-c', command], {
|
|
64
|
+
cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: !windows, windowsHide: true,
|
|
65
|
+
});
|
|
63
66
|
let output = '';
|
|
64
67
|
let stopped;
|
|
65
68
|
let idle;
|
|
66
|
-
const signal = name =>
|
|
69
|
+
const signal = name => { try { windows ? child.kill() : process.kill(-child.pid, name); } catch {} };
|
|
67
70
|
const stop = reason => {
|
|
68
71
|
if (stopped) return;
|
|
69
72
|
stopped = reason;
|
package/LICENSE
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Apache License
|
|
3
|
-
Version 2.0, January 2004
|
|
4
|
-
http://www.apache.org/licenses/
|
|
5
|
-
|
|
6
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
-
|
|
8
|
-
1. Definitions.
|
|
9
|
-
|
|
10
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
-
|
|
13
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
-
the copyright owner that is granting the License.
|
|
15
|
-
|
|
16
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
-
other entities that control, are controlled by, or are under common
|
|
18
|
-
control with that entity. For the purposes of this definition,
|
|
19
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
-
direction or management of such entity, whether by contract or
|
|
21
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
-
|
|
24
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
-
exercising permissions granted by this License.
|
|
26
|
-
|
|
27
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
-
including but not limited to software source code, documentation
|
|
29
|
-
source, and configuration files.
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
-
|
|
181
|
-
To apply the Apache License to your work, attach the following
|
|
182
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
-
replaced with your own identifying information. (Don't include
|
|
184
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
-
comment syntax for the file format. We also recommend that a
|
|
186
|
-
file or class name and description of purpose be included on the
|
|
187
|
-
same "printed page" as the copyright notice for easier
|
|
188
|
-
identification within third-party archives.
|
|
189
|
-
|
|
190
|
-
Copyright [yyyy] [name of copyright owner]
|
|
191
|
-
|
|
192
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
-
you may not use this file except in compliance with the License.
|
|
194
|
-
You may obtain a copy of the License at
|
|
195
|
-
|
|
196
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
-
|
|
198
|
-
Unless required by applicable law or agreed to in writing, software
|
|
199
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
-
See the License for the specific language governing permissions and
|
|
202
|
-
limitations under the License.
|
package/NOTICE
DELETED
package/dist/atomic.d.ts
DELETED
package/dist/atomic.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// packages/core/src/atomic.js
|
|
2
|
-
import { randomBytes } from "node:crypto";
|
|
3
|
-
import { rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
async function moveFile(from, to) {
|
|
5
|
-
for (let attempt = 0; ; attempt++) {
|
|
6
|
-
try {
|
|
7
|
-
return await rename(from, to);
|
|
8
|
-
} catch (error) {
|
|
9
|
-
if (process.platform !== "win32" || attempt >= 20 || !["EPERM", "EACCES", "EBUSY"].includes(error?.code)) throw error;
|
|
10
|
-
await new Promise((resolve) => setTimeout(resolve, 10 + attempt * 10));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
async function writeAtomic(file, body, mode = 384) {
|
|
15
|
-
const temporary = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
16
|
-
try {
|
|
17
|
-
await writeFile(temporary, body, { mode });
|
|
18
|
-
await moveFile(temporary, file);
|
|
19
|
-
} catch (error) {
|
|
20
|
-
await rm(temporary, { force: true }).catch(() => {
|
|
21
|
-
});
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
moveFile,
|
|
27
|
-
writeAtomic
|
|
28
|
-
};
|