@ftrdotdev/pi-delegates 0.0.0-stage → 0.1.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/OPERATIONS.md +57 -0
  4. package/README.md +448 -2
  5. package/ROADMAP.md +158 -0
  6. package/TESTING.md +1061 -0
  7. package/agents.ts +8 -0
  8. package/examples/README.md +114 -0
  9. package/examples/gated.ts +28 -0
  10. package/index.ts +9 -0
  11. package/package.json +93 -4
  12. package/skills/pi-delegates/SKILL.md +147 -0
  13. package/skills/pi-delegates/references/control.md +159 -0
  14. package/skills/pi-delegates/references/definitions.md +163 -0
  15. package/skills/pi-delegates/references/gates.md +175 -0
  16. package/skills/pi-delegates/references/launch.md +156 -0
  17. package/src/domain/definitions.test.ts +41 -0
  18. package/src/domain/definitions.ts +161 -0
  19. package/src/domain/ids.ts +13 -0
  20. package/src/domain/names.ts +35 -0
  21. package/src/domain/orchestration/admission.ts +78 -0
  22. package/src/domain/orchestration/control.test.ts +1298 -0
  23. package/src/domain/orchestration/control.ts +436 -0
  24. package/src/domain/orchestration/fanout.test.ts +419 -0
  25. package/src/domain/orchestration/fanout.ts +334 -0
  26. package/src/domain/orchestration/gates.test.ts +686 -0
  27. package/src/domain/orchestration/gates.ts +360 -0
  28. package/src/domain/orchestration/launch.test.ts +173 -0
  29. package/src/domain/orchestration/launch.ts +581 -0
  30. package/src/domain/orchestration/requests.test.ts +700 -0
  31. package/src/domain/orchestration/requests.ts +769 -0
  32. package/src/domain/orchestration/review.test.ts +214 -0
  33. package/src/domain/orchestration/review.ts +168 -0
  34. package/src/domain/orchestration/run-wait.test.ts +262 -0
  35. package/src/domain/orchestration/run-wait.ts +256 -0
  36. package/src/domain/orchestration/workflow-section.test.ts +62 -0
  37. package/src/domain/orchestration/workflow-section.ts +99 -0
  38. package/src/domain/orchestration/workflow.test.ts +1425 -0
  39. package/src/domain/orchestration/workflow.ts +705 -0
  40. package/src/domain/run-records.test.ts +27 -0
  41. package/src/domain/run-records.ts +527 -0
  42. package/src/domain/shapes.test.ts +165 -0
  43. package/src/domain/skills.test.ts +466 -0
  44. package/src/domain/skills.ts +97 -0
  45. package/src/domain/tool-schema.test.ts +46 -0
  46. package/src/domain/tool-schema.ts +20 -0
  47. package/src/domain/toolkit.test.ts +201 -0
  48. package/src/domain/toolkit.ts +379 -0
  49. package/src/domain/view.test.ts +739 -0
  50. package/src/domain/view.ts +459 -0
  51. package/src/example.test.ts +15 -0
  52. package/src/extension/commands.test.ts +481 -0
  53. package/src/extension/commands.ts +227 -0
  54. package/src/extension/entry.test.ts +1118 -0
  55. package/src/extension/entry.ts +342 -0
  56. package/src/extension/gate-alerts.test.ts +235 -0
  57. package/src/extension/gate-alerts.ts +143 -0
  58. package/src/extension/guard.test.ts +48 -0
  59. package/src/extension/guard.ts +31 -0
  60. package/src/extension/host-signals.test.ts +20 -0
  61. package/src/extension/host-signals.ts +13 -0
  62. package/src/extension/inspector-command.test.ts +1191 -0
  63. package/src/extension/inspector-command.ts +638 -0
  64. package/src/extension/prompt.test.ts +110 -0
  65. package/src/extension/prompt.ts +50 -0
  66. package/src/extension/request-alerts.test.ts +183 -0
  67. package/src/extension/request-alerts.ts +181 -0
  68. package/src/extension/revocation.test.ts +81 -0
  69. package/src/extension/revocation.ts +84 -0
  70. package/src/extension/shortcut.test.ts +64 -0
  71. package/src/extension/shortcut.ts +105 -0
  72. package/src/extension/tools.test.ts +993 -0
  73. package/src/extension/tools.ts +505 -0
  74. package/src/extension/version.test.ts +123 -0
  75. package/src/extension/version.ts +97 -0
  76. package/src/harness-policy.test.ts +74 -0
  77. package/src/package-manifest.test.ts +157 -0
  78. package/src/presentation/actions.test.ts +221 -0
  79. package/src/presentation/actions.ts +85 -0
  80. package/src/presentation/activity.test.ts +387 -0
  81. package/src/presentation/activity.ts +66 -0
  82. package/src/presentation/close.test.ts +361 -0
  83. package/src/presentation/inspector.test.ts +679 -0
  84. package/src/presentation/inspector.ts +440 -0
  85. package/src/presentation/overlay.test.ts +555 -0
  86. package/src/presentation/overlay.ts +229 -0
  87. package/src/presentation/repaint.test.ts +329 -0
  88. package/src/presentation/shortcut.ts +2 -0
  89. package/src/presentation/snapshot.test.ts +530 -0
  90. package/src/presentation/snapshot.ts +306 -0
  91. package/src/presentation/strip.test.ts +196 -0
  92. package/src/presentation/strip.ts +74 -0
  93. package/src/presentation/wording.test.ts +238 -0
  94. package/src/presentation/wording.ts +222 -0
  95. package/src/runtime/bridge.test.ts +131 -0
  96. package/src/runtime/bridge.ts +134 -0
  97. package/src/runtime/config.test.ts +44 -0
  98. package/src/runtime/config.ts +87 -0
  99. package/src/runtime/context.test.ts +19 -0
  100. package/src/runtime/context.ts +9 -0
  101. package/src/runtime/execution-env.test.ts +35 -0
  102. package/src/runtime/execution-env.ts +15 -0
  103. package/src/runtime/extensions.test.ts +86 -0
  104. package/src/runtime/extensions.ts +140 -0
  105. package/src/runtime/log.test.ts +128 -0
  106. package/src/runtime/log.ts +68 -0
  107. package/src/runtime/mcp.test.ts +1453 -0
  108. package/src/runtime/mcp.ts +938 -0
  109. package/src/runtime/models.test.ts +145 -0
  110. package/src/runtime/models.ts +259 -0
  111. package/src/runtime/observe.test.ts +50 -0
  112. package/src/runtime/observe.ts +150 -0
  113. package/src/runtime/session.test.ts +359 -0
  114. package/src/runtime/session.ts +425 -0
  115. package/src/runtime/timers.test.ts +31 -0
  116. package/src/runtime/timers.ts +10 -0
@@ -0,0 +1,64 @@
1
+ import { assert, it, vi } from "@effect/vitest";
2
+ import { mkdtemp, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { DEFAULT_INSPECT_SHORTCUT } from "../presentation/shortcut.ts";
6
+ import {
7
+ INSPECT_SHORTCUT_ENV,
8
+ INSPECT_SHORTCUT_FILE,
9
+ isValidInspectShortcut,
10
+ resolveInspectShortcut,
11
+ } from "./shortcut.ts";
12
+
13
+ const agentDir = (): Promise<string> => mkdtemp(join(tmpdir(), "delegates-shortcut-"));
14
+
15
+ it("accepts the documented key shapes", () => {
16
+ for (const key of ["ctrl+space", "ctrl+alt+i", "ctrl+shift+i", "f2", "escape"]) {
17
+ assert.strictEqual(isValidInspectShortcut(key), true, key);
18
+ }
19
+ for (const key of ["", "ctrl+", "ctrl+nope", "ctrl+ctrl+i", "f13"]) {
20
+ assert.strictEqual(isValidInspectShortcut(key), false, key);
21
+ }
22
+ });
23
+
24
+ it("defaults to ctrl+space", async () => {
25
+ assert.strictEqual(resolveInspectShortcut(undefined, await agentDir()), DEFAULT_INSPECT_SHORTCUT);
26
+ });
27
+
28
+ it("reads inspectorShortcut from delegates.json", async () => {
29
+ const dir = await agentDir();
30
+ await writeFile(
31
+ join(dir, INSPECT_SHORTCUT_FILE),
32
+ JSON.stringify({ inspectorShortcut: "ctrl+alt+i" }),
33
+ );
34
+ assert.strictEqual(resolveInspectShortcut(undefined, dir), "ctrl+alt+i");
35
+ });
36
+
37
+ it("an explicit option beats the environment and the file", async () => {
38
+ const dir = await agentDir();
39
+ await writeFile(
40
+ join(dir, INSPECT_SHORTCUT_FILE),
41
+ JSON.stringify({ inspectorShortcut: "ctrl+alt+i" }),
42
+ );
43
+ vi.stubEnv(INSPECT_SHORTCUT_ENV, "f2");
44
+ assert.strictEqual(resolveInspectShortcut("ctrl+shift+i", dir), "ctrl+shift+i");
45
+ });
46
+
47
+ it("the environment beats the file", async () => {
48
+ const dir = await agentDir();
49
+ await writeFile(
50
+ join(dir, INSPECT_SHORTCUT_FILE),
51
+ JSON.stringify({ inspectorShortcut: "ctrl+alt+i" }),
52
+ );
53
+ vi.stubEnv(INSPECT_SHORTCUT_ENV, "f2");
54
+ assert.strictEqual(resolveInspectShortcut(undefined, dir), "f2");
55
+ });
56
+
57
+ it("an invalid file value falls back to the default", async () => {
58
+ const dir = await agentDir();
59
+ await writeFile(
60
+ join(dir, INSPECT_SHORTCUT_FILE),
61
+ JSON.stringify({ inspectorShortcut: "ctrl+nope" }),
62
+ );
63
+ assert.strictEqual(resolveInspectShortcut(undefined, dir), DEFAULT_INSPECT_SHORTCUT);
64
+ });
@@ -0,0 +1,105 @@
1
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
2
+ import { Predicate } from "effect";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { DEFAULT_INSPECT_SHORTCUT } from "../presentation/shortcut.ts";
6
+
7
+ /** A per-user override; the CLI environment is the least surprising place for a one-off run. */
8
+ export const INSPECT_SHORTCUT_ENV = "PI_DELEGATES_INSPECTOR_SHORTCUT";
9
+
10
+ /** The extension's own settings file; Pi's `keybindings.json` only names built-in actions. */
11
+ export const INSPECT_SHORTCUT_FILE = "delegates.json";
12
+
13
+ const SYMBOLS = [
14
+ "`",
15
+ "-",
16
+ "=",
17
+ "[",
18
+ "]",
19
+ "\\",
20
+ ";",
21
+ "'",
22
+ ",",
23
+ ".",
24
+ "/",
25
+ "!",
26
+ "@",
27
+ "#",
28
+ "$",
29
+ "%",
30
+ "^",
31
+ "&",
32
+ "*",
33
+ "(",
34
+ ")",
35
+ "_",
36
+ "+",
37
+ "|",
38
+ "~",
39
+ "{",
40
+ "}",
41
+ ":",
42
+ "<",
43
+ ">",
44
+ "?",
45
+ ];
46
+
47
+ const NAMED_KEYS = new Set([
48
+ // ASCII ranges only: splitting into code units is exact here.
49
+ ..."abcdefghijklmnopqrstuvwxyz".split(""),
50
+ ..."0123456789".split(""),
51
+ ...SYMBOLS,
52
+ "escape",
53
+ "esc",
54
+ "enter",
55
+ "return",
56
+ "tab",
57
+ "space",
58
+ "backspace",
59
+ "delete",
60
+ "insert",
61
+ "clear",
62
+ "home",
63
+ "end",
64
+ "pageup",
65
+ "pagedown",
66
+ "up",
67
+ "down",
68
+ "left",
69
+ "right",
70
+ ]);
71
+
72
+ const MODIFIERS = new Set(["ctrl", "shift", "alt", "super"]);
73
+
74
+ /** `ctrl+space`, `ctrl+alt+i`, `f2`, or any key Pi's `KeyId` accepts. */
75
+ export const isValidInspectShortcut = (value: string): boolean => {
76
+ const parts = value.trim().toLowerCase().split("+");
77
+ const key = parts.pop();
78
+ if (key === undefined || key.length === 0) return false;
79
+ if (parts.some((modifier) => !MODIFIERS.has(modifier))) return false;
80
+ if (new Set(parts).size !== parts.length) return false;
81
+ return NAMED_KEYS.has(key) || /^f(?:[1-9]|1[0-2])$/.test(key);
82
+ };
83
+
84
+ const accepted = (value: unknown): string | undefined =>
85
+ typeof value === "string" && isValidInspectShortcut(value) ? value.trim() : undefined;
86
+
87
+ const fromFile = (agentDir: string): string | undefined => {
88
+ try {
89
+ const parsed: unknown = JSON.parse(readFileSync(join(agentDir, INSPECT_SHORTCUT_FILE), "utf8"));
90
+ if (!Predicate.isObject(parsed)) return undefined;
91
+ return accepted(parsed.inspectorShortcut);
92
+ } catch {
93
+ return undefined;
94
+ }
95
+ };
96
+
97
+ /** Option beats environment, environment beats the user file, then the default. */
98
+ export const resolveInspectShortcut = (
99
+ configured: string | undefined,
100
+ agentDir: string = getAgentDir(),
101
+ ): string =>
102
+ accepted(configured) ??
103
+ accepted(process.env[INSPECT_SHORTCUT_ENV]) ??
104
+ fromFile(agentDir) ??
105
+ DEFAULT_INSPECT_SHORTCUT;