@aibyzero/byz 0.1.5 → 0.1.7

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 (33) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +33 -0
  3. package/dist/cli.js +18 -18
  4. package/dist/conversation/conversation-extension.js +85 -0
  5. package/dist/conversation/interaction-policy.js +53 -0
  6. package/dist/conversation/routing-policy.js +102 -0
  7. package/dist/fast-session.js +276 -0
  8. package/dist/fast.js +9 -0
  9. package/dist/prewalk.js +150 -0
  10. package/dist/runtime/bundle/chunks/{chunk-WMLOZBQV.js → chunk-JDLZZASY.js} +7 -7
  11. package/dist/runtime/bundle/cli.js +1 -1
  12. package/dist/runtime/bundle/index.js +1 -1
  13. package/dist/runtime/bundle/rpc-entry.js +1 -1
  14. package/dist/runtime/config.d.ts.map +1 -1
  15. package/dist/runtime/config.js +3 -3
  16. package/dist/runtime/config.js.map +1 -1
  17. package/dist/runtime/core/extensions/index.d.ts +1 -1
  18. package/dist/runtime/core/extensions/index.d.ts.map +1 -1
  19. package/dist/runtime/core/extensions/index.js.map +1 -1
  20. package/dist/runtime/core/extensions/runner.d.ts.map +1 -1
  21. package/dist/runtime/core/extensions/runner.js +3 -0
  22. package/dist/runtime/core/extensions/runner.js.map +1 -1
  23. package/dist/runtime/core/extensions/types.d.ts +17 -0
  24. package/dist/runtime/core/extensions/types.d.ts.map +1 -1
  25. package/dist/runtime/core/extensions/types.js.map +1 -1
  26. package/dist/runtime/modes/interactive/interactive-mode.d.ts +5 -0
  27. package/dist/runtime/modes/interactive/interactive-mode.d.ts.map +1 -1
  28. package/dist/runtime/modes/interactive/interactive-mode.js +59 -6
  29. package/dist/runtime/modes/interactive/interactive-mode.js.map +1 -1
  30. package/dist/runtime/modes/rpc/rpc-mode.d.ts.map +1 -1
  31. package/dist/runtime/modes/rpc/rpc-mode.js +9 -0
  32. package/dist/runtime/modes/rpc/rpc-mode.js.map +1 -1
  33. package/package.json +1 -1
@@ -0,0 +1,150 @@
1
+ import { realpath } from "node:fs/promises";
2
+ import { isAbsolute, relative, resolve, sep } from "node:path";
3
+
4
+ const PREWALK_COMMAND_USAGE = "Usage: /prewalk [cancel|status]";
5
+ const WRITE_TOOL_NAMES = new Set(["edit", "write"]);
6
+
7
+ function hasBuiltinWriteTools(pi) {
8
+ const tools = new Map(pi.getAllTools().map((tool) => [tool.name, tool]));
9
+ return [...WRITE_TOOL_NAMES].every((name) => {
10
+ const sourceInfo = tools.get(name)?.sourceInfo;
11
+ return sourceInfo?.source === "builtin" && sourceInfo.path === `<builtin:${name}>`;
12
+ });
13
+ }
14
+
15
+ async function isWorkspacePath(cwd, inputPath) {
16
+ if (typeof inputPath !== "string" || inputPath.length === 0) return false;
17
+ try {
18
+ const [workspaceRoot, targetPath] = await Promise.all([realpath(cwd), realpath(resolve(cwd, inputPath))]);
19
+ const relativePath = relative(workspaceRoot, targetPath);
20
+ return (
21
+ relativePath.length > 0 &&
22
+ relativePath !== ".." &&
23
+ !relativePath.startsWith(`..${sep}`) &&
24
+ !isAbsolute(relativePath)
25
+ );
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ export function createPrewalkExtension({ fastController }) {
32
+ if (!fastController) throw new Error("Prewalk requires the Fast session controller.");
33
+
34
+ return function prewalkExtension(pi) {
35
+ let state = "idle";
36
+ let target;
37
+ let candidateQueue = Promise.resolve();
38
+
39
+ function reset() {
40
+ state = "idle";
41
+ target = undefined;
42
+ }
43
+
44
+ function notifyStatus(ctx) {
45
+ if (state === "armed" && target) {
46
+ ctx.ui.notify(
47
+ `Prewalk: armed; target=${fastController.formatTarget(target)}; thinking=${target.thinking}`,
48
+ "info",
49
+ );
50
+ return;
51
+ }
52
+ ctx.ui.notify(`Prewalk: ${state === "switching" ? "switching" : "not armed"}.`, "info");
53
+ }
54
+
55
+ function cancel(ctx, message = "Prewalk: canceled.") {
56
+ if (state !== "armed") {
57
+ ctx.ui.notify("Prewalk: not armed.", "info");
58
+ return false;
59
+ }
60
+ reset();
61
+ ctx.ui.notify(message, "info");
62
+ return true;
63
+ }
64
+
65
+ function arm(ctx) {
66
+ if (!ctx.isIdle()) {
67
+ ctx.ui.notify("Prewalk cannot arm while the agent is busy.", "warning");
68
+ return;
69
+ }
70
+ if (!ctx.isProjectTrusted()) {
71
+ ctx.ui.notify("Prewalk requires a trusted project.", "warning");
72
+ return;
73
+ }
74
+ if (fastController.isActive()) {
75
+ ctx.ui.notify("Prewalk cannot arm while Fast is already on.", "warning");
76
+ return;
77
+ }
78
+ if (state === "armed") {
79
+ ctx.ui.notify("Prewalk is already armed.", "info");
80
+ return;
81
+ }
82
+ if (!hasBuiltinWriteTools(pi)) {
83
+ ctx.ui.notify("Prewalk requires the built-in edit and write tools.", "warning");
84
+ return;
85
+ }
86
+ const nextTarget = fastController.resolveTarget(ctx, { requireAuth: true, requireModel: true });
87
+ if (!nextTarget) return;
88
+ target = nextTarget;
89
+ state = "armed";
90
+ notifyStatus(ctx);
91
+ }
92
+
93
+ async function considerToolResult(event, ctx) {
94
+ if (state !== "armed" || !target) return;
95
+ if (event.isError || !WRITE_TOOL_NAMES.has(event.toolName)) return;
96
+ if (!hasBuiltinWriteTools(pi)) return;
97
+ if (!(await isWorkspacePath(ctx.cwd, event.input?.path))) return;
98
+ if (state !== "armed" || !target) return;
99
+
100
+ const consumedTarget = target;
101
+ state = "switching";
102
+ target = undefined;
103
+ const applied = await fastController.applyTarget(ctx, consumedTarget);
104
+ reset();
105
+ if (applied) {
106
+ ctx.ui.notify(
107
+ `Prewalk: handed off to ${fastController.formatTarget(consumedTarget)}; thinking=${fastController.getThinkingLevel()}.`,
108
+ "info",
109
+ );
110
+ return;
111
+ }
112
+ ctx.ui.notify("Prewalk: handoff failed and was canceled.", "error");
113
+ }
114
+
115
+ pi.registerCommand("prewalk", {
116
+ description: "Arm a one-time handoff to the Fast target after the first successful write",
117
+ handler: async (args, ctx) => {
118
+ const action = args.trim().toLowerCase();
119
+ if (!action) {
120
+ arm(ctx);
121
+ return;
122
+ }
123
+ if (action === "cancel") {
124
+ cancel(ctx);
125
+ return;
126
+ }
127
+ if (action === "status") {
128
+ notifyStatus(ctx);
129
+ return;
130
+ }
131
+ ctx.ui.notify(PREWALK_COMMAND_USAGE, "warning");
132
+ },
133
+ });
134
+
135
+ pi.on("tool_result", (event, ctx) => {
136
+ candidateQueue = candidateQueue.then(
137
+ () => considerToolResult(event, ctx),
138
+ () => considerToolResult(event, ctx),
139
+ );
140
+ return candidateQueue;
141
+ });
142
+
143
+ fastController.onExplicitSelection((_event, ctx) => {
144
+ if (state === "armed") cancel(ctx, "Prewalk: canceled after an explicit model or thinking change.");
145
+ });
146
+ fastController.onActiveChange((active, ctx) => {
147
+ if (active && state === "armed") cancel(ctx, "Prewalk: canceled because Fast was enabled.");
148
+ });
149
+ };
150
+ }