@modootoday/pmcp 0.17.4 → 0.18.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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +60 -0
- package/README.md +29 -24
- package/dist/apply-4IGTXOCQ.js +242 -0
- package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
- package/dist/available-DBSIVVJ6.js +73 -0
- package/dist/broadcast-3RY3OZGY.js +18 -0
- package/dist/chunk-25GHX674.js +1246 -0
- package/dist/chunk-2P4Z2NUX.js +28 -0
- package/dist/chunk-34DECPVC.js +22 -0
- package/dist/chunk-3NYG4SGU.js +45 -0
- package/dist/chunk-3PW4FI7U.js +32 -0
- package/dist/chunk-3Y3HDMHA.js +108 -0
- package/dist/chunk-47O3X4VS.js +113 -0
- package/dist/chunk-4NDEP7HU.js +26 -0
- package/dist/chunk-4VCC2NXE.js +104 -0
- package/dist/chunk-5OMOPUE6.js +39 -0
- package/dist/chunk-5QQWS4US.js +53 -0
- package/dist/chunk-5ZABTVSW.js +48 -0
- package/dist/chunk-65ZHM5RH.js +4985 -0
- package/dist/chunk-665TA55Z.js +419 -0
- package/dist/chunk-6STKGOCW.js +27 -0
- package/dist/chunk-6WXMJOMI.js +9 -0
- package/dist/chunk-73AKO4UL.js +24 -0
- package/dist/chunk-7BLPN3W6.js +31 -0
- package/dist/chunk-7DLZC73N.js +29 -0
- package/dist/chunk-7GBYECSK.js +72 -0
- package/dist/chunk-7TD53M7L.js +13 -0
- package/dist/chunk-A4PKLESO.js +112 -0
- package/dist/chunk-ABTJQ4QV.js +74 -0
- package/dist/chunk-BBTBJCFA.js +380 -0
- package/dist/chunk-BU65MNVU.js +13 -0
- package/dist/chunk-BVCTKPT3.js +83 -0
- package/dist/chunk-C4NHQGHL.js +142 -0
- package/dist/chunk-CJTKR6K6.js +1213 -0
- package/dist/chunk-DCU2EXQV.js +78 -0
- package/dist/chunk-DZ2MRTYT.js +135 -0
- package/dist/chunk-E2YOZ2FF.js +207 -0
- package/dist/chunk-E3DQB5LS.js +48 -0
- package/dist/chunk-E7OOHLQR.js +7 -0
- package/dist/chunk-EATCUWGG.js +66 -0
- package/dist/chunk-EIDIVIAD.js +33 -0
- package/dist/chunk-EJBZGIDK.js +1934 -0
- package/dist/chunk-ELAGZ635.js +252 -0
- package/dist/chunk-GZHHEHKY.js +44 -0
- package/dist/chunk-HDMBVLCZ.js +53 -0
- package/dist/chunk-HQOB7OQS.js +81 -0
- package/dist/chunk-IGYRMM62.js +28 -0
- package/dist/chunk-IJBSOWHK.js +86 -0
- package/dist/chunk-INT7QLEU.js +114 -0
- package/dist/chunk-J6QLLQVL.js +1025 -0
- package/dist/chunk-J7UYNJCR.js +9 -0
- package/dist/chunk-JEL35P7S.js +53 -0
- package/dist/chunk-JGJ4INEN.js +32 -0
- package/dist/chunk-JS5RTH4I.js +84 -0
- package/dist/chunk-JUXNIXN4.js +42 -0
- package/dist/chunk-JWRZDYB5.js +59 -0
- package/dist/chunk-KMXRRSKT.js +660 -0
- package/dist/chunk-LAZQBMAU.js +67 -0
- package/dist/chunk-LLBPVZXM.js +67 -0
- package/dist/chunk-LLT5FQBE.js +57 -0
- package/dist/chunk-LMT3PPXJ.js +17 -0
- package/dist/chunk-MM2Y43LC.js +87 -0
- package/dist/chunk-MPSQXSC6.js +346 -0
- package/dist/chunk-MVFH26QT.js +97 -0
- package/dist/chunk-MWFOUBFC.js +39 -0
- package/dist/chunk-N5AQ3PP7.js +211 -0
- package/dist/chunk-NQPURJT5.js +44 -0
- package/dist/chunk-NRBQK6UX.js +105 -0
- package/dist/chunk-NZS5CD72.js +333 -0
- package/dist/chunk-OEH47H6A.js +48 -0
- package/dist/chunk-OG7QR2DP.js +75 -0
- package/dist/chunk-OPYFEHKG.js +52 -0
- package/dist/chunk-P4N7DBD5.js +83 -0
- package/dist/chunk-PAX3QXX2.js +140 -0
- package/dist/chunk-PLX3BOOS.js +396 -0
- package/dist/chunk-PMJG2CXF.js +122 -0
- package/dist/chunk-PWSJJXLQ.js +643 -0
- package/dist/chunk-Q5H3L6Y4.js +23 -0
- package/dist/chunk-Q65R3XKX.js +155 -0
- package/dist/chunk-QEW4J3IZ.js +74 -0
- package/dist/chunk-QPL7E2HW.js +464 -0
- package/dist/chunk-R2GPCZUX.js +22 -0
- package/dist/chunk-R4L6LJJ2.js +778 -0
- package/dist/chunk-R5MT42JS.js +284 -0
- package/dist/chunk-RK4PYD7L.js +73 -0
- package/dist/chunk-RMATE45Z.js +197 -0
- package/dist/chunk-S3PIAMXV.js +230 -0
- package/dist/chunk-SG5TPMKH.js +93 -0
- package/dist/chunk-T3LKX23M.js +168 -0
- package/dist/chunk-T6GOWHK6.js +30 -0
- package/dist/chunk-TIA4SPU2.js +10 -0
- package/dist/chunk-TNCZ6444.js +57 -0
- package/dist/chunk-TVL5RTE6.js +269 -0
- package/dist/chunk-UOCLRM7P.js +151 -0
- package/dist/chunk-UPQTAHUK.js +189 -0
- package/dist/chunk-V4NPDK6X.js +14 -0
- package/dist/chunk-VJFEN6DJ.js +38 -0
- package/dist/chunk-WIW772I3.js +25 -0
- package/dist/chunk-XELAZAIM.js +136 -0
- package/dist/chunk-XNML2KIC.js +23 -0
- package/dist/chunk-XP2U3LO3.js +30 -0
- package/dist/chunk-YGOWIJPE.js +51 -0
- package/dist/chunk-YIXDHQYE.js +11 -0
- package/dist/chunk-YMHUM7AV.js +22 -0
- package/dist/chunk-YSAWTGNA.js +117 -0
- package/dist/chunk-Z4HRRXRF.js +478 -0
- package/dist/chunk-ZH6R642Z.js +102 -0
- package/dist/claude-U2JC2DNQ.js +77 -0
- package/dist/cli-VYCQJZ5X.js +41 -0
- package/dist/cli-ZTCBSDW4.js +46 -0
- package/dist/cli.js +144 -16197
- package/dist/completion-E7RRG3ZT.js +142 -0
- package/dist/config-DnpLL2kT.d.ts +46 -0
- package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
- package/dist/diagnostics-XXH4FLUG.js +93 -0
- package/dist/doctor-ZIOESU3N.js +538 -0
- package/dist/entry-ZNFCTDVE.js +305 -0
- package/dist/exec-mcp-X6372BLE.js +365 -0
- package/dist/harness-F2XFDYXF.js +177 -0
- package/dist/harness-egress-bridge.js +4 -4
- package/dist/harness-launch-gate.js +47 -940
- package/dist/harness-pane-runner.js +13 -80
- package/dist/harness-worker.js +21 -2703
- package/dist/hook-body.js +5221 -0
- package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
- package/dist/hook.js +26 -0
- package/dist/hooks-FYE2L5RW.js +21 -0
- package/dist/host-GRY3VAHH.js +22 -0
- package/dist/host-X6BR6X4O.js +200 -0
- package/dist/host-run-GCA6H6SR.js +307 -0
- package/dist/http.d.ts +5 -42
- package/dist/http.js +21 -2234
- package/dist/import-mcp-2TTBPVLY.js +400 -0
- package/dist/index.d.ts +146 -168
- package/dist/index.js +133 -4948
- package/dist/init-627KFXTG.js +14 -0
- package/dist/install-GG7HHZK2.js +796 -0
- package/dist/invoke-LW22Z6ET.js +23 -0
- package/dist/list-MCP2FXUF.js +68 -0
- package/dist/list-NGMSQ5SH.js +65 -0
- package/dist/load-BEUBABtB.d.ts +21 -0
- package/dist/logout-6CSHUWWE.js +44 -0
- package/dist/logs-SPB6AANY.js +107 -0
- package/dist/mailbox/index.d.ts +10 -5
- package/dist/mailbox/index.js +53 -1572
- package/dist/mailbox-7BV54Q4R.js +285 -0
- package/dist/mailbox-GDJ7BWQN.js +189 -0
- package/dist/mainline-JQTTYJMI.js +639 -0
- package/dist/marketplace-G4VQET5W.js +191 -0
- package/dist/mcp-2DKVU3SW.js +15 -0
- package/dist/mcp-V23HC3LB.js +193 -0
- package/dist/models-ISU4DCMA.js +32 -0
- package/dist/opencode-CN7JLQYO.js +60 -0
- package/dist/pause-FFAYRBWI.js +18 -0
- package/dist/preview-DT7DWG5F.js +91 -0
- package/dist/project/hook-adapter.d.ts +5 -2
- package/dist/project/hook-adapter.js +41 -27
- package/dist/project-FY62G55N.js +70 -0
- package/dist/pty-XTJ4MIWK.js +94 -0
- package/dist/recovery-U6QB3PMT.js +100 -0
- package/dist/reindex-Y27QJFDB.js +22 -0
- package/dist/resume-UU4HZIUP.js +18 -0
- package/dist/run-HALGEJNJ.js +19 -0
- package/dist/run-OGA3P7FC.js +126 -0
- package/dist/serve-NBKT5BKY.js +104 -0
- package/dist/session-XM2CR425.js +159 -0
- package/dist/setup-DTKZLZUT.js +18 -0
- package/dist/start-login-UIQYQBMC.js +416 -0
- package/dist/status-A2OUTNGK.js +9 -0
- package/dist/status-H2VAHIDV.js +10 -0
- package/dist/status-NOOHW5WA.js +43 -0
- package/dist/status-VHODZPXB.js +55 -0
- package/dist/status-XQANBVXW.js +286 -0
- package/dist/stdio.d.ts +3 -13
- package/dist/stdio.js +16 -3186
- package/dist/sweep-64JDCGK6.js +18 -0
- package/dist/test-MKAXFJOL.js +561 -0
- package/dist/tools-gpHNq9Dh.d.ts +328 -0
- package/dist/tui-MWKAXE4K.js +153 -0
- package/dist/unbroadcast-KPUEFLZD.js +18 -0
- package/dist/validate-5GZ5YWNA.js +46 -0
- package/dist/worker-RQ575EJL.js +80 -0
- package/dist/worktree-create-PZSRB7PH.js +89 -0
- package/dist/worktree-list-JYB6VXLW.js +51 -0
- package/dist/worktree-sync-UF5CXPWV.js +30 -0
- package/docs/hooks/capabilities/antigravity.json +199 -0
- package/docs/hooks/capabilities/claude.json +179 -0
- package/docs/hooks/capabilities/codex.json +179 -0
- package/docs/hooks/capabilities/gemini.json +196 -0
- package/docs/hooks/capabilities/grok.json +192 -0
- package/docs/hooks/capabilities/opencode.json +184 -0
- package/docs/project-configuration.md +821 -4
- package/docs/terminal-harness.md +71 -28
- package/docs/terminal-workspace.md +91 -170
- package/gemini-extension.json +1 -1
- package/package.json +13 -1
- package/plugin.json +1 -1
- package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
- package/plugins/pmcp/gemini-extension.json +1 -1
- package/plugins/pmcp/mod/commands.ts +72 -0
- package/plugins/pmcp/mod/contract.d.ts +39 -0
- package/plugins/pmcp/mod/draw.tsx +216 -0
- package/plugins/pmcp/mod/guard.ts +42 -0
- package/plugins/pmcp/mod/hooks.json +4 -0
- package/plugins/pmcp/mod/host.ts +46 -0
- package/plugins/pmcp/mod/model.ts +144 -0
- package/plugins/pmcp/mod/reader/index.ts +18 -0
- package/plugins/pmcp/mod/reader/read.ts +76 -0
- package/plugins/pmcp/mod/reader/settings.ts +54 -0
- package/plugins/pmcp/mod/reader/types.ts +38 -0
- package/plugins/pmcp/mod/register.tsx +73 -0
- package/plugins/pmcp/mod/sessions/format.ts +91 -0
- package/plugins/pmcp/mod/sessions/types.ts +162 -0
- package/plugins/pmcp/mod/snapshot.ts +75 -0
- package/plugins/pmcp/mod/spinner.tsx +30 -0
- package/plugins/pmcp/mod/state.ts +28 -0
- package/plugins/pmcp/plugin.json +1 -1
- package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
- package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -11
- package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +145 -0
- package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +88 -0
- package/schema/catalog-v1.json +158 -0
- package/schema/library.json +164 -0
- package/schema/marketplace-manifest.json +130 -0
- package/schema/plugin-manifest.json +55 -0
- package/schema/skill-frontmatter.json +144 -0
- package/schema/skill-metadata-core.json +110 -0
- package/skills/agent-assets-migrate/SKILL.md +96 -0
- package/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/skills/package-skill-catalog/SKILL.md +51 -11
- package/skills/pmcp-project-init/SKILL.md +145 -0
- package/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/skills/skill-package-scaffold/SKILL.md +88 -0
- package/dist/config-BkSpjUG6.d.ts +0 -50
- package/dist/embed-DRROSD3F.d.ts +0 -53
- package/dist/hook-spec-CSJJySsH.d.ts +0 -11
- package/dist/server-VWSY3Shw.d.ts +0 -543
- package/dist/tui-worker.js +0 -6549
- /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { STATE_PATHS } from "./reader/index";
|
|
2
|
+
import { refresh } from "./snapshot";
|
|
3
|
+
import { PANE_ID, state } from "./state";
|
|
4
|
+
|
|
5
|
+
async function writeState($: any, name: string, value: object): Promise<void> {
|
|
6
|
+
const dir = state.stateDir;
|
|
7
|
+
await $.process.run(["mkdir", "-p", dir]);
|
|
8
|
+
await $.fs.write(`${dir}/${name}`, `${JSON.stringify(value, null, 2)}\n`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function removeState($: any, name: string): Promise<void> {
|
|
12
|
+
await $.process.run(["rm", "-f", `${state.stateDir}/${name}`]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function togglePane($: any): Promise<{ text: string }> {
|
|
16
|
+
if (!state.settings?.sessionsPane)
|
|
17
|
+
return { text: "The sessions pane is off in [ui.claude]." };
|
|
18
|
+
if (state.isOpen) {
|
|
19
|
+
await $.ui.close({ id: PANE_ID });
|
|
20
|
+
state.isOpen = false;
|
|
21
|
+
await refresh($);
|
|
22
|
+
return { text: "Sessions pane closed." };
|
|
23
|
+
}
|
|
24
|
+
await $.ui.open({ id: PANE_ID, title: "Sessions" });
|
|
25
|
+
state.isOpen = true;
|
|
26
|
+
await refresh($);
|
|
27
|
+
return { text: `${state.snapshot.records.length} live session(s).` };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function runCommand(
|
|
31
|
+
$: any,
|
|
32
|
+
args: string,
|
|
33
|
+
): Promise<{ text: string }> {
|
|
34
|
+
if (!state.settings) return { text: "The pmcp mod has not started yet." };
|
|
35
|
+
const [verb = "", ...words] = args.trim().split(/\s+/);
|
|
36
|
+
const since = new Date().toISOString();
|
|
37
|
+
if (verb === "pause") {
|
|
38
|
+
const reason = words.join(" ");
|
|
39
|
+
if (!reason) return { text: "Usage: /pmcp pause <reason>" };
|
|
40
|
+
await writeState($, STATE_PATHS.pause, { by: state.self, reason, since });
|
|
41
|
+
await refresh($);
|
|
42
|
+
return {
|
|
43
|
+
text: `Paused: ${reason}. Other sessions' edits and mutating commands are refused until /pmcp resume.`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (verb === "resume") {
|
|
47
|
+
await removeState($, STATE_PATHS.pause);
|
|
48
|
+
await refresh($);
|
|
49
|
+
return { text: "Resumed." };
|
|
50
|
+
}
|
|
51
|
+
if (verb === "broadcast") {
|
|
52
|
+
const text = words.join(" ");
|
|
53
|
+
if (!text) return { text: "Usage: /pmcp broadcast <text>" };
|
|
54
|
+
const id = `${Date.now()}`;
|
|
55
|
+
await writeState($, STATE_PATHS.broadcast, {
|
|
56
|
+
id,
|
|
57
|
+
by: state.self,
|
|
58
|
+
text,
|
|
59
|
+
since,
|
|
60
|
+
});
|
|
61
|
+
await refresh($);
|
|
62
|
+
return {
|
|
63
|
+
text: "Broadcast sent; every other session sees it at its next prompt.",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (verb === "unbroadcast") {
|
|
67
|
+
await removeState($, STATE_PATHS.broadcast);
|
|
68
|
+
await refresh($);
|
|
69
|
+
return { text: "Broadcast cleared." };
|
|
70
|
+
}
|
|
71
|
+
return togglePane($);
|
|
72
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The state contract the plugin manifest names. The host requires it to be self-contained,
|
|
2
|
+
// so these shapes repeat src/sessions/types.ts and reader/types.ts for the one kept value.
|
|
3
|
+
|
|
4
|
+
export type PmcpRecord = {
|
|
5
|
+
readonly session: string;
|
|
6
|
+
readonly worktree?: string;
|
|
7
|
+
readonly status?: "idle" | "working" | "waiting";
|
|
8
|
+
readonly behind?: number;
|
|
9
|
+
readonly [key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type PmcpSnapshot = {
|
|
13
|
+
readonly records: readonly PmcpRecord[];
|
|
14
|
+
readonly pause: {
|
|
15
|
+
readonly by: string;
|
|
16
|
+
readonly reason: string;
|
|
17
|
+
readonly since: string;
|
|
18
|
+
} | null;
|
|
19
|
+
readonly lease: {
|
|
20
|
+
readonly pid: number;
|
|
21
|
+
readonly subject: string;
|
|
22
|
+
readonly cwd?: string;
|
|
23
|
+
readonly since: string;
|
|
24
|
+
} | null;
|
|
25
|
+
readonly broadcast: {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly by: string;
|
|
28
|
+
readonly text: string;
|
|
29
|
+
readonly since: string;
|
|
30
|
+
} | null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
declare module "claude-code" {
|
|
34
|
+
interface PluginState {
|
|
35
|
+
pmcp: {
|
|
36
|
+
kept: { snapshot: PmcpSnapshot; isOpen: boolean; now: number } | null;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/* @jsxRuntime classic */
|
|
2
|
+
/* @jsx h */
|
|
3
|
+
/* @jsxFrag Fragment */
|
|
4
|
+
|
|
5
|
+
import { runCommand } from "./commands";
|
|
6
|
+
import {
|
|
7
|
+
ageOf,
|
|
8
|
+
bandMark,
|
|
9
|
+
blocking,
|
|
10
|
+
detailOf,
|
|
11
|
+
headline,
|
|
12
|
+
holderOf,
|
|
13
|
+
kindOf,
|
|
14
|
+
labelOf,
|
|
15
|
+
LOOK,
|
|
16
|
+
marksOf,
|
|
17
|
+
nameOf,
|
|
18
|
+
placeOf,
|
|
19
|
+
stuck,
|
|
20
|
+
summaryOf,
|
|
21
|
+
TONE,
|
|
22
|
+
toneOf,
|
|
23
|
+
waitingOf,
|
|
24
|
+
} from "./model";
|
|
25
|
+
import { state } from "./state";
|
|
26
|
+
|
|
27
|
+
const MARKS = 6;
|
|
28
|
+
|
|
29
|
+
export async function drawPane($: any, e: any): Promise<any> {
|
|
30
|
+
const { Box, Text, Button, Client } = await $.ui.resolve(e);
|
|
31
|
+
const { pause, lease, records, broadcast } = state.snapshot;
|
|
32
|
+
const tone = TONE[toneOf(state.snapshot)];
|
|
33
|
+
const columns = Math.max(20, Number(e.props?.bodyColumns ?? 80));
|
|
34
|
+
const now = state.now;
|
|
35
|
+
const nameWidth = Math.max(4, ...records.map((r) => labelOf(r).length));
|
|
36
|
+
const placeWidth = Math.max(5, ...records.map((r) => placeOf(r).length));
|
|
37
|
+
const fixed = 2 + nameWidth + 1 + 8 + placeWidth + 1 + MARKS + 5;
|
|
38
|
+
const actionWidth = Math.max(0, columns - fixed);
|
|
39
|
+
const mark = bandMark(state.snapshot);
|
|
40
|
+
return (
|
|
41
|
+
<Box flexDirection="column">
|
|
42
|
+
<Box flexDirection="row" backgroundColor={tone.background}>
|
|
43
|
+
{mark.spin ? (
|
|
44
|
+
<Client
|
|
45
|
+
key="spin"
|
|
46
|
+
module="./spinner.tsx"
|
|
47
|
+
props={{ color: tone.color, background: tone.background }}
|
|
48
|
+
width={2}
|
|
49
|
+
/>
|
|
50
|
+
) : (
|
|
51
|
+
<Text key="spin" color={tone.color} backgroundColor={tone.background}>
|
|
52
|
+
{mark.glyph}{" "}
|
|
53
|
+
</Text>
|
|
54
|
+
)}
|
|
55
|
+
{pause ? (
|
|
56
|
+
<Text color="error" bold backgroundColor={tone.background}>
|
|
57
|
+
PAUSED
|
|
58
|
+
</Text>
|
|
59
|
+
) : (
|
|
60
|
+
<Text color={tone.color} bold backgroundColor={tone.background}>
|
|
61
|
+
sessions
|
|
62
|
+
</Text>
|
|
63
|
+
)}
|
|
64
|
+
<Text backgroundColor={tone.background}>
|
|
65
|
+
{" "}
|
|
66
|
+
{pause
|
|
67
|
+
? `${pause.reason} · ${ageOf(pause.since, now)} ago`
|
|
68
|
+
: headline(state.snapshot)}
|
|
69
|
+
</Text>
|
|
70
|
+
</Box>
|
|
71
|
+
{lease ? (
|
|
72
|
+
<Text wrap="truncate-end">
|
|
73
|
+
<Text color="warning">◷ lease for {ageOf(lease.since, now)} </Text>
|
|
74
|
+
<Text>by {holderOf(lease, records)} </Text>
|
|
75
|
+
<Text dimColor>{lease.subject}</Text>
|
|
76
|
+
</Text>
|
|
77
|
+
) : null}
|
|
78
|
+
{broadcast ? (
|
|
79
|
+
<Text wrap="truncate-end">
|
|
80
|
+
<Text color="suggestion">» broadcast </Text>
|
|
81
|
+
<Text>{broadcast.text}</Text>
|
|
82
|
+
</Text>
|
|
83
|
+
) : null}
|
|
84
|
+
<Text> </Text>
|
|
85
|
+
{records.length === 0 ? <Text dimColor>No live sessions.</Text> : null}
|
|
86
|
+
{records.map((record) => {
|
|
87
|
+
const look = LOOK[kindOf(record)];
|
|
88
|
+
return (
|
|
89
|
+
<Box key={record.session}>
|
|
90
|
+
<Text wrap="truncate-end">
|
|
91
|
+
<Text color={look.color}>{look.glyph} </Text>
|
|
92
|
+
<Text bold={record.session === state.self}>
|
|
93
|
+
{labelOf(record).padEnd(nameWidth)}{" "}
|
|
94
|
+
</Text>
|
|
95
|
+
<Text color={look.color}>{look.word.padEnd(8)}</Text>
|
|
96
|
+
<Text dimColor>{placeOf(record).padEnd(placeWidth)} </Text>
|
|
97
|
+
<Text color="warning">{marksOf(record).padEnd(MARKS)}</Text>
|
|
98
|
+
<Text dimColor>
|
|
99
|
+
{ageOf(record.updatedAt, now).padStart(4)}{" "}
|
|
100
|
+
{detailOf(record).slice(0, actionWidth)}
|
|
101
|
+
</Text>
|
|
102
|
+
</Text>
|
|
103
|
+
</Box>
|
|
104
|
+
);
|
|
105
|
+
})}
|
|
106
|
+
<Text> </Text>
|
|
107
|
+
{pause ? (
|
|
108
|
+
<Button
|
|
109
|
+
key="resume"
|
|
110
|
+
label="Resume sessions"
|
|
111
|
+
onPress={() => runCommand($, "resume")}
|
|
112
|
+
/>
|
|
113
|
+
) : (
|
|
114
|
+
<Text dimColor>
|
|
115
|
+
/pmcp pause <reason> · /pmcp broadcast <text>
|
|
116
|
+
</Text>
|
|
117
|
+
)}
|
|
118
|
+
</Box>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function row(key: string, Box: any, Text: any, children: any): any {
|
|
123
|
+
return (
|
|
124
|
+
<Box key={key}>
|
|
125
|
+
<Text wrap="truncate-end">{children}</Text>
|
|
126
|
+
</Box>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function drawBand($: any, e: any, next: any): Promise<any> {
|
|
131
|
+
if (e.props?.hasSurvey) return next(e);
|
|
132
|
+
const { pause, lease, records } = state.snapshot;
|
|
133
|
+
const waiting = blocking(records);
|
|
134
|
+
const heard = state.snapshot.broadcast;
|
|
135
|
+
const broadcast = heard?.by === state.self ? null : heard;
|
|
136
|
+
const held = lease && stuck(lease) ? lease : null;
|
|
137
|
+
const { Box, Text, Client } = await $.ui.resolve(e);
|
|
138
|
+
const tone = TONE[toneOf(state.snapshot)];
|
|
139
|
+
const mark = bandMark(state.snapshot);
|
|
140
|
+
const rows = [];
|
|
141
|
+
const summary = (
|
|
142
|
+
<Box key="summary" flexDirection="row" backgroundColor={tone.background}>
|
|
143
|
+
{mark.spin ? (
|
|
144
|
+
<Client
|
|
145
|
+
key="spin"
|
|
146
|
+
module="./spinner.tsx"
|
|
147
|
+
props={{ color: tone.color, background: tone.background }}
|
|
148
|
+
width={2}
|
|
149
|
+
/>
|
|
150
|
+
) : (
|
|
151
|
+
<Text key="spin" color={tone.color} backgroundColor={tone.background}>
|
|
152
|
+
{mark.glyph}{" "}
|
|
153
|
+
</Text>
|
|
154
|
+
)}
|
|
155
|
+
<Text wrap="truncate-end" backgroundColor={tone.background}>
|
|
156
|
+
<Text bold color={tone.color}>
|
|
157
|
+
pmcp{" "}
|
|
158
|
+
</Text>
|
|
159
|
+
<Text>{summaryOf(state.snapshot)}</Text>
|
|
160
|
+
<Text dimColor> · /pmcp </Text>
|
|
161
|
+
</Text>
|
|
162
|
+
</Box>
|
|
163
|
+
);
|
|
164
|
+
if (pause) {
|
|
165
|
+
rows.push(
|
|
166
|
+
row("pause", Box, Text, [
|
|
167
|
+
<Text key="mark" color="error" bold>
|
|
168
|
+
■ paused{" "}
|
|
169
|
+
</Text>,
|
|
170
|
+
<Text key="reason">{pause.reason}</Text>,
|
|
171
|
+
<Text key="hint" dimColor>
|
|
172
|
+
{" "}
|
|
173
|
+
· /pmcp resume
|
|
174
|
+
</Text>,
|
|
175
|
+
]),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (waiting.length > 0) {
|
|
179
|
+
const names = waiting.map((r) => `${nameOf(r)} (${waitingOf(r)})`);
|
|
180
|
+
rows.push(
|
|
181
|
+
row("asking", Box, Text, [
|
|
182
|
+
<Text key="mark" color="permission" bold>
|
|
183
|
+
◆ asking{" "}
|
|
184
|
+
</Text>,
|
|
185
|
+
<Text key="names">{names.join(", ")}</Text>,
|
|
186
|
+
]),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (held) {
|
|
190
|
+
rows.push(
|
|
191
|
+
row("lease", Box, Text, [
|
|
192
|
+
<Text key="mark" color="warning">
|
|
193
|
+
◷ lease held for {ageOf(held.since, state.now)}{" "}
|
|
194
|
+
</Text>,
|
|
195
|
+
<Text key="holder">by {holderOf(held, records)} </Text>,
|
|
196
|
+
<Text key="subject" dimColor>
|
|
197
|
+
{held.subject}
|
|
198
|
+
</Text>,
|
|
199
|
+
]),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (broadcast) {
|
|
203
|
+
rows.push(
|
|
204
|
+
row("broadcast", Box, Text, [
|
|
205
|
+
<Text key="mark" color="suggestion">
|
|
206
|
+
» broadcast{" "}
|
|
207
|
+
</Text>,
|
|
208
|
+
<Text key="text">{broadcast.text}</Text>,
|
|
209
|
+
]),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
// Prioritize actionable states because narrow status bands cannot display every summary.
|
|
213
|
+
const room = Math.max(1, Number(e.props?.maxRows ?? rows.length + 1));
|
|
214
|
+
const shown = room > rows.length ? [summary, ...rows] : rows.slice(0, room);
|
|
215
|
+
return <Box flexDirection="column">{shown}</Box>;
|
|
216
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Leave foreign-edit decisions to the person because the mod must not enforce independent policy.
|
|
2
|
+
import { nameOf } from "./model";
|
|
3
|
+
import type { SessionRecord } from "./reader/index";
|
|
4
|
+
import { state } from "./state";
|
|
5
|
+
|
|
6
|
+
function checkoutOf(target: string, records: readonly SessionRecord[]): string {
|
|
7
|
+
let best = "";
|
|
8
|
+
for (const record of records) {
|
|
9
|
+
const root = record.worktree ?? "";
|
|
10
|
+
if (root && target.startsWith(`${root}/`) && root.length > best.length) {
|
|
11
|
+
best = root;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const desk = /^(.*\/\.claude\/worktrees\/[^/]+)\//.exec(target)?.[1] ?? "";
|
|
15
|
+
return desk.length > best.length ? desk : best;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function holdForeignEdit($: any, e: any, next: any): Promise<any> {
|
|
19
|
+
const target = String(e.file_path ?? e.notebook_path ?? "");
|
|
20
|
+
const records = state.snapshot.records;
|
|
21
|
+
const mine = records.find((r) => r.session === state.self)?.worktree;
|
|
22
|
+
const checkout = checkoutOf(target, records);
|
|
23
|
+
// Choose the innermost checkout because linked worktrees may be nested under the main checkout.
|
|
24
|
+
const owner = records.find(
|
|
25
|
+
(r) =>
|
|
26
|
+
r.session !== state.self && r.worktree === checkout && checkout !== mine,
|
|
27
|
+
);
|
|
28
|
+
if (!owner) return next(e);
|
|
29
|
+
try {
|
|
30
|
+
const answer = await $.ui.ask(
|
|
31
|
+
`${nameOf(owner)} works in ${owner.worktree}. Edit ${target} anyway?`,
|
|
32
|
+
["Edit", "Cancel"],
|
|
33
|
+
);
|
|
34
|
+
if (answer === "Edit") return next(e);
|
|
35
|
+
} catch {
|
|
36
|
+
// Leave noninteractive warnings to hooks because no person is available for a mod prompt.
|
|
37
|
+
return next(e);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
deny: `${nameOf(owner)} works in ${owner.worktree}; the person declined this edit.`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseUiSettings, UI_SETTINGS_FILE } from "./reader/index";
|
|
2
|
+
import type { StateFiles, UiSettings } from "./reader/index";
|
|
3
|
+
|
|
4
|
+
export function hostFiles($: any): StateFiles {
|
|
5
|
+
return {
|
|
6
|
+
exists: async (path) => Boolean(await $.fs.exists(path)),
|
|
7
|
+
read: async (path) => String(await $.fs.read(path)),
|
|
8
|
+
list: async (directory) => {
|
|
9
|
+
const entries = (await $.fs.list(directory).catch(() => [])) as any[];
|
|
10
|
+
return entries.map((entry) => String(entry.name));
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Ask the projected hook for state location so mod and hook readers cannot diverge.
|
|
16
|
+
export async function resolveStateDir(
|
|
17
|
+
$: any,
|
|
18
|
+
root: string,
|
|
19
|
+
settings: UiSettings,
|
|
20
|
+
): Promise<string> {
|
|
21
|
+
if (settings.stateDir) return settings.stateDir;
|
|
22
|
+
const hook = `${root}/.agents/pmcp-hooks/hook.mjs`;
|
|
23
|
+
if (!(await $.fs.exists(hook))) return "";
|
|
24
|
+
const run = await $.process
|
|
25
|
+
.run(["node", hook, "--state-dir"])
|
|
26
|
+
.catch(() => null);
|
|
27
|
+
if (!run || run.exitCode !== 0) return "";
|
|
28
|
+
return String(run.stdout).trim();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function findSettings(
|
|
32
|
+
$: any,
|
|
33
|
+
cwd: string,
|
|
34
|
+
): Promise<{ root: string; settings: UiSettings } | null> {
|
|
35
|
+
let directory = cwd.replace(/\/+$/, "");
|
|
36
|
+
while (directory) {
|
|
37
|
+
const path = `${directory}/${UI_SETTINGS_FILE}`;
|
|
38
|
+
if (await $.fs.exists(path)) {
|
|
39
|
+
const source = String(await $.fs.read(path).catch(() => ""));
|
|
40
|
+
const settings = parseUiSettings(source, directory);
|
|
41
|
+
return settings ? { root: directory, settings } : null;
|
|
42
|
+
}
|
|
43
|
+
directory = directory.replace(/\/[^/]*$/, "");
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Lease, SessionRecord, SessionSnapshot } from "./reader/index";
|
|
2
|
+
import { LEASE_STUCK_MS, state } from "./state";
|
|
3
|
+
|
|
4
|
+
export type Kind = "asking" | "working" | "idle";
|
|
5
|
+
|
|
6
|
+
export const LOOK: {
|
|
7
|
+
[K in Kind]: { glyph: string; word: string; color: string };
|
|
8
|
+
} = {
|
|
9
|
+
asking: { glyph: "◆", word: "asking", color: "permission" },
|
|
10
|
+
working: { glyph: "●", word: "working", color: "claude" },
|
|
11
|
+
idle: { glyph: "○", word: "idle", color: "inactive" },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ORDER: Kind[] = ["asking", "working", "idle"];
|
|
15
|
+
|
|
16
|
+
const WAITING: { [key: string]: string } = {
|
|
17
|
+
permission_prompt: "permission",
|
|
18
|
+
agent_needs_input: "question",
|
|
19
|
+
idle_prompt: "done",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function nameOf(record: SessionRecord): string {
|
|
23
|
+
return record.alias || record.session.slice(0, 8);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function kindOf(record: SessionRecord): Kind {
|
|
27
|
+
if (record.status === "waiting" && record.waiting !== "idle_prompt")
|
|
28
|
+
return "asking";
|
|
29
|
+
if (record.status === "working") return "working";
|
|
30
|
+
return "idle";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function blocking(records: readonly SessionRecord[]): SessionRecord[] {
|
|
34
|
+
return records.filter(
|
|
35
|
+
(r) => kindOf(r) === "asking" && r.session !== state.self,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function stuck(lease: Lease): boolean {
|
|
40
|
+
return state.now - Date.parse(lease.since ?? "") > LEASE_STUCK_MS;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// An empty reason is still a question; older records carry no notification type.
|
|
44
|
+
export function waitingOf(record: SessionRecord): string {
|
|
45
|
+
return WAITING[record.waiting ?? ""] ?? (record.waiting || "input");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Name the session whose runtime holds the lease, else the one session working in its cwd.
|
|
49
|
+
export function holderOf(
|
|
50
|
+
lease: Lease,
|
|
51
|
+
records: readonly SessionRecord[],
|
|
52
|
+
): string {
|
|
53
|
+
const byPid = records.find((r) => r.pid === lease.pid);
|
|
54
|
+
if (byPid) return nameOf(byPid);
|
|
55
|
+
const here = records.filter((r) => lease.cwd && r.worktree === lease.cwd);
|
|
56
|
+
if (here.length === 1) return nameOf(here[0]!);
|
|
57
|
+
return `pid ${lease.pid}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function labelOf(record: SessionRecord): string {
|
|
61
|
+
if (record.session === state.self) return `${nameOf(record)} (you)`;
|
|
62
|
+
return nameOf(record);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function byKind(a: SessionRecord, b: SessionRecord): number {
|
|
66
|
+
const order = ORDER.indexOf(kindOf(a)) - ORDER.indexOf(kindOf(b));
|
|
67
|
+
if (order !== 0) return order;
|
|
68
|
+
return labelOf(a).localeCompare(labelOf(b));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A desk is named by its directory: detached linked worktrees have no branch to show.
|
|
72
|
+
export function placeOf(record: SessionRecord): string {
|
|
73
|
+
const worktree = record.worktree ?? "";
|
|
74
|
+
const desk = /\/\.claude\/worktrees\/([^/]+)\/?$/u.exec(worktree)?.[1];
|
|
75
|
+
if (desk) return desk;
|
|
76
|
+
if (record.branch) return record.branch;
|
|
77
|
+
return worktree.replace(/\/+$/u, "").split("/").pop() || "-";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function detailOf(record: SessionRecord): string {
|
|
81
|
+
if (kindOf(record) === "asking") return waitingOf(record);
|
|
82
|
+
return record.lastAction ?? "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function marksOf(record: SessionRecord): string {
|
|
86
|
+
return record.behind ? `↓${record.behind}` : "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The band animates only while a session works, the same signal the pane's working rows use.
|
|
90
|
+
export function bandMark(snapshot: SessionSnapshot): {
|
|
91
|
+
spin: boolean;
|
|
92
|
+
glyph: string;
|
|
93
|
+
} {
|
|
94
|
+
const spin = snapshot.records.some((r) => kindOf(r) === "working");
|
|
95
|
+
return { spin, glyph: spin ? LOOK.working.glyph : LOOK.idle.glyph };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type Tone = "paused" | "asking" | "leased" | "working" | "idle";
|
|
99
|
+
|
|
100
|
+
export function toneOf(snapshot: SessionSnapshot): Tone {
|
|
101
|
+
if (snapshot.pause) return "paused";
|
|
102
|
+
if (blocking(snapshot.records).length > 0) return "asking";
|
|
103
|
+
if (snapshot.lease) return "leased";
|
|
104
|
+
if (snapshot.records.some((r) => kindOf(r) === "working")) return "working";
|
|
105
|
+
return "idle";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const TONE: { [T in Tone]: { color: string; background: string } } = {
|
|
109
|
+
paused: { color: "error", background: "#3a1d22" },
|
|
110
|
+
asking: { color: "permission", background: "#2e2640" },
|
|
111
|
+
leased: { color: "warning", background: "#332b17" },
|
|
112
|
+
working: { color: "claude", background: "#2b2420" },
|
|
113
|
+
idle: { color: "inactive", background: "#22252b" },
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export function ageOf(stamp: string | undefined, now: number): string {
|
|
117
|
+
const seconds = Math.max(
|
|
118
|
+
0,
|
|
119
|
+
Math.round((now - Date.parse(stamp ?? "")) / 1000),
|
|
120
|
+
);
|
|
121
|
+
if (!Number.isFinite(seconds)) return "";
|
|
122
|
+
if (seconds < 60) return `${seconds}s`;
|
|
123
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;
|
|
124
|
+
return `${Math.floor(seconds / 3600)}h`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function headline(snapshot: SessionSnapshot): string {
|
|
128
|
+
const { records } = snapshot;
|
|
129
|
+
const asking = records.filter((r) => kindOf(r) === "asking").length;
|
|
130
|
+
const working = records.filter((r) => kindOf(r) === "working").length;
|
|
131
|
+
const parts = [`${records.length} session${records.length === 1 ? "" : "s"}`];
|
|
132
|
+
if (asking > 0) parts.push(`${asking} asking`);
|
|
133
|
+
if (working > 0) parts.push(`${working} working`);
|
|
134
|
+
return parts.join(" · ");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function summaryOf(snapshot: SessionSnapshot): string {
|
|
138
|
+
const parts = [headline(snapshot)];
|
|
139
|
+
const behind = snapshot.records.filter((r) => (r.behind ?? 0) > 0).length;
|
|
140
|
+
if (behind > 0) parts.push(`${behind} behind`);
|
|
141
|
+
if (snapshot.lease) parts.push(`lease: ${snapshot.lease.subject}`);
|
|
142
|
+
if (snapshot.broadcast) parts.push("broadcast");
|
|
143
|
+
return parts.join(" · ");
|
|
144
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
isAlive,
|
|
3
|
+
readRecords,
|
|
4
|
+
readSessionState,
|
|
5
|
+
STALE_MS,
|
|
6
|
+
STATE_PATHS,
|
|
7
|
+
} from "./read";
|
|
8
|
+
export { parseUiSettings, UI_SETTINGS_FILE } from "./settings";
|
|
9
|
+
export type {
|
|
10
|
+
Broadcast,
|
|
11
|
+
Lease,
|
|
12
|
+
Pause,
|
|
13
|
+
ReadOptions,
|
|
14
|
+
SessionRecord,
|
|
15
|
+
SessionSnapshot,
|
|
16
|
+
StateFiles,
|
|
17
|
+
UiSettings,
|
|
18
|
+
} from "./types";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asBroadcast,
|
|
3
|
+
asLease,
|
|
4
|
+
asPause,
|
|
5
|
+
asRecord,
|
|
6
|
+
leaseFile,
|
|
7
|
+
recordLive,
|
|
8
|
+
STATE_FILES,
|
|
9
|
+
} from "../sessions/format";
|
|
10
|
+
import type {
|
|
11
|
+
ReadOptions,
|
|
12
|
+
SessionRecord,
|
|
13
|
+
SessionSnapshot,
|
|
14
|
+
StateFiles,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
export { STALE_MS } from "../sessions/format";
|
|
18
|
+
|
|
19
|
+
export const STATE_PATHS = {
|
|
20
|
+
records: STATE_FILES.records,
|
|
21
|
+
pause: STATE_FILES.pause,
|
|
22
|
+
lease: leaseFile("lockfile"),
|
|
23
|
+
broadcast: STATE_FILES.broadcast,
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
function parse(text: string): unknown {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(text);
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function readJson(files: StateFiles, path: string): Promise<unknown> {
|
|
35
|
+
if (!(await files.exists(path))) return null;
|
|
36
|
+
return parse(await files.read(path).catch(() => ""));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function isAlive(
|
|
40
|
+
files: StateFiles,
|
|
41
|
+
pid: unknown,
|
|
42
|
+
): Promise<boolean> {
|
|
43
|
+
const value = Number(pid);
|
|
44
|
+
if (!Number.isInteger(value) || value <= 0) return false;
|
|
45
|
+
return files.exists(`/proc/${value}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function readRecords(
|
|
49
|
+
files: StateFiles,
|
|
50
|
+
options: ReadOptions,
|
|
51
|
+
): Promise<SessionRecord[]> {
|
|
52
|
+
const directory = `${options.stateDir}/${STATE_PATHS.records}`;
|
|
53
|
+
const names = await files.list(directory).catch(() => [] as string[]);
|
|
54
|
+
const records: SessionRecord[] = [];
|
|
55
|
+
for (const name of names.filter((item) => item.endsWith(".json")).sort()) {
|
|
56
|
+
const record = asRecord(await readJson(files, `${directory}/${name}`));
|
|
57
|
+
if (!record) continue;
|
|
58
|
+
const pidAlive = await isAlive(files, record.pid);
|
|
59
|
+
if (recordLive(record, options.now, pidAlive)) records.push(record);
|
|
60
|
+
}
|
|
61
|
+
return records;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function readSessionState(
|
|
65
|
+
files: StateFiles,
|
|
66
|
+
options: ReadOptions,
|
|
67
|
+
): Promise<SessionSnapshot> {
|
|
68
|
+
const at = (name: string) => `${options.stateDir}/${name}`;
|
|
69
|
+
const lease = asLease(await readJson(files, at(STATE_PATHS.lease)));
|
|
70
|
+
return {
|
|
71
|
+
records: await readRecords(files, options),
|
|
72
|
+
pause: asPause(await readJson(files, at(STATE_PATHS.pause))),
|
|
73
|
+
lease: lease && (await isAlive(files, lease.pid)) ? lease : null,
|
|
74
|
+
broadcast: asBroadcast(await readJson(files, at(STATE_PATHS.broadcast))),
|
|
75
|
+
};
|
|
76
|
+
}
|