@astrosheep/keiyaku 2.8.1 → 2.8.3
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/build/.tsbuildinfo +1 -1
- package/build/cli/help.js +2 -0
- package/build/cli/index.js +22 -0
- package/build/cli/parse.js +5 -0
- package/build/cli/skills-install.js +115 -22
- package/build/core/projection-kill.js +26 -0
- package/build/core/projection-wake.js +3 -0
- package/build/generated/version.js +1 -1
- package/package.json +1 -1
package/build/cli/help.js
CHANGED
|
@@ -14,6 +14,7 @@ export const CLI_COMMAND_METADATA = {
|
|
|
14
14
|
revive: command("revive", "Revive an Akuma helper session", ["keiyaku revive ARTIFACT_ID"], "none", ["cwd", "repo", "model", "effort"], "Continue a persisted helper session."),
|
|
15
15
|
wait: command("wait", "Wait for an akuma projection", ["keiyaku wait <projection-address> [--timeout DURATION]", "keiyaku @addr wait <projection-address> [--timeout DURATION]"], "none", ["cwd", "repo", "contract", "timeout"], "Read an akuma projection until its outcome is available, or show a timeout snapshot."),
|
|
16
16
|
tell: command("tell", "Send intent to a projection mailbox", ["keiyaku tell [--effort LEVEL] PROJECTION MESSAGE", "keiyaku @addr tell [--effort LEVEL] PROJECTION MESSAGE"], "none", ["cwd", "repo", "contract", "effort"], "Write intent to the mailbox and wake only when eligible."),
|
|
17
|
+
kill: command("kill", "Stop the current projection generation", ["keiyaku kill <projection-address>", "keiyaku @addr kill <projection-address>"], "none", ["cwd", "repo", "contract"], "Terminate the current generation while keeping the projection identity and tell ledger."),
|
|
17
18
|
log: command("log", "Render a contract ledger", ["keiyaku log [-C|--cwd DIR] [--repo DIR] [--contract ADDR]", "keiyaku @addr log [-C|--cwd DIR] [--repo DIR]"], "none", ["cwd", "repo", "contract"], "Read a contract ledger."),
|
|
18
19
|
akuma: command("akuma", "Inspect Akuma profiles", ["keiyaku akuma list|show"], "none", [], "Inspect configured helper profiles.", {
|
|
19
20
|
subcommands: ["list", "ls", "show"],
|
|
@@ -84,6 +85,7 @@ export function renderCliHelp(version) {
|
|
|
84
85
|
" wait Wait for an akuma projection.",
|
|
85
86
|
" revive Revive an Akuma helper session.",
|
|
86
87
|
" tell Send intent to an Akuma projection.",
|
|
88
|
+
" kill Stop the current Akuma generation.",
|
|
87
89
|
" log Render a contract ledger.",
|
|
88
90
|
" akuma Inspect helper profiles.",
|
|
89
91
|
" skills Install bundled official skills.",
|
package/build/cli/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import { buildBindDraftResponse, buildBindResponse, buildForfeitResponse, format
|
|
|
35
35
|
import { buildCallResponse, renderAdoptedLaunchReceipt } from "./render/call.js";
|
|
36
36
|
import { projectionDir, writeInboxTell } from "../core/projection-core.js";
|
|
37
37
|
import { assertTellEffortSupported, tellProjection } from "../core/projection-wake.js";
|
|
38
|
+
import { killProjectionGeneration } from "../core/projection-kill.js";
|
|
38
39
|
import { resolveProjectionAddress } from "./projection-address.js";
|
|
39
40
|
import { waitForProjection } from "../core/projection-wait.js";
|
|
40
41
|
import { buildWaitResponse } from "./render/wait.js";
|
|
@@ -233,6 +234,27 @@ const CLI_COMMAND_SPECS = {
|
|
|
233
234
|
};
|
|
234
235
|
return address ? await withResolvedAddress(address, operation) : await operation();
|
|
235
236
|
}),
|
|
237
|
+
kill: commandSpec("kill", async (_stdin, flags, _signal, positional) => {
|
|
238
|
+
const cwd = flags.contractId ? await repositoryDirectory(flags) : await projectDirectory(flags);
|
|
239
|
+
const [projectionAddress] = positional;
|
|
240
|
+
if (!projectionAddress)
|
|
241
|
+
throw new FlowError("EMPTY_PARAM", "kill requires a projection address");
|
|
242
|
+
const address = flags.contractId ? await resolveContractAddress(cwd, flags.contractId, flags.contractAddressSource) : undefined;
|
|
243
|
+
const operation = async () => {
|
|
244
|
+
const projection = await resolveProjectionAddress({
|
|
245
|
+
cwd,
|
|
246
|
+
address: projectionAddress,
|
|
247
|
+
scope: address,
|
|
248
|
+
verb: "kill",
|
|
249
|
+
});
|
|
250
|
+
const result = killProjectionGeneration(projectionDir(cwd, projection.id));
|
|
251
|
+
const line = result.status === "killed"
|
|
252
|
+
? `× killed ${projection.id}`
|
|
253
|
+
: `· already resting ${projection.id}`;
|
|
254
|
+
return textResponse(line);
|
|
255
|
+
};
|
|
256
|
+
return address ? await withResolvedAddress(address, operation) : await operation();
|
|
257
|
+
}),
|
|
236
258
|
log: commandSpec("log", async (_stdin, flags) => {
|
|
237
259
|
const cwd = await repositoryDirectory(flags);
|
|
238
260
|
const address = await resolveContractAddress(cwd, flags.contractId, flags.contractAddressSource);
|
package/build/cli/parse.js
CHANGED
|
@@ -9,6 +9,7 @@ const COMMISSION_SELECTOR_COMMANDS = new Set([
|
|
|
9
9
|
"call",
|
|
10
10
|
"wait",
|
|
11
11
|
"tell",
|
|
12
|
+
"kill",
|
|
12
13
|
"log",
|
|
13
14
|
"renew",
|
|
14
15
|
"petition",
|
|
@@ -21,6 +22,7 @@ const CLI_COMMAND_ORDER = [
|
|
|
21
22
|
"revive",
|
|
22
23
|
"wait",
|
|
23
24
|
"tell",
|
|
25
|
+
"kill",
|
|
24
26
|
"log",
|
|
25
27
|
"akuma list",
|
|
26
28
|
"akuma ls",
|
|
@@ -45,6 +47,7 @@ const COMMAND_FLAGS = {
|
|
|
45
47
|
revive: ["cwd", "repo", "model", "effort"],
|
|
46
48
|
wait: ["cwd", "repo", "contract", "timeout"],
|
|
47
49
|
tell: ["cwd", "repo", "contract", "effort"],
|
|
50
|
+
kill: ["cwd", "repo", "contract"],
|
|
48
51
|
log: ["cwd", "repo", "contract"],
|
|
49
52
|
akuma: [],
|
|
50
53
|
"akuma ls": ["cwd", "repo"],
|
|
@@ -99,6 +102,8 @@ export function commandPositionalRange(command) {
|
|
|
99
102
|
return { min: 1, max: 1, label: "<projection-address>" };
|
|
100
103
|
if (command === "tell")
|
|
101
104
|
return { min: 2, max: 2, label: "<projection> <message>" };
|
|
105
|
+
if (command === "kill")
|
|
106
|
+
return { min: 1, max: 1, label: "<projection-address>" };
|
|
102
107
|
if (isCallCommand(command))
|
|
103
108
|
return { min: 0, max: 1 };
|
|
104
109
|
return { min: 0, max: 0 };
|
|
@@ -4,10 +4,12 @@ import * as os from "node:os";
|
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { FlowError, asMessage } from "../flow-error.js";
|
|
7
|
+
import { VERSION } from "../generated/version.js";
|
|
7
8
|
const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
8
9
|
const PACKAGE_ROOT = path.resolve(MODULE_DIR, "../..");
|
|
9
10
|
const OFFICIAL_SKILLS = ["keiyaku", "keiyaku-akuma"];
|
|
10
11
|
const SKILL_ROOT = path.join(PACKAGE_ROOT, "skills");
|
|
12
|
+
const INSTALL_MARKER = ".keiyaku-skill-owned.json";
|
|
11
13
|
function skillSource(skill) {
|
|
12
14
|
return path.join(SKILL_ROOT, skill);
|
|
13
15
|
}
|
|
@@ -50,6 +52,76 @@ function objectKind(stat) {
|
|
|
50
52
|
return "directory";
|
|
51
53
|
return "other";
|
|
52
54
|
}
|
|
55
|
+
function updateHashField(hash, value) {
|
|
56
|
+
const bytes = typeof value === "string" ? Buffer.from(value, "utf8") : value;
|
|
57
|
+
const length = Buffer.allocUnsafe(4);
|
|
58
|
+
length.writeUInt32BE(bytes.length);
|
|
59
|
+
hash.update(length);
|
|
60
|
+
hash.update(bytes);
|
|
61
|
+
}
|
|
62
|
+
async function contentHash(root) {
|
|
63
|
+
const hash = crypto.createHash("sha256");
|
|
64
|
+
const walk = async (directory, relativeDirectory) => {
|
|
65
|
+
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
66
|
+
entries.sort((left, right) => Buffer.compare(Buffer.from(left.name, "utf8"), Buffer.from(right.name, "utf8")));
|
|
67
|
+
for (const entry of entries) {
|
|
68
|
+
const relative = relativeDirectory ? `${relativeDirectory}/${entry.name}` : entry.name;
|
|
69
|
+
if (relative === INSTALL_MARKER)
|
|
70
|
+
continue;
|
|
71
|
+
const absolute = path.join(directory, entry.name);
|
|
72
|
+
const stat = await fs.lstat(absolute);
|
|
73
|
+
const kind = stat.isDirectory() ? "directory"
|
|
74
|
+
: stat.isFile() ? "file"
|
|
75
|
+
: stat.isSymbolicLink() ? "symlink"
|
|
76
|
+
: "other";
|
|
77
|
+
updateHashField(hash, kind);
|
|
78
|
+
updateHashField(hash, relative);
|
|
79
|
+
if (kind === "file")
|
|
80
|
+
updateHashField(hash, await fs.readFile(absolute));
|
|
81
|
+
if (kind === "symlink")
|
|
82
|
+
updateHashField(hash, await fs.readlink(absolute));
|
|
83
|
+
if (kind === "other")
|
|
84
|
+
updateHashField(hash, `${stat.mode}:${stat.rdev}`);
|
|
85
|
+
if (kind === "directory")
|
|
86
|
+
await walk(absolute, relative);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
await walk(root, "");
|
|
90
|
+
return hash.digest("hex");
|
|
91
|
+
}
|
|
92
|
+
function validMarker(value, skill) {
|
|
93
|
+
if (!value || typeof value !== "object")
|
|
94
|
+
return false;
|
|
95
|
+
const marker = value;
|
|
96
|
+
return marker.kind === "official-skill-copy"
|
|
97
|
+
&& marker.skill === skill
|
|
98
|
+
&& typeof marker.sourceVersion === "string"
|
|
99
|
+
&& typeof marker.contentHash === "string"
|
|
100
|
+
&& /^[0-9a-f]{64}$/.test(marker.contentHash);
|
|
101
|
+
}
|
|
102
|
+
async function readInstallMarker(target, skill) {
|
|
103
|
+
try {
|
|
104
|
+
const markerPath = path.join(target, INSTALL_MARKER);
|
|
105
|
+
if (!(await fs.lstat(markerPath)).isFile())
|
|
106
|
+
return undefined;
|
|
107
|
+
const marker = JSON.parse(await fs.readFile(markerPath, "utf8"));
|
|
108
|
+
return validMarker(marker, skill) ? marker : undefined;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (isMissing(error) || error instanceof SyntaxError)
|
|
112
|
+
return undefined;
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function writeInstallMarker(target, skill, hash) {
|
|
117
|
+
const marker = {
|
|
118
|
+
kind: "official-skill-copy",
|
|
119
|
+
skill,
|
|
120
|
+
sourceVersion: VERSION,
|
|
121
|
+
contentHash: hash,
|
|
122
|
+
};
|
|
123
|
+
await fs.writeFile(path.join(target, INSTALL_MARKER), `${JSON.stringify(marker, null, 2)}\n`, "utf8");
|
|
124
|
+
}
|
|
53
125
|
async function classifyTarget(skill, target, canonicalSource) {
|
|
54
126
|
let stat;
|
|
55
127
|
try {
|
|
@@ -61,21 +133,39 @@ async function classifyTarget(skill, target, canonicalSource) {
|
|
|
61
133
|
throw error;
|
|
62
134
|
}
|
|
63
135
|
const kind = objectKind(stat);
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
136
|
+
if (stat.isDirectory()) {
|
|
137
|
+
const marker = await readInstallMarker(target, skill);
|
|
138
|
+
if (marker) {
|
|
139
|
+
const installedHash = await contentHash(target);
|
|
140
|
+
if (installedHash === marker.contentHash) {
|
|
141
|
+
const sourceHash = await contentHash(canonicalSource);
|
|
142
|
+
return {
|
|
143
|
+
skill,
|
|
144
|
+
path: target,
|
|
145
|
+
source: canonicalSource,
|
|
146
|
+
kind: "owned",
|
|
147
|
+
needsUpgrade: marker.sourceVersion !== VERSION || marker.contentHash !== sourceHash,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
skill,
|
|
152
|
+
path: target,
|
|
153
|
+
source: canonicalSource,
|
|
154
|
+
kind: "foreign",
|
|
155
|
+
collisionReason: "modified",
|
|
156
|
+
foreignIdentity: { kind, dev: stat.dev, ino: stat.ino },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
78
159
|
}
|
|
160
|
+
const link = stat.isSymbolicLink() ? await fs.readlink(target) : undefined;
|
|
161
|
+
return {
|
|
162
|
+
skill,
|
|
163
|
+
path: target,
|
|
164
|
+
source: canonicalSource,
|
|
165
|
+
kind: "foreign",
|
|
166
|
+
collisionReason: "foreign",
|
|
167
|
+
foreignIdentity: { kind, dev: stat.dev, ino: stat.ino, link },
|
|
168
|
+
};
|
|
79
169
|
}
|
|
80
170
|
async function ensureParent(parent, createdDirectories) {
|
|
81
171
|
const absentBeforeMutation = [];
|
|
@@ -159,9 +249,8 @@ async function rollbackAndVerify(originalError, states, createdDirectories) {
|
|
|
159
249
|
}
|
|
160
250
|
else if (state.kind === "owned") {
|
|
161
251
|
try {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
if (link !== state.originalLink || resolved !== state.source) {
|
|
252
|
+
const marker = await readInstallMarker(state.path, state.skill);
|
|
253
|
+
if (!marker || await contentHash(state.path) !== marker.contentHash) {
|
|
165
254
|
failures.push(`owned target changed at ${state.path}`);
|
|
166
255
|
}
|
|
167
256
|
}
|
|
@@ -210,17 +299,21 @@ export async function installOfficialSkills(force = false) {
|
|
|
210
299
|
}
|
|
211
300
|
const collisions = states.filter((state) => state.kind === "foreign");
|
|
212
301
|
if (collisions.length > 0 && !force) {
|
|
213
|
-
|
|
302
|
+
const details = collisions.map((state) => state.collisionReason === "modified"
|
|
303
|
+
? `${state.path} (owned fact exists but copied content was modified)`
|
|
304
|
+
: `${state.path} (foreign target or missing ownership fact)`);
|
|
305
|
+
throw new FlowError("EMPTY_PARAM", `Skill target collision at ${details.join(", ")}. Re-run with -f or --force to replace it.`);
|
|
214
306
|
}
|
|
215
307
|
const createdDirectories = [];
|
|
216
308
|
try {
|
|
217
309
|
for (const state of states) {
|
|
218
|
-
if (state.kind === "owned")
|
|
310
|
+
if (state.kind === "owned" && !state.needsUpgrade)
|
|
219
311
|
continue;
|
|
220
312
|
await ensureParent(path.dirname(state.path), createdDirectories);
|
|
221
313
|
state.temp = siblingArtifact(state.path, "tmp");
|
|
222
|
-
await fs.
|
|
223
|
-
|
|
314
|
+
await fs.cp(state.source, state.temp, { recursive: true, errorOnExist: true, force: false });
|
|
315
|
+
await writeInstallMarker(state.temp, state.skill, await contentHash(state.temp));
|
|
316
|
+
if (state.kind === "foreign" || state.kind === "owned") {
|
|
224
317
|
state.backup = siblingArtifact(state.path, "backup");
|
|
225
318
|
await fs.rename(state.path, state.backup);
|
|
226
319
|
}
|
|
@@ -248,7 +341,7 @@ export async function installOfficialSkills(force = false) {
|
|
|
248
341
|
skill: state.skill,
|
|
249
342
|
path: state.path,
|
|
250
343
|
source: state.source,
|
|
251
|
-
status: state.
|
|
344
|
+
status: state.installed ? "installed" : "owned",
|
|
252
345
|
})),
|
|
253
346
|
warnings,
|
|
254
347
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { openProjectionGenerationStore } from "./projection-generation-store.js";
|
|
2
|
+
export function killProjectionGeneration(projectionDirectory, nowMs = Date.now()) {
|
|
3
|
+
const store = openProjectionGenerationStore(projectionDirectory);
|
|
4
|
+
try {
|
|
5
|
+
const current = store.readCurrentGeneration();
|
|
6
|
+
if (!current)
|
|
7
|
+
return { status: "already-resting" };
|
|
8
|
+
if (current.verdict) {
|
|
9
|
+
return { status: "already-resting", executionId: current.launch.executionId };
|
|
10
|
+
}
|
|
11
|
+
const transition = store.verdictIfOpen({
|
|
12
|
+
executionId: current.launch.executionId,
|
|
13
|
+
verdict: "completed",
|
|
14
|
+
facts: {
|
|
15
|
+
operatorAction: "kill",
|
|
16
|
+
killedAt: new Date(nowMs).toISOString(),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
return transition.status === "committed"
|
|
20
|
+
? { status: "killed", executionId: current.launch.executionId }
|
|
21
|
+
: { status: "already-resting", executionId: current.launch.executionId };
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
store.close();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -116,6 +116,9 @@ export async function tellProjection(projectionDirectory, effort) {
|
|
|
116
116
|
? await startCommittedSuccessor(projectionDirectory, successorExecutionId)
|
|
117
117
|
: "pending";
|
|
118
118
|
}
|
|
119
|
+
if (life.phase !== "done") {
|
|
120
|
+
return "pending";
|
|
121
|
+
}
|
|
119
122
|
const transition = store.launchIfSettled({
|
|
120
123
|
executionId: successorExecutionId,
|
|
121
124
|
facts,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated by scripts/generate-version.mjs
|
|
2
|
-
export const VERSION = "2.8.
|
|
2
|
+
export const VERSION = "2.8.3";
|