@h-rig/run-plugin 0.0.6-alpha.186

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.
Files changed (70) hide show
  1. package/README.md +1 -0
  2. package/dist/src/plugin.d.ts +4 -0
  3. package/dist/src/plugin.js +4319 -0
  4. package/dist/src/read-model/inspect-command.d.ts +19 -0
  5. package/dist/src/read-model/inspect-command.js +341 -0
  6. package/dist/src/read-model/plugin.d.ts +4 -0
  7. package/dist/src/read-model/plugin.js +2550 -0
  8. package/dist/src/read-model/read-model-backend/diagnostics.d.ts +9 -0
  9. package/dist/src/read-model/read-model-backend/diagnostics.js +51 -0
  10. package/dist/src/read-model/read-model-backend/guard.d.ts +4 -0
  11. package/dist/src/read-model/read-model-backend/guard.js +25 -0
  12. package/dist/src/read-model/read-model-backend/inbox.d.ts +23 -0
  13. package/dist/src/read-model/read-model-backend/inbox.js +669 -0
  14. package/dist/src/read-model/read-model-backend/index.d.ts +8 -0
  15. package/dist/src/read-model/read-model-backend/index.js +1163 -0
  16. package/dist/src/read-model/read-model-backend/inspect.d.ts +26 -0
  17. package/dist/src/read-model/read-model-backend/inspect.js +770 -0
  18. package/dist/src/read-model/read-model-backend/projection.d.ts +39 -0
  19. package/dist/src/read-model/read-model-backend/projection.js +669 -0
  20. package/dist/src/read-model/read-model-backend/run-status.d.ts +27 -0
  21. package/dist/src/read-model/read-model-backend/run-status.js +237 -0
  22. package/dist/src/read-model/read-model-backend/stats.d.ts +12 -0
  23. package/dist/src/read-model/read-model-backend/stats.js +800 -0
  24. package/dist/src/read-model/read-model-service.d.ts +2 -0
  25. package/dist/src/read-model/read-model-service.js +1725 -0
  26. package/dist/src/read-model/reconcile.d.ts +23 -0
  27. package/dist/src/read-model/reconcile.js +306 -0
  28. package/dist/src/read-model/run-format.d.ts +23 -0
  29. package/dist/src/read-model/run-format.js +202 -0
  30. package/dist/src/read-model/runs-screen.d.ts +14 -0
  31. package/dist/src/read-model/runs-screen.js +217 -0
  32. package/dist/src/read-model/session-journal.d.ts +26 -0
  33. package/dist/src/read-model/session-journal.js +355 -0
  34. package/dist/src/read-model/stats-command.d.ts +16 -0
  35. package/dist/src/read-model/stats-command.js +88 -0
  36. package/dist/src/read-model/stats-format.d.ts +1 -0
  37. package/dist/src/read-model/stats-format.js +8 -0
  38. package/dist/src/worker/autohost.d.ts +11 -0
  39. package/dist/src/worker/autohost.js +858 -0
  40. package/dist/src/worker/constants.d.ts +3 -0
  41. package/dist/src/worker/constants.js +10 -0
  42. package/dist/src/worker/extension.d.ts +14 -0
  43. package/dist/src/worker/extension.js +881 -0
  44. package/dist/src/worker/host.d.ts +1 -0
  45. package/dist/src/worker/host.js +1 -0
  46. package/dist/src/worker/inbox-command.d.ts +23 -0
  47. package/dist/src/worker/inbox-command.js +163 -0
  48. package/dist/src/worker/index.d.ts +2 -0
  49. package/dist/src/worker/index.js +1767 -0
  50. package/dist/src/worker/local-run-changes.d.ts +3 -0
  51. package/dist/src/worker/local-run-changes.js +65 -0
  52. package/dist/src/worker/notifications.d.ts +1 -0
  53. package/dist/src/worker/notifications.js +27 -0
  54. package/dist/src/worker/notify-cap.d.ts +11 -0
  55. package/dist/src/worker/notify-cap.js +13 -0
  56. package/dist/src/worker/panel-plugin.d.ts +11 -0
  57. package/dist/src/worker/panel-plugin.js +37 -0
  58. package/dist/src/worker/plugin.d.ts +3 -0
  59. package/dist/src/worker/plugin.js +1761 -0
  60. package/dist/src/worker/run-control-service.d.ts +2 -0
  61. package/dist/src/worker/run-control-service.js +210 -0
  62. package/dist/src/worker/session-journal-writer.d.ts +4 -0
  63. package/dist/src/worker/session-journal-writer.js +184 -0
  64. package/dist/src/worker/stall.d.ts +21 -0
  65. package/dist/src/worker/stall.js +55 -0
  66. package/dist/src/worker/utils.d.ts +21 -0
  67. package/dist/src/worker/utils.js +29 -0
  68. package/dist/src/worker/workflow-journal-writer.d.ts +7 -0
  69. package/dist/src/worker/workflow-journal-writer.js +76 -0
  70. package/package.json +47 -0
@@ -0,0 +1,88 @@
1
+ // @bun
2
+ // packages/run-plugin/src/read-model/stats-command.ts
3
+ import { RUN_READ_MODEL } from "@rig/contracts";
4
+ import { defineCapability } from "@rig/core/capability";
5
+ import { requireCapabilityForRoot } from "@rig/core/capability-loaders";
6
+ import { CliError, requireNoExtraArgs, takeOption } from "@rig/std-shared/cli-args";
7
+
8
+ // packages/run-plugin/src/read-model/stats-format.ts
9
+ function formatRatePercent(value) {
10
+ return value === null ? "\u2014" : `${Math.round(value * 100)}%`;
11
+ }
12
+
13
+ // packages/run-plugin/src/read-model/stats-command.ts
14
+ import { formatStatsTable, printFormattedOutput } from "@rig/std-shared/cli-format";
15
+ var DAY_MS = 24 * 60 * 60 * 1000;
16
+ var STATS_USAGE = "rig stats [show] [--since <7d|30d|ISO date>]";
17
+ var RunReadModelCap = defineCapability(RUN_READ_MODEL);
18
+ function parseSinceOption(value, now = new Date) {
19
+ if (!value?.trim())
20
+ return null;
21
+ const trimmed = value.trim();
22
+ const relative = trimmed.match(/^(\d+)d$/i);
23
+ if (relative?.[1]) {
24
+ const days = Number.parseInt(relative[1], 10);
25
+ if (!Number.isFinite(days) || days <= 0)
26
+ throw new CliError(`Invalid --since value: ${value}`, 2, { hint: "Use an ISO date or a relative window like `7d`." });
27
+ return new Date(now.getTime() - days * DAY_MS);
28
+ }
29
+ const parsed = Date.parse(trimmed);
30
+ if (!Number.isFinite(parsed))
31
+ throw new CliError(`Invalid --since value: ${value}`, 2, { hint: "Use an ISO date or a relative window like `7d`." });
32
+ return new Date(parsed);
33
+ }
34
+ function formatDuration(ms) {
35
+ if (ms === null)
36
+ return "\u2014";
37
+ const seconds = Math.round(ms / 1000);
38
+ if (seconds < 60)
39
+ return `${seconds}s`;
40
+ const minutes = Math.round(ms / 60000);
41
+ if (minutes < 60)
42
+ return `${minutes}m`;
43
+ const hours = Math.floor(minutes / 60);
44
+ const remainder = minutes % 60;
45
+ return remainder === 0 ? `${hours}h` : `${hours}h ${remainder}m`;
46
+ }
47
+ function formatStatsRows(stats) {
48
+ return [
49
+ ["window", stats.since ? `since ${stats.since}` : "all runs"],
50
+ ["total runs", stats.totalRuns],
51
+ ["completed", `${stats.completedRuns} (${formatRatePercent(stats.completionRate)})`],
52
+ ["failed", `${stats.failedRuns} (${formatRatePercent(stats.failureRate)})`],
53
+ ["needs attention", `${stats.needsAttentionRuns} (${formatRatePercent(stats.needsAttentionRate)})`],
54
+ ["median run time", formatDuration(stats.medianCompletionMs)],
55
+ ["steering", stats.steeringTotal],
56
+ ["stalls", stats.stallTotal],
57
+ ["pending approvals", stats.approvalsPending]
58
+ ];
59
+ }
60
+ async function executeStats(context, args, deps = {}) {
61
+ const list = [...args];
62
+ const [first = "show", ...rest] = list;
63
+ const command = first.startsWith("-") ? "show" : first;
64
+ const commandArgs = first.startsWith("-") ? list : rest;
65
+ if (command === "help") {
66
+ printFormattedOutput(`Usage: ${STATS_USAGE}`);
67
+ return { ok: true, group: "stats", command };
68
+ }
69
+ if (command !== "show")
70
+ throw new CliError(`Unknown stats command: ${command}`, 1, { hint: "Run `rig stats --help` \u2014 the default command is `show`." });
71
+ const sinceResult = takeOption(commandArgs, "--since");
72
+ requireNoExtraArgs(sinceResult.rest, STATS_USAGE);
73
+ const since = parseSinceOption(sinceResult.value);
74
+ const readModel = await requireCapabilityForRoot(context.projectRoot, RunReadModelCap, "RUN_READ_MODEL capability unavailable for this project root: load @rig/run-plugin (standard bundle).");
75
+ const details = await readModel.getStats({
76
+ projectRoot: context.projectRoot,
77
+ since: since ? since.toISOString() : null,
78
+ ...deps.listRuns ? { runs: await deps.listRuns(context.projectRoot) } : {}
79
+ });
80
+ if ((context.outputMode ?? "text") === "text")
81
+ printFormattedOutput(formatStatsTable(formatStatsRows(details)));
82
+ return { ok: true, group: "stats", command, details };
83
+ }
84
+ export {
85
+ parseSinceOption,
86
+ formatStatsRows,
87
+ executeStats
88
+ };
@@ -0,0 +1 @@
1
+ export declare function formatRatePercent(value: number | null): string;
@@ -0,0 +1,8 @@
1
+ // @bun
2
+ // packages/run-plugin/src/read-model/stats-format.ts
3
+ function formatRatePercent(value) {
4
+ return value === null ? "\u2014" : `${Math.round(value * 100)}%`;
5
+ }
6
+ export {
7
+ formatRatePercent
8
+ };
@@ -0,0 +1,11 @@
1
+ import type { ExtensionAPI, ExtensionContext, AgentEndEvent } from "@oh-my-pi/pi-coding-agent";
2
+ import { type RunControlIntake, type RunSessionJournalCodec } from "@rig/contracts";
3
+ export interface RunProcessWorkerHooks {
4
+ readonly beforeAgentStart: () => void;
5
+ readonly messageStart: () => void;
6
+ readonly agentEnd: (event: AgentEndEvent) => Promise<void>;
7
+ }
8
+ export declare const REGISTRY_PROJECTION_TIMELINE_LIMIT = 100;
9
+ export declare function detectRunControlText(codec: RunSessionJournalCodec, text: string, runId: string): RunControlIntake | null;
10
+ export declare function maybeStartRunProcessAutohost(api: ExtensionAPI, ctx: ExtensionContext): Promise<RunProcessWorkerHooks | null>;
11
+ export declare function maybeStartSpikeAutohost(ctx: ExtensionContext): Promise<void>;