@phren/cli 0.3.34 → 0.3.36

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 (68) hide show
  1. package/dist/bridge/agent-hooks.d.ts +11 -1
  2. package/dist/bridge/agent-hooks.js +56 -19
  3. package/dist/bridge/changes.js +30 -13
  4. package/dist/bridge/dispatch-command.js +3 -1
  5. package/dist/bridge/health.js +3 -1
  6. package/dist/bridge/host-key.d.ts +16 -0
  7. package/dist/bridge/host-key.js +35 -0
  8. package/dist/bridge/launch-brief.d.ts +2 -0
  9. package/dist/bridge/launch-brief.js +5 -0
  10. package/dist/bridge/link.js +11 -4
  11. package/dist/bridge/owner-inbox-sources.d.ts +5 -0
  12. package/dist/bridge/owner-inbox-sources.js +94 -0
  13. package/dist/bridge/owner-inbox-view.js +20 -1
  14. package/dist/bridge/owner-inbox.d.ts +7 -3
  15. package/dist/bridge/owner-inbox.js +113 -69
  16. package/dist/bridge/pair.js +3 -2
  17. package/dist/bridge/server.js +3 -23
  18. package/dist/bridge/sudo.d.ts +36 -6
  19. package/dist/bridge/sudo.js +180 -37
  20. package/dist/bridge/worker-reports.d.ts +8 -1
  21. package/dist/bridge/worker-reports.js +28 -7
  22. package/dist/bridge-hook.mjs +817 -473
  23. package/dist/clanker.d.ts +54 -0
  24. package/dist/clanker.js +188 -0
  25. package/dist/cli/config.js +30 -0
  26. package/dist/cli/hooks-output.d.ts +1 -1
  27. package/dist/cli/hooks-output.js +28 -21
  28. package/dist/cli/hooks.js +1 -1
  29. package/dist/cli/namespaces-skills.js +2 -2
  30. package/dist/cli/namespaces-tasks.js +46 -7
  31. package/dist/cli/session-start.js +12 -3
  32. package/dist/cli/session-stop.js +9 -0
  33. package/dist/cli/team.js +3 -0
  34. package/dist/cli-handlers.js +7 -0
  35. package/dist/cli-registry.js +1 -0
  36. package/dist/data/task-format.d.ts +5 -1
  37. package/dist/data/task-format.js +13 -5
  38. package/dist/index.js +82 -50
  39. package/dist/init/init-configure.d.ts +2 -0
  40. package/dist/init/init-configure.js +12 -0
  41. package/dist/init/init-uninstall.js +21 -2
  42. package/dist/init/init.d.ts +2 -0
  43. package/dist/init/init.js +11 -3
  44. package/dist/init/preferences.d.ts +6 -0
  45. package/dist/init/teardown.js +18 -4
  46. package/dist/link/doctor.js +2 -2
  47. package/dist/link/link.js +9 -0
  48. package/dist/link/refresh.d.ts +10 -0
  49. package/dist/link/refresh.js +34 -0
  50. package/dist/mcp/local-index.d.ts +20 -0
  51. package/dist/mcp/local-index.js +39 -1
  52. package/dist/shared/index.d.ts +14 -0
  53. package/dist/shared/index.js +88 -74
  54. package/dist/shared/retrieval.js +1 -1
  55. package/dist/skill/files.js +40 -11
  56. package/dist/skill/registry.d.ts +6 -0
  57. package/dist/skill/registry.js +21 -5
  58. package/dist/task/lifecycle.js +3 -1
  59. package/dist/tools/dispatch.js +5 -2
  60. package/dist/tools/finding.js +20 -11
  61. package/dist/tools/graph.d.ts +2 -0
  62. package/dist/tools/graph.js +2 -0
  63. package/dist/tools/search.d.ts +2 -0
  64. package/dist/tools/search.js +88 -6
  65. package/dist/tools/tasks.js +45 -0
  66. package/dist/tools/types.d.ts +3 -1
  67. package/dist/tools/types.js +3 -2
  68. package/package.json +1 -1
@@ -3,7 +3,14 @@ import type { TurnRecord } from "./turn-records.js";
3
3
  import { type Integrator, type PullRequest } from "./return-contract.js";
4
4
  export { integratorSchema, prsSchema, pullRequestSchema } from "./return-contract.js";
5
5
  /** The worker reports PR evidence to its own Hook, without direct messaging or
6
- * GitHub comments. Bound to this terminal and submitted turn, not the next one. */
6
+ * GitHub comments. Bound to this terminal and submitted turn, not the next one.
7
+ *
8
+ * The pane's turn record can miss that turn: a nested agent run in the
9
+ * worker's own pane (`claude -p` from its shell) inherits the pane's
10
+ * variables, and its hooks replace the record with its own conversation. A
11
+ * worker whose dispatch this Hook saw arrive in this pane and conversation
12
+ * still reports; the evidence binds to its current turn, the one the next
13
+ * Stop ends, and never to a prompt submitted after the report. */
7
14
  export declare function reportWorker(input: unknown): Promise<Json>;
8
15
  export declare function workerPrs(target: Target, record: TurnRecord): Promise<PullRequest[] | undefined>;
9
16
  export declare function readIntegrator(): Promise<Integrator | undefined>;
@@ -6,15 +6,24 @@ import { atomicInPrivateDir, BridgeError, bridgeRoot, targetSchema } from "./pro
6
6
  import { paneIdentity, findPane, snapshot, validateTarget } from "./herdr.js";
7
7
  import { originPaneSchema } from "./dispatch.js";
8
8
  import { paneTurn } from "./dispatch-returns.js";
9
+ import { briefArrival, briefId } from "./launch-brief.js";
9
10
  import { integratorSchema, prsSchema, reportText as text } from "./return-contract.js";
10
11
  export { integratorSchema, prsSchema, pullRequestSchema } from "./return-contract.js";
11
- const reportSchema = z.object({ target: targetSchema, terminal: text(200), promptSeq: z.number().int(), prs: prsSchema, at: z.string().datetime() }).strict();
12
+ // `promptSeq` is absent for a report bound by its dispatch instead of a recorded prompt (`reportWorker`).
13
+ const reportSchema = z.object({ target: targetSchema, terminal: text(200), promptSeq: z.number().int().optional(), prs: prsSchema, at: z.string().datetime() }).strict();
12
14
  const key = (target) => createHash("sha256").update(JSON.stringify([target.server, target.workspace, target.tab, target.pane, target.source, target.session])).digest("hex");
13
15
  const reportFile = (target) => path.join(bridgeRoot(), "worker-reports", `${key(target)}.json`);
14
16
  /** The worker reports PR evidence to its own Hook, without direct messaging or
15
- * GitHub comments. Bound to this terminal and submitted turn, not the next one. */
17
+ * GitHub comments. Bound to this terminal and submitted turn, not the next one.
18
+ *
19
+ * The pane's turn record can miss that turn: a nested agent run in the
20
+ * worker's own pane (`claude -p` from its shell) inherits the pane's
21
+ * variables, and its hooks replace the record with its own conversation. A
22
+ * worker whose dispatch this Hook saw arrive in this pane and conversation
23
+ * still reports; the evidence binds to its current turn, the one the next
24
+ * Stop ends, and never to a prompt submitted after the report. */
16
25
  export async function reportWorker(input) {
17
- const data = z.object({ origin: originPaneSchema, prs: prsSchema }).strict().parse(input);
26
+ const data = z.object({ origin: originPaneSchema, prs: prsSchema, dispatch: briefId.optional() }).strict().parse(input);
18
27
  const pane = findPane(await snapshot(data.origin.server), data.origin);
19
28
  if (!pane)
20
29
  throw new BridgeError(409, "The worker pane changed.");
@@ -22,18 +31,30 @@ export async function reportWorker(input) {
22
31
  const target = targetSchema.parse({ ...data.origin, source: pane.agent, session });
23
32
  await validateTarget(target, false, true);
24
33
  const record = await paneTurn(target.server, pane, target.source);
25
- if (!record?.prompt || record.session !== session || record.terminal !== pane.terminal_id)
26
- throw new BridgeError(409, "The Hook has not recorded this worker's submitted turn yet.");
27
- await atomicInPrivateDir(reportFile(target), reportSchema.parse({ target, terminal: record.terminal, promptSeq: record.prompt.seq, prs: data.prs, at: new Date().toISOString() }));
34
+ const promptSeq = record?.prompt && record.session === session && record.terminal === pane.terminal_id ? record.prompt.seq : undefined;
35
+ if (promptSeq === undefined && !(typeof pane.terminal_id === "string" && await arrivedHere(data.dispatch ?? (record && record.session === session ? record.dispatch : undefined), target)))
36
+ throw new BridgeError(409, "The Hook has not recorded this worker's submitted turn yet, and no dispatch it launched arrived in this pane.");
37
+ await atomicInPrivateDir(reportFile(target), reportSchema.parse({ target, terminal: pane.terminal_id, ...(promptSeq !== undefined ? { promptSeq } : {}), prs: data.prs, at: new Date().toISOString() }));
28
38
  return { ok: true, target, prs: data.prs };
29
39
  }
40
+ /** Whether this Hook launched dispatch `id` and its brief arrived in exactly this pane and conversation. */
41
+ async function arrivedHere(id, target) {
42
+ if (!id)
43
+ return false;
44
+ const arrival = await briefArrival(id);
45
+ return [arrival?.accepted, arrival?.started].some(event => event && key(event.target) === key(target));
46
+ }
30
47
  export async function workerPrs(target, record) {
31
48
  try {
32
49
  const file = reportFile(target), info = await lstat(file);
33
50
  if (!info.isFile() || info.isSymbolicLink() || info.size > 131072)
34
51
  return undefined;
35
52
  const report = reportSchema.parse(JSON.parse(await readFile(file, "utf8")));
36
- return report.terminal === record.terminal && report.promptSeq === record.prompt?.seq ? report.prs : undefined;
53
+ if (report.terminal !== record.terminal)
54
+ return undefined;
55
+ if (report.promptSeq !== undefined)
56
+ return report.promptSeq === record.prompt?.seq ? report.prs : undefined;
57
+ return !record.prompt || Date.parse(record.prompt.at) <= Date.parse(report.at) ? report.prs : undefined;
37
58
  }
38
59
  catch (error) {
39
60
  if (error.code !== "ENOENT")