@astrosheep/keiyaku 2.9.7 → 2.9.9
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/agents/harness/event-persistence.js +7 -5
- package/build/agents/harness/events.js +3 -2
- package/build/agents/harness/projection.js +8 -6
- package/build/agents/providers/codex-app-server/adapter.js +6 -1
- package/build/agents/providers/codex-app-server/session.js +8 -7
- package/build/agents/selector.js +12 -1
- package/build/cli/commands/akuma/view/handler.js +3 -11
- package/build/cli/commands/contract/amend/handler.js +1 -1
- package/build/cli/commands/contract/amend/meta.js +4 -4
- package/build/cli/commands/projection/status/handler.js +5 -4
- package/build/cli/commands/projection/status/meta.js +2 -2
- package/build/cli/commands/task/add/meta.js +9 -1
- package/build/cli/commands/task/shared.js +2 -1
- package/build/cli/completion.js +8 -0
- package/build/cli/render/kanshi.js +238 -80
- package/build/cli/render/path-prefix-compaction.js +119 -76
- package/build/cli/render/projection-activity.js +65 -21
- package/build/cli/render/shared.js +8 -7
- package/build/cli/render/status.js +11 -23
- package/build/cli/render/wait.js +42 -64
- package/build/config/env-keys.js +1 -1
- package/build/config/env.js +1 -1
- package/build/config/settings/disease.js +4 -4
- package/build/config/settings/loader.js +44 -21
- package/build/core/addressing.js +40 -9
- package/build/core/amend.js +21 -5
- package/build/core/call/context.js +19 -3
- package/build/core/call/execution.js +43 -20
- package/build/core/ledger-batch.js +194 -0
- package/build/core/projection/generation/database.js +22 -0
- package/build/core/projection/generation/projection-generation-execution.js +52 -38
- package/build/core/projection/generation/projection-generation-launcher.js +148 -20
- package/build/core/projection/generation/projection-generation-process.js +3 -1
- package/build/core/projection/generation/projection-generation-runner.js +76 -40
- package/build/core/projection/generation/projection-generation-runtime.js +82 -19
- package/build/core/projection/generation/store.js +17 -1
- package/build/core/projection/generation/transitions.js +89 -12
- package/build/core/projection/index.js +3 -3
- package/build/core/projection/projection-activity.js +2 -0
- package/build/core/projection/projection-kill.js +22 -10
- package/build/core/projection/projection-runner-lock.js +177 -37
- package/build/core/projection/projection-status.js +183 -60
- package/build/core/projection/projection-wake.js +171 -72
- package/build/core/status/board.js +55 -14
- package/build/core/status/drift.js +21 -5
- package/build/core/status/ledger-batch.js +1 -158
- package/build/core/task/settlement-git.js +2 -2
- package/build/core/task/task-git-runtime.js +8 -10
- package/build/core/task/task-git-store.js +5 -3
- package/build/core/worktree-path.js +39 -25
- package/build/flow-error.js +1 -1
- package/build/generated/version.js +2 -2
- package/build/git/refs.js +47 -1
- package/package.json +1 -1
- package/skills/keiyaku-akuma/SKILL.md +18 -0
- package/skills/keiyaku-workflow/SKILL.md +68 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AGENT_ACTIVITY_MAX_CHANGES, AGENT_EVENT_TEXT_MAX_CHARS, AGENT_UNKNOWN_PAYLOAD_MAX_CHARS, } from "./events.js";
|
|
1
|
+
import { AGENT_ACTIVITY_MAX_CHANGES, AGENT_DONE_FINAL_MESSAGE_PERSISTENCE_PREVIEW_MAX_CHARS, AGENT_EVENT_TEXT_MAX_CHARS, AGENT_UNKNOWN_PAYLOAD_MAX_CHARS, } from "./events.js";
|
|
2
2
|
import { EXEC_EVENT_BUFFER_HARD_CAP } from "./event-channel.js";
|
|
3
3
|
export function createTruncationMarker(envelope = {
|
|
4
4
|
seq: EXEC_EVENT_BUFFER_HARD_CAP,
|
|
@@ -23,10 +23,10 @@ export function overflowMarkerFromDropped(dropped) {
|
|
|
23
23
|
turn: dropped.turn,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
function truncateText(value) {
|
|
26
|
+
function truncateText(value, limit = AGENT_EVENT_TEXT_MAX_CHARS) {
|
|
27
27
|
return {
|
|
28
|
-
value: value.slice(0,
|
|
29
|
-
truncated: value.length >
|
|
28
|
+
value: value.slice(0, limit),
|
|
29
|
+
truncated: value.length > limit,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
/** Bound unknown native payloads before they enter the projection event stream. */
|
|
@@ -186,7 +186,9 @@ function normalizeBodyForPersistence(body) {
|
|
|
186
186
|
return { body: { ...body, text: text.value }, truncated: text.truncated };
|
|
187
187
|
}
|
|
188
188
|
case "done": {
|
|
189
|
-
const finalMessage = body.finalMessage === undefined
|
|
189
|
+
const finalMessage = body.finalMessage === undefined
|
|
190
|
+
? undefined
|
|
191
|
+
: truncateText(body.finalMessage, AGENT_DONE_FINAL_MESSAGE_PERSISTENCE_PREVIEW_MAX_CHARS);
|
|
190
192
|
return {
|
|
191
193
|
body: { ...body, ...(finalMessage ? { finalMessage: finalMessage.value } : {}) },
|
|
192
194
|
truncated: finalMessage?.truncated ?? false,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export const AGENT_EVENT_TEXT_MAX_CHARS =
|
|
2
|
+
export const AGENT_EVENT_TEXT_MAX_CHARS = 16_384;
|
|
3
|
+
export const AGENT_DONE_FINAL_MESSAGE_PERSISTENCE_PREVIEW_MAX_CHARS = 65_536;
|
|
3
4
|
export const AGENT_THOUGHT_TEXT_MAX_CHARS = 4_000;
|
|
4
5
|
export const AGENT_PLAN_MAX_ITEMS = 64;
|
|
5
6
|
export const AGENT_PLAN_ITEM_TEXT_MAX_CHARS = 200;
|
|
6
7
|
export const AGENT_ACTIVITY_MAX_CHANGES = 32;
|
|
7
|
-
export const AGENT_UNKNOWN_PAYLOAD_MAX_CHARS =
|
|
8
|
+
export const AGENT_UNKNOWN_PAYLOAD_MAX_CHARS = AGENT_EVENT_TEXT_MAX_CHARS;
|
|
8
9
|
export const activityCallSchema = z.discriminatedUnion("kind", [
|
|
9
10
|
z.object({ kind: z.literal("run"), command: z.string(), description: z.string().optional() }).strict(),
|
|
10
11
|
z.object({
|
|
@@ -239,12 +239,14 @@ async function settleProjection(shared) {
|
|
|
239
239
|
}, shared.terms.idleTimeoutMs);
|
|
240
240
|
idleTimeout.unref?.();
|
|
241
241
|
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
if (shared.terms.executionTimeoutMs > 0) {
|
|
243
|
+
executionTimeout = setTimeout(() => {
|
|
244
|
+
policyBudgetExceeded = true;
|
|
245
|
+
requestPolicyBudgetCleanup(shared, createAbortError(`${shared.terms.provider} execution policy budget expired`));
|
|
246
|
+
resolvePolicyBudget();
|
|
247
|
+
}, shared.terms.executionTimeoutMs);
|
|
248
|
+
executionTimeout.unref?.();
|
|
249
|
+
}
|
|
248
250
|
const requestLiveAbort = () => {
|
|
249
251
|
if (shared.explicitlyAborted)
|
|
250
252
|
return;
|
|
@@ -243,7 +243,12 @@ export async function startCodexAppServer(prompt, cwd, options = {}) {
|
|
|
243
243
|
builderDiagnostic = (text) => builder.emit({ type: "diagnostic", text });
|
|
244
244
|
emitTurnStarted = () => builder.emit({ type: "turn", phase: "started" });
|
|
245
245
|
const env = buildSubagentEnv(options.env);
|
|
246
|
-
server = new CodexAppServerProcess(executable, env,
|
|
246
|
+
server = new CodexAppServerProcess(executable, env, {
|
|
247
|
+
cwd,
|
|
248
|
+
codexHome: options.codexHome,
|
|
249
|
+
onEvidence: options.onEvidence,
|
|
250
|
+
onEvidenceDiagnostic: (text) => builder.emit({ type: "diagnostic", text }),
|
|
251
|
+
});
|
|
247
252
|
const { turnCompleted } = createCodexAppServerTurnMonitor({
|
|
248
253
|
server,
|
|
249
254
|
builder,
|
|
@@ -3,8 +3,6 @@ import { emitProviderEvidence, sha256Utf8 } from "../../harness/runtime.js";
|
|
|
3
3
|
import { coerceString } from "../../harness/runtime.js";
|
|
4
4
|
import { CODEX_APP_SERVER_PROVIDER } from "./identity.js";
|
|
5
5
|
export class CodexAppServerProcess {
|
|
6
|
-
onEvidence;
|
|
7
|
-
onEvidenceDiagnostic;
|
|
8
6
|
child;
|
|
9
7
|
pending = new Map();
|
|
10
8
|
notificationListeners = new Set();
|
|
@@ -17,15 +15,18 @@ export class CodexAppServerProcess {
|
|
|
17
15
|
gracefulClose;
|
|
18
16
|
forceClose;
|
|
19
17
|
codexHome;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.codexHome = codexHome;
|
|
18
|
+
onEvidence;
|
|
19
|
+
onEvidenceDiagnostic;
|
|
20
|
+
constructor(executable, env, options) {
|
|
21
|
+
this.codexHome = options.codexHome;
|
|
22
|
+
this.onEvidence = options.onEvidence;
|
|
23
|
+
this.onEvidenceDiagnostic = options.onEvidenceDiagnostic;
|
|
24
24
|
const spawnEnv = {
|
|
25
25
|
...env,
|
|
26
|
-
...(codexHome ? { CODEX_HOME: codexHome } : {}),
|
|
26
|
+
...(options.codexHome ? { CODEX_HOME: options.codexHome } : {}),
|
|
27
27
|
};
|
|
28
28
|
this.child = spawn(executable, ["app-server", "--listen", "stdio://"], {
|
|
29
|
+
cwd: options.cwd,
|
|
29
30
|
env: spawnEnv,
|
|
30
31
|
stdio: ["pipe", "pipe", "pipe"],
|
|
31
32
|
});
|
package/build/agents/selector.js
CHANGED
|
@@ -77,7 +77,18 @@ export async function selectSubagent(agentName, cwd) {
|
|
|
77
77
|
throw new FlowError("INVALID_SETTINGS", `Akuma '${selected}' references missing provider instance '${instanceName}'.`);
|
|
78
78
|
}
|
|
79
79
|
if (!("instance" in providerCandidate) || providerCandidate.instance === undefined) {
|
|
80
|
-
|
|
80
|
+
const source = providerCandidate.source === "global" ? "global" : "local";
|
|
81
|
+
throw new FlowError("INVALID_SETTINGS", `Akuma '${selected}' references invalid provider instance '${instanceName}': ${providerCandidate.reason}`, {
|
|
82
|
+
facts: {
|
|
83
|
+
kind: "invalid_settings",
|
|
84
|
+
diseases: [{
|
|
85
|
+
source,
|
|
86
|
+
coordinate: providerCandidate.coordinate,
|
|
87
|
+
knob: "providers",
|
|
88
|
+
reason: providerCandidate.reason,
|
|
89
|
+
}],
|
|
90
|
+
},
|
|
91
|
+
});
|
|
81
92
|
}
|
|
82
93
|
const providerInstance = providerCandidate.instance;
|
|
83
94
|
const adapter = providerInstance.kind;
|
|
@@ -2,19 +2,12 @@ import { FlowError } from "../../../../flow-error.js";
|
|
|
2
2
|
import { assertSettingsKnobUsable } from "../../../../config/settings/disease.js";
|
|
3
3
|
import { loadKeiyakuSettings } from "../../../../config/settings/loader.js";
|
|
4
4
|
import { loadAkumaCatalog } from "../../../../config/akuma-loader.js";
|
|
5
|
-
import {
|
|
5
|
+
import { readAkumaNonterminalProjectionStatus } from "../../../../core/projection/index.js";
|
|
6
6
|
import { isResponseArtifactId } from "../../../../core/response-artifact-id.js";
|
|
7
7
|
import { textResponse } from "../../../render/shared.js";
|
|
8
8
|
import { renderProjectionStatusSection } from "../../../render/status.js";
|
|
9
9
|
import { projectDirectory } from "../../shared.js";
|
|
10
10
|
import { renderAkumaShow, renderAkumaView } from "../../akuma.js";
|
|
11
|
-
const NONTERMINAL_PROJECTION_STATES = new Set([
|
|
12
|
-
"minting",
|
|
13
|
-
"startup-timeout",
|
|
14
|
-
"unknown",
|
|
15
|
-
"out",
|
|
16
|
-
"lost",
|
|
17
|
-
]);
|
|
18
11
|
export const handler = async (_stdin, flags, _signal, positional) => {
|
|
19
12
|
const [name] = positional;
|
|
20
13
|
if (!name)
|
|
@@ -28,8 +21,7 @@ export const handler = async (_stdin, flags, _signal, positional) => {
|
|
|
28
21
|
assertSettingsKnobUsable(loaded, "default");
|
|
29
22
|
assertSettingsKnobUsable(loaded, "reviewer");
|
|
30
23
|
const profile = renderAkumaShow(await loadAkumaCatalog(cwd), loaded.providerInstances, loaded.knobs, name).trimEnd();
|
|
31
|
-
const projectionStatus = await
|
|
32
|
-
const
|
|
33
|
-
const projections = renderProjectionStatusSection({ rows }).trimEnd();
|
|
24
|
+
const projectionStatus = await readAkumaNonterminalProjectionStatus(cwd, Date.now(), name);
|
|
25
|
+
const projections = renderProjectionStatusSection(projectionStatus).trimEnd();
|
|
34
26
|
return textResponse(renderAkumaView(profile, projections));
|
|
35
27
|
};
|
|
@@ -5,7 +5,7 @@ import { buildAmendResponse } from "../../../render/arc.js";
|
|
|
5
5
|
import { renderCoreResult } from "../../../render/shared.js";
|
|
6
6
|
import { effectiveDirectory, repositoryDirectory } from "../../shared.js";
|
|
7
7
|
export const handler = async (stdin, flags) => {
|
|
8
|
-
const parsed = buildAmendInput(stdin, effectiveDirectory(flags), flags.contractId, flags.contractAddressSource);
|
|
8
|
+
const parsed = buildAmendInput(stdin, effectiveDirectory(flags), flags.contractId, flags.contractAddressSource, flags.appendScope);
|
|
9
9
|
const cwd = await repositoryDirectory(flags, "amend");
|
|
10
10
|
const address = await resolveExistingContractAddress(cwd, flags.contractId, flags.contractAddressSource, effectiveDirectory(flags));
|
|
11
11
|
return renderCoreResult(amendKeiyaku({
|
|
@@ -2,11 +2,11 @@ export const meta = {
|
|
|
2
2
|
command: "amend",
|
|
3
3
|
summary: "Record an amendment",
|
|
4
4
|
usage: [
|
|
5
|
-
"keiyaku amend [-C|--cwd DIR] [--repo DIR] [--contract ADDR] - < amendment.md",
|
|
6
|
-
"keiyaku @addr amend [-C|--cwd DIR] [--repo DIR] - < amendment.md",
|
|
5
|
+
"keiyaku amend [-C|--cwd DIR] [--repo DIR] [--contract ADDR] [--append-scope PATTERN] - < amendment.md",
|
|
6
|
+
"keiyaku @addr amend [-C|--cwd DIR] [--repo DIR] [--append-scope PATTERN] - < amendment.md",
|
|
7
7
|
],
|
|
8
8
|
stdin: { mode: "document", selector: { kind: "positional", index: 0, required: true, rejectBlank: true } },
|
|
9
|
-
flags: ["cwd", "repo", "contract"],
|
|
10
|
-
purpose: "Append a prose amendment and optional
|
|
9
|
+
flags: ["cwd", "repo", "contract", "append-scope"],
|
|
10
|
+
purpose: "Append a prose amendment and one optional ordered scope-pattern delta from --append-scope or Scope Append.",
|
|
11
11
|
completionRank: 8,
|
|
12
12
|
};
|
|
@@ -6,6 +6,10 @@ import { renderProjectionFilteredStatus, renderStatusBoard } from "../../../rend
|
|
|
6
6
|
import { textResponse } from "../../../render/shared.js";
|
|
7
7
|
import { projectDirectory, repositoryDirectory } from "../../shared.js";
|
|
8
8
|
export const handler = async (_stdin, flags, _signal, positional) => {
|
|
9
|
+
const [projectionId] = positional;
|
|
10
|
+
if (projectionId !== undefined && !isProjectionId(projectionId)) {
|
|
11
|
+
throw new FlowError("EMPTY_PARAM", `invalid projection id: ${projectionId}`);
|
|
12
|
+
}
|
|
9
13
|
// Status is read-only and must open outside Git. projectDirectory still
|
|
10
14
|
// honors --repo as a repository coordinate when the operator names one.
|
|
11
15
|
const cwd = flags.target === undefined
|
|
@@ -14,12 +18,9 @@ export const handler = async (_stdin, flags, _signal, positional) => {
|
|
|
14
18
|
const target = flags.target === undefined ? undefined : normalizeTargetRef(flags.target);
|
|
15
19
|
const board = await readKanshiBoard(cwd, Date.now(), {
|
|
16
20
|
...(target === undefined ? {} : { target }),
|
|
17
|
-
|
|
21
|
+
...(projectionId === undefined ? {} : { projectionId }),
|
|
18
22
|
});
|
|
19
|
-
const [projectionId] = positional;
|
|
20
23
|
if (projectionId === undefined)
|
|
21
24
|
return textResponse(renderStatusBoard(board));
|
|
22
|
-
if (!isProjectionId(projectionId))
|
|
23
|
-
throw new FlowError("EMPTY_PARAM", `invalid projection id: ${projectionId}`);
|
|
24
25
|
return textResponse(renderProjectionFilteredStatus(board, projectionId));
|
|
25
26
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export const meta = {
|
|
2
2
|
command: "status",
|
|
3
3
|
summary: "Show the Kanshi board",
|
|
4
|
-
usage: ["keiyaku status [PROJECTION] [-C|--cwd DIR] [--repo DIR] [--target REF]
|
|
4
|
+
usage: ["keiyaku status [PROJECTION] [-C|--cwd DIR] [--repo DIR] [--target REF]"],
|
|
5
5
|
stdin: { mode: "argument" },
|
|
6
|
-
flags: ["cwd", "repo", "target"
|
|
6
|
+
flags: ["cwd", "repo", "target"],
|
|
7
7
|
purpose: "Read the Kanshi board or filter it to one projection without mutation.",
|
|
8
8
|
completionRank: 14,
|
|
9
9
|
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
const TASK_ADD_USAGE_PREFIX = "keiyaku task add [-C|--cwd DIR] [--needs ID]... [--parent ID] [--from ID]... [--pri 0-3]";
|
|
1
2
|
export const meta = {
|
|
2
3
|
command: "task add",
|
|
3
4
|
summary: "Add a task",
|
|
4
|
-
usage: [
|
|
5
|
+
usage: [
|
|
6
|
+
`${TASK_ADD_USAGE_PREFIX} <BODY>`,
|
|
7
|
+
`${TASK_ADD_USAGE_PREFIX} - < task.md`,
|
|
8
|
+
],
|
|
5
9
|
stdin: {
|
|
6
10
|
mode: "argument",
|
|
7
11
|
selector: { kind: "positional", index: 0, required: true, rejectBlank: true },
|
|
8
12
|
},
|
|
9
13
|
flags: ["cwd", "needs", "parent", "from", "pri"],
|
|
10
14
|
purpose: "Create a lightweight task from a title and optional body.",
|
|
15
|
+
notes: [
|
|
16
|
+
"<BODY> and literal - are mutually exclusive body selectors. Use literal - with stdin for multiline prose.",
|
|
17
|
+
"Only literal - reads stdin; unselected piped bytes are ignored and never change a literal <BODY>.",
|
|
18
|
+
],
|
|
11
19
|
};
|
|
@@ -17,7 +17,8 @@ export function parseTaskAddInput(input) {
|
|
|
17
17
|
if (!input.trim())
|
|
18
18
|
throw new FlowError("EMPTY_PARAM", "task add input cannot be blank");
|
|
19
19
|
const lines = input.split(/\r?\n/);
|
|
20
|
-
const
|
|
20
|
+
const firstLine = lines[0]?.startsWith("# ") ? lines[0].slice(2) : lines[0];
|
|
21
|
+
const title = firstLine?.trim() ?? "";
|
|
21
22
|
if (!title)
|
|
22
23
|
throw new FlowError("EMPTY_PARAM", "task title cannot be blank");
|
|
23
24
|
if (lines.length > 1 && lines[1].trim() !== "") {
|
package/build/cli/completion.js
CHANGED
|
@@ -19,6 +19,10 @@ function topLevelCommands() {
|
|
|
19
19
|
function subcommandsFor(parent) {
|
|
20
20
|
return [...(getCommandMetadata(parent).subcommands ?? [])];
|
|
21
21
|
}
|
|
22
|
+
function topLevelOptionsFor(command) {
|
|
23
|
+
const metadata = allCommandMetadata().find((meta) => meta.command === command && !command.includes(" "));
|
|
24
|
+
return metadata ? metadata.flags.map((flag) => `--${flag}`) : [];
|
|
25
|
+
}
|
|
22
26
|
function filterPrefix(items, word) {
|
|
23
27
|
return items.filter((item) => item.startsWith(word));
|
|
24
28
|
}
|
|
@@ -50,6 +54,10 @@ export async function renderCompletionCandidates(input) {
|
|
|
50
54
|
if (input.previous === "--filter") {
|
|
51
55
|
return filterPrefix([TASK_FILTER_COMPLETION], word).join("\n");
|
|
52
56
|
}
|
|
57
|
+
const options = input.previous ? topLevelOptionsFor(input.previous) : [];
|
|
58
|
+
if (options.length > 0) {
|
|
59
|
+
return filterPrefix(options, word).join("\n");
|
|
60
|
+
}
|
|
53
61
|
return filterPrefix(topLevelCommands(), word).join("\n");
|
|
54
62
|
}
|
|
55
63
|
export function renderCompletionScript(shell = "bash") {
|
|
@@ -1,25 +1,82 @@
|
|
|
1
|
+
import { getConfig } from "../../config/env.js";
|
|
1
2
|
import { formatAgeMs } from "./format.js";
|
|
3
|
+
import { displayColumns, resolveLineColumns, truncateColumns } from "./line-width.js";
|
|
4
|
+
import { renderPendingProjectionTell, renderProjectionActivity, selectProjectionActivityWindow, } from "./projection-activity.js";
|
|
5
|
+
const KANSHI_MAX_COLUMNS = 120;
|
|
6
|
+
const KANSHI_ACTIVITY_ROWS = 3;
|
|
2
7
|
function shortHead(hash) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
return hash?.slice(0, 7);
|
|
9
|
+
}
|
|
10
|
+
function supportsColor() {
|
|
11
|
+
const { terminal } = getConfig();
|
|
12
|
+
if (terminal.noColor !== undefined || terminal.forceColor === "0")
|
|
13
|
+
return false;
|
|
14
|
+
if (terminal.forceColor !== undefined)
|
|
15
|
+
return true;
|
|
16
|
+
return process.stdout.isTTY === true && terminal.term?.toLowerCase() !== "dumb";
|
|
17
|
+
}
|
|
18
|
+
function tone(text, value) {
|
|
19
|
+
if (!supportsColor() || value === undefined || value === "normal")
|
|
20
|
+
return text;
|
|
21
|
+
return value === "description"
|
|
22
|
+
? `\x1b[2m${text}\x1b[0m`
|
|
23
|
+
: `\x1b[31m${text}\x1b[0m`;
|
|
24
|
+
}
|
|
25
|
+
function renderFacts(facts) {
|
|
26
|
+
return {
|
|
27
|
+
plain: facts.map((fact) => fact.text).join(" · "),
|
|
28
|
+
rendered: facts.map((fact) => tone(fact.text, fact.tone)).join(" · "),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Align facts without allowing ANSI bytes to enter width arithmetic. */
|
|
32
|
+
function alignedBoardRow(input) {
|
|
33
|
+
const facts = renderFacts(input.facts);
|
|
34
|
+
const prefix = `${input.prefix} `;
|
|
35
|
+
const titleBudget = Math.max(0, input.width - displayColumns(prefix) - displayColumns(facts.plain) - 1);
|
|
36
|
+
const visibleTitle = truncateColumns(input.title, titleBudget);
|
|
37
|
+
const spaces = " ".repeat(Math.max(1, input.width - displayColumns(prefix) - displayColumns(visibleTitle) - displayColumns(facts.plain)));
|
|
38
|
+
return `${prefix}${tone(visibleTitle, input.titleTone ?? "description")}${spaces}${facts.rendered}`;
|
|
6
39
|
}
|
|
7
40
|
function arcSparkline(arcs) {
|
|
8
|
-
if (arcs <=
|
|
9
|
-
return
|
|
41
|
+
if (arcs <= 1)
|
|
42
|
+
return undefined;
|
|
10
43
|
return Array.from({ length: arcs }, () => "·").join("──");
|
|
11
44
|
}
|
|
12
45
|
function pendingAfterIds(contract) {
|
|
13
46
|
return contract.after.filter((item) => !item.terminal).map((item) => item.id);
|
|
14
47
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The Kanshi shape is the after DAG, not the petition/claim settlement queue.
|
|
50
|
+
* Stable input order settles independent lanes and any malformed cycle remains
|
|
51
|
+
* observable rather than dropping a contract.
|
|
52
|
+
*/
|
|
53
|
+
export function orderKanshiContracts(contracts) {
|
|
54
|
+
const byId = new Map(contracts.map((contract) => [contract.id, contract]));
|
|
55
|
+
const remaining = new Set(contracts.map((contract) => contract.id));
|
|
56
|
+
const emitted = new Set();
|
|
57
|
+
const ordered = [];
|
|
58
|
+
while (remaining.size > 0) {
|
|
59
|
+
const next = contracts.find((contract) => (remaining.has(contract.id)
|
|
60
|
+
&& pendingAfterIds(contract)
|
|
61
|
+
.filter((id) => byId.has(id))
|
|
62
|
+
.every((id) => emitted.has(id))));
|
|
63
|
+
if (!next) {
|
|
64
|
+
// The bind boundary normally rejects cycles. Keep a corrupt historical
|
|
65
|
+
// graph visible in its original deterministic order instead of inventing
|
|
66
|
+
// a dependency edge or omitting work from the board.
|
|
67
|
+
const fallback = contracts.find((contract) => remaining.has(contract.id));
|
|
68
|
+
if (!fallback)
|
|
69
|
+
break;
|
|
70
|
+
ordered.push(fallback);
|
|
71
|
+
emitted.add(fallback.id);
|
|
72
|
+
remaining.delete(fallback.id);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
ordered.push(next);
|
|
76
|
+
emitted.add(next.id);
|
|
77
|
+
remaining.delete(next.id);
|
|
78
|
+
}
|
|
79
|
+
return ordered;
|
|
23
80
|
}
|
|
24
81
|
function renderDriftMark(drift) {
|
|
25
82
|
if (drift.state === "drift")
|
|
@@ -28,73 +85,174 @@ function renderDriftMark(drift) {
|
|
|
28
85
|
return "▲orphaned";
|
|
29
86
|
return undefined;
|
|
30
87
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
88
|
+
function contractGlyph(contract) {
|
|
89
|
+
if (contract.state.state === "corrupt")
|
|
90
|
+
return "×";
|
|
91
|
+
return pendingAfterIds(contract).length > 0 ? "⧗" : "□";
|
|
92
|
+
}
|
|
93
|
+
function contractFacts(contract) {
|
|
94
|
+
const facts = [];
|
|
95
|
+
const spark = arcSparkline(contract.arcs);
|
|
96
|
+
if (spark)
|
|
97
|
+
facts.push({ text: spark });
|
|
98
|
+
const drift = renderDriftMark(contract.baseDrift);
|
|
99
|
+
if (drift)
|
|
100
|
+
facts.push({ text: drift });
|
|
101
|
+
const lifecycle = contract.state.state === "active" ? "open" : contract.state.state;
|
|
102
|
+
const age = formatAgeMs(contract.lastActiveMs);
|
|
103
|
+
facts.push({ text: age ? `${lifecycle} ${age}` : lifecycle });
|
|
104
|
+
if (contract.queueHeadStalled) {
|
|
105
|
+
facts.push({ text: age ? `stalled ${age}` : "stalled", tone: "alert" });
|
|
38
106
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
return facts;
|
|
108
|
+
}
|
|
109
|
+
function renderKeiyakuSection(board, width) {
|
|
110
|
+
if (!board.contractsObservable)
|
|
111
|
+
return undefined;
|
|
112
|
+
const lines = [`keiyaku ${board.contracts.length}`];
|
|
113
|
+
for (const contract of orderKanshiContracts(board.contracts)) {
|
|
114
|
+
lines.push(alignedBoardRow({
|
|
115
|
+
prefix: `${contractGlyph(contract)} ${contract.place ?? contract.slug}`,
|
|
116
|
+
title: contract.title,
|
|
117
|
+
facts: contractFacts(contract),
|
|
118
|
+
width,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
return lines.join("\n");
|
|
122
|
+
}
|
|
123
|
+
function activityState(row) {
|
|
124
|
+
switch (row.state) {
|
|
125
|
+
case "lost": return "lost";
|
|
126
|
+
case "startup-timeout": return "stalled";
|
|
127
|
+
case "unknown":
|
|
128
|
+
case "incompatible": return "unknown";
|
|
129
|
+
case "failed":
|
|
130
|
+
case "dead": return "dead";
|
|
131
|
+
case "done": return "returned";
|
|
132
|
+
case "killed":
|
|
133
|
+
case "dismissed": return "dismissed";
|
|
134
|
+
case "minting":
|
|
135
|
+
case "out": return "running";
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function projectionBinding(board, row) {
|
|
139
|
+
if (row.binding?.kind !== "commission")
|
|
140
|
+
return "";
|
|
141
|
+
const place = board.commissionPlaces.get(row.binding.commissionId);
|
|
142
|
+
return place ? `@${place}` : "";
|
|
143
|
+
}
|
|
144
|
+
function projectionFacts(row) {
|
|
145
|
+
const facts = [];
|
|
146
|
+
if (row.durationMs !== undefined)
|
|
147
|
+
facts.push({ text: `up ${formatAgeMs(row.durationMs) ?? "0s"}` });
|
|
148
|
+
if (row.activityAgeMs !== undefined)
|
|
149
|
+
facts.push({ text: `active ${formatAgeMs(row.activityAgeMs) ?? "0s"}` });
|
|
150
|
+
if (row.state !== "out" && row.state !== "minting")
|
|
151
|
+
facts.push({ text: row.state, tone: row.state === "startup-timeout" ? "alert" : "normal" });
|
|
152
|
+
return facts;
|
|
153
|
+
}
|
|
154
|
+
function renderEmbeddedActivity(row, width) {
|
|
155
|
+
const observedAtMs = row.observedAtMs ?? Date.now();
|
|
156
|
+
const selection = row.activity
|
|
157
|
+
? selectProjectionActivityWindow(row.activity, KANSHI_ACTIVITY_ROWS)
|
|
158
|
+
: undefined;
|
|
159
|
+
const ordinary = row.activity
|
|
160
|
+
? renderProjectionActivity(selection.activity, {
|
|
161
|
+
anchorMs: observedAtMs,
|
|
162
|
+
state: activityState(row),
|
|
163
|
+
showPlan: false,
|
|
164
|
+
showSilence: false,
|
|
165
|
+
...(row.workspaceRoot ? { workspaceRoot: row.workspaceRoot } : {}),
|
|
166
|
+
maxColumns: width,
|
|
167
|
+
leadingOmittedCount: selection.leadingOmittedCount,
|
|
168
|
+
})
|
|
169
|
+
: undefined;
|
|
170
|
+
const rendered = ordinary?.lines.map((line, index) => ({
|
|
171
|
+
line,
|
|
172
|
+
at: ordinary.rowAts[index],
|
|
173
|
+
order: index,
|
|
174
|
+
})) ?? [];
|
|
175
|
+
const tells = (row.pendingTells ?? []).map((tell, index) => ({
|
|
176
|
+
line: renderPendingProjectionTell(tell, {
|
|
177
|
+
anchorMs: observedAtMs,
|
|
178
|
+
maxColumns: width,
|
|
179
|
+
renderUnconsumedTail: (tail) => tone(tail, "alert"),
|
|
180
|
+
}),
|
|
181
|
+
at: tell.createdAt,
|
|
182
|
+
order: rendered.length + index,
|
|
183
|
+
}));
|
|
184
|
+
return [...rendered, ...tells]
|
|
185
|
+
.sort((left, right) => {
|
|
186
|
+
const leftAt = Date.parse(left.at ?? "");
|
|
187
|
+
const rightAt = Date.parse(right.at ?? "");
|
|
188
|
+
const safeLeft = Number.isFinite(leftAt) ? leftAt : Number.POSITIVE_INFINITY;
|
|
189
|
+
const safeRight = Number.isFinite(rightAt) ? rightAt : Number.POSITIVE_INFINITY;
|
|
190
|
+
return safeLeft - safeRight || left.order - right.order;
|
|
191
|
+
})
|
|
192
|
+
.map((entry) => entry.line);
|
|
193
|
+
}
|
|
194
|
+
function terminalSummary(board) {
|
|
195
|
+
const omitted = board.projections?.omitted;
|
|
196
|
+
if (!omitted)
|
|
197
|
+
return undefined;
|
|
198
|
+
const compatibleStates = ["failed", "dead", "done", "killed", "dismissed"];
|
|
199
|
+
const details = compatibleStates
|
|
200
|
+
.flatMap((state) => omitted.byState[state] > 0 ? [`${omitted.byState[state]} ${state}`] : []);
|
|
201
|
+
return details.length > 0 ? `+ ${details.join(" · ")}` : undefined;
|
|
202
|
+
}
|
|
203
|
+
function renderAkumaSection(board, width) {
|
|
204
|
+
if (!board.projections)
|
|
205
|
+
return undefined;
|
|
206
|
+
const lines = [`akuma ${board.projections.rows.length}`];
|
|
207
|
+
for (const row of board.projections.rows) {
|
|
208
|
+
const alias = row.alias ? ` ${row.alias}` : "";
|
|
209
|
+
lines.push(alignedBoardRow({
|
|
210
|
+
prefix: `◆ ${row.id}${alias}`,
|
|
211
|
+
title: projectionBinding(board, row),
|
|
212
|
+
titleTone: "normal",
|
|
213
|
+
facts: projectionFacts(row),
|
|
214
|
+
width,
|
|
215
|
+
}));
|
|
216
|
+
lines.push(...renderEmbeddedActivity(row, width));
|
|
98
217
|
}
|
|
99
|
-
|
|
218
|
+
const folded = terminalSummary(board);
|
|
219
|
+
if (folded)
|
|
220
|
+
lines.push(tone(folded, "description"));
|
|
221
|
+
return lines.join("\n");
|
|
222
|
+
}
|
|
223
|
+
function taskLabel(task) {
|
|
224
|
+
return task.title === task.id ? `P${task.pri} ${task.id}` : `P${task.pri} ${task.id} ${task.title}`;
|
|
225
|
+
}
|
|
226
|
+
function renderTaskSection(tasks, width) {
|
|
227
|
+
if (!tasks)
|
|
228
|
+
return undefined;
|
|
229
|
+
const lines = [`task ${tasks.total}`];
|
|
230
|
+
for (const task of tasks.topTasks) {
|
|
231
|
+
lines.push(alignedBoardRow({
|
|
232
|
+
prefix: "▶",
|
|
233
|
+
title: taskLabel(task),
|
|
234
|
+
facts: [{ text: `in_progress · active ${formatAgeMs(task.activityAgeMs) ?? "0s"}` }],
|
|
235
|
+
width,
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
const folded = [
|
|
239
|
+
tasks.ready > 0 ? `${tasks.ready} ready` : undefined,
|
|
240
|
+
tasks.blocked > 0 ? `${tasks.blocked} blocked` : undefined,
|
|
241
|
+
].filter((fact) => fact !== undefined);
|
|
242
|
+
if (folded.length > 0)
|
|
243
|
+
lines.push(tone(`+ ${folded.join(" · ")}`, "description"));
|
|
244
|
+
return lines.join("\n");
|
|
245
|
+
}
|
|
246
|
+
export function renderKanshiBoard(board) {
|
|
247
|
+
const width = Math.min(KANSHI_MAX_COLUMNS, resolveLineColumns());
|
|
248
|
+
const left = "kanshi ";
|
|
249
|
+
const head = shortHead(board.defaultHead);
|
|
250
|
+
const right = head ? ` 現世 ${head}` : " 現世";
|
|
251
|
+
const dashes = "─".repeat(Math.max(1, width - displayColumns(left) - displayColumns(right)));
|
|
252
|
+
const sections = [
|
|
253
|
+
renderKeiyakuSection(board, width),
|
|
254
|
+
renderAkumaSection(board, width),
|
|
255
|
+
renderTaskSection(board.tasks, width),
|
|
256
|
+
].filter((section) => section !== undefined);
|
|
257
|
+
return `${[`${left}${dashes}${right}`, ...sections].join("\n\n")}\n`;
|
|
100
258
|
}
|