@phren/cli 0.3.42 → 0.3.43
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/dist/bridge/conductor-role.js +15 -3
- package/dist/bridge/gitboy-contract.d.ts +5 -0
- package/dist/bridge/gitboy-contract.js +2 -0
- package/dist/bridge/pair.js +1 -1
- package/dist/bridge/project-git.d.ts +8 -0
- package/dist/bridge/project-git.js +39 -0
- package/dist/bridge/project-memory.d.ts +12 -0
- package/dist/bridge/project-memory.js +27 -3
- package/dist/bridge/scoped-gateway.js +3 -2
- package/dist/bridge/server-routes.js +13 -3
- package/dist/bridge-hook.mjs +101 -10
- package/package.json +1 -1
|
@@ -81,6 +81,11 @@ function recordFor(server, pane, by, session) {
|
|
|
81
81
|
...(session ? { session } : {}), since: new Date().toISOString(), by,
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
/** The one pane in a snapshot whose agent reports this session; none when it is absent or ambiguous. */
|
|
85
|
+
function sessionPane(session, s) {
|
|
86
|
+
const found = objects(s.panes).filter(p => runsAgent(p) && objects([p.agent_session])[0]?.value === session);
|
|
87
|
+
return found.length === 1 ? found[0] : undefined;
|
|
88
|
+
}
|
|
84
89
|
/** The recorded pane in a snapshot of its server, when it is still the same terminal. */
|
|
85
90
|
function recordedPane(record, s) {
|
|
86
91
|
const pane = objects(s.panes).find(p => p.pane_id === record.pane);
|
|
@@ -109,10 +114,17 @@ export function conductorPane(server, s) {
|
|
|
109
114
|
const record = state.conductor;
|
|
110
115
|
if (!record || record.server !== server)
|
|
111
116
|
return undefined;
|
|
112
|
-
|
|
117
|
+
let pane = recordedPane(record, s);
|
|
113
118
|
if (!pane) {
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
// The pane went away or was recreated (a moved tab, a Herdr restart): the
|
|
120
|
+
// role follows the session, so a pane running it takes the role over.
|
|
121
|
+
const adopted = record.session ? sessionPane(record.session, s) : undefined;
|
|
122
|
+
if (!adopted) {
|
|
123
|
+
await writeRoleState({ ...state, conductor: null });
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
await writeRoleState({ ...state, conductor: { ...recordFor(server, adopted, record.by, record.session), since: record.since } });
|
|
127
|
+
return adopted;
|
|
116
128
|
}
|
|
117
129
|
// Keep the place current: a pane moved to another tab or workspace is the same pane.
|
|
118
130
|
const moved = (id.safeParse(pane.workspace_id).success && pane.workspace_id !== record.workspace) || (id.safeParse(pane.tab_id).success && pane.tab_id !== record.tab)
|
|
@@ -29,4 +29,9 @@ export declare const findingWriteSchema: z.ZodObject<{
|
|
|
29
29
|
name: z.ZodOptional<z.ZodString>;
|
|
30
30
|
}, z.core.$strict>>;
|
|
31
31
|
}, z.core.$strict>;
|
|
32
|
+
/** Complete one task by its stable id (`bid:` plus 8 hex digits), as `/tasks?branch=` lists it. */
|
|
33
|
+
export declare const taskCompleteSchema: z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export type TaskComplete = z.infer<typeof taskCompleteSchema>;
|
|
32
37
|
export type FindingWrite = z.infer<typeof findingWriteSchema>;
|
|
@@ -44,3 +44,5 @@ export const findingWriteSchema = z.object({
|
|
|
44
44
|
name: z.string().min(1).max(200).refine(value => !/[\x00-\x1f\x7f]/.test(value)).optional(),
|
|
45
45
|
}).strict().optional(),
|
|
46
46
|
}).strict();
|
|
47
|
+
/** Complete one task by its stable id (`bid:` plus 8 hex digits), as `/tasks?branch=` lists it. */
|
|
48
|
+
export const taskCompleteSchema = z.object({ id: z.string().regex(/^bid:[0-9a-f]{8}$/) }).strict();
|
package/dist/bridge/pair.js
CHANGED
|
@@ -241,7 +241,7 @@ async function runScopedPair(args, version) {
|
|
|
241
241
|
text = await readFile(key, "utf8");
|
|
242
242
|
const line = await acceptScopedKey(scope, text);
|
|
243
243
|
const fingerprint = await hostFingerprint();
|
|
244
|
-
console.log(`Authorized ${SCOPE_KEY_COMMENT[scope]} for ${scope}: ${scope === "gitboy-write" ? "POST /v1/projects/<project>/findings only" : "GET /v1/projects/<project>/memory, memory/files, memory/search and tasks only"}.`);
|
|
244
|
+
console.log(`Authorized ${SCOPE_KEY_COMMENT[scope]} for ${scope}: ${scope === "gitboy-write" ? "POST /v1/projects/<project>/findings and tasks/complete only" : "GET /v1/projects/<project>/memory, memory/files, memory/search and tasks only"}.`);
|
|
245
245
|
console.log(` ${line}`);
|
|
246
246
|
console.log(` SSH user: ${userInfo().username} host key: ${fingerprint ?? "unknown (no /etc/ssh/ssh_host_ed25519_key.pub)"}`);
|
|
247
247
|
console.log(` Addresses: ${(await pairingHosts()).join(", ") || "none found"}`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Json } from "./protocol.js";
|
|
2
|
+
/** `GET /v1/projects/:project/git`: the project's host, branch and open pull
|
|
3
|
+
* requests with their checks, read from its checkout on this computer, so the
|
|
4
|
+
* desktop's Projects page needs no session running there. */
|
|
5
|
+
export declare const PROJECT_GIT_ROUTE: RegExp;
|
|
6
|
+
/** The recorded source folder for this computer wins; otherwise the folders
|
|
7
|
+
* `/v1/projects/locate` offers, newest session first. */
|
|
8
|
+
export declare function projectGit(base: string, rawProject: string, activity: Json[]): Promise<Json>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getProjectSourcePath } from "../project-config.js";
|
|
2
|
+
import { resolveProject } from "../store-routing.js";
|
|
3
|
+
import { isValidProjectName } from "../utils.js";
|
|
4
|
+
import { gitPulls } from "./git.js";
|
|
5
|
+
import { locateProject } from "./locate.js";
|
|
6
|
+
import { gitRoot } from "./projects.js";
|
|
7
|
+
import { BridgeError } from "./protocol.js";
|
|
8
|
+
/** `GET /v1/projects/:project/git`: the project's host, branch and open pull
|
|
9
|
+
* requests with their checks, read from its checkout on this computer, so the
|
|
10
|
+
* desktop's Projects page needs no session running there. */
|
|
11
|
+
export const PROJECT_GIT_ROUTE = /^\/v1\/projects\/([^/]+)\/git$/;
|
|
12
|
+
/** The recorded source folder for this computer wins; otherwise the folders
|
|
13
|
+
* `/v1/projects/locate` offers, newest session first. */
|
|
14
|
+
export async function projectGit(base, rawProject, activity) {
|
|
15
|
+
let project;
|
|
16
|
+
try {
|
|
17
|
+
project = decodeURIComponent(rawProject);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new BridgeError(400, "Invalid project name.");
|
|
21
|
+
}
|
|
22
|
+
if (!isValidProjectName(project))
|
|
23
|
+
throw new BridgeError(400, "Invalid project name.");
|
|
24
|
+
const folders = [];
|
|
25
|
+
try {
|
|
26
|
+
const source = getProjectSourcePath(resolveProject(base, project).store.path, project);
|
|
27
|
+
if (source)
|
|
28
|
+
folders.push(source);
|
|
29
|
+
}
|
|
30
|
+
catch { /* not in the store: located folders only */ }
|
|
31
|
+
for (const candidate of await locateProject(project, activity))
|
|
32
|
+
folders.push(candidate.directory);
|
|
33
|
+
for (const folder of folders) {
|
|
34
|
+
const root = await gitRoot(folder).catch(() => undefined);
|
|
35
|
+
if (root)
|
|
36
|
+
return { project, directory: root, ...(await gitPulls(root)) };
|
|
37
|
+
}
|
|
38
|
+
throw new BridgeError(404, "No checkout of this project on this computer.", { code: "no-checkout" });
|
|
39
|
+
}
|
|
@@ -92,3 +92,15 @@ export declare function saveFinding(base: string, rawProject: string, input: unk
|
|
|
92
92
|
status: string;
|
|
93
93
|
finding: MemoryFinding | null;
|
|
94
94
|
}>;
|
|
95
|
+
/** Mark one open task done, by the stable id `/tasks?branch=` gave gitboy when
|
|
96
|
+
* its pull request merged. Exact ids only: no text matching, so a wrong guess
|
|
97
|
+
* can never complete another task. A task already done answers `already-done`. */
|
|
98
|
+
export declare function completeProjectTask(base: string, rawProject: string, input: unknown): {
|
|
99
|
+
project: string;
|
|
100
|
+
id: string;
|
|
101
|
+
status: "already-done";
|
|
102
|
+
} | {
|
|
103
|
+
project: string;
|
|
104
|
+
id: string;
|
|
105
|
+
status: "completed";
|
|
106
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { readFindings } from "../data/access.js";
|
|
4
|
-
import { readTasks } from "../data/tasks.js";
|
|
4
|
+
import { completeTask, readTasks } from "../data/tasks.js";
|
|
5
5
|
import { taskStores } from "../data/task-store-directory.js";
|
|
6
6
|
import { FINDING_TAGS } from "../phren-core.js";
|
|
7
7
|
import { getProjectRemote, readProjectConfig } from "../project-config.js";
|
|
@@ -12,13 +12,13 @@ import { BridgeError } from "./protocol.js";
|
|
|
12
12
|
import { moduleEnabled } from "../modules/runtime.js";
|
|
13
13
|
import { loadCodePackage } from "../modules/code-package.js";
|
|
14
14
|
import { bestChunkMatch, tokenizeForOverlap } from "../shared/retrieval.js";
|
|
15
|
-
import { findingWriteSchema, isBranchName, isRepoPath, isSearchText, MAX_FILE_PATHS, MAX_FINDING_BODY, MAX_SEARCH_LIMIT } from "./gitboy-contract.js";
|
|
15
|
+
import { findingWriteSchema, taskCompleteSchema, isBranchName, isRepoPath, isSearchText, MAX_FILE_PATHS, MAX_FINDING_BODY, MAX_SEARCH_LIMIT } from "./gitboy-contract.js";
|
|
16
16
|
// `GET /v1/projects/:project/memory`: one project's findings, truths and
|
|
17
17
|
// tasks as a fixed read-only contract, for a client that renders them beside
|
|
18
18
|
// the repository (gitboy). Phren stays the source of truth; nothing here
|
|
19
19
|
// writes. The scoped `gitboy-read` SSH key reaches only this route
|
|
20
20
|
// (scoped-gateway.ts). Contract: docs/phren-hook.md#gitboy-read-only-memory.
|
|
21
|
-
export const PROJECT_MEMORY_ROUTE = /^\/v1\/projects\/([^/]+)\/(memory|memory\/files|memory\/search|tasks|findings)$/;
|
|
21
|
+
export const PROJECT_MEMORY_ROUTE = /^\/v1\/projects\/([^/]+)\/(memory|memory\/files|memory\/search|tasks|tasks\/complete|findings)$/;
|
|
22
22
|
export const MEMORY_LIMITS = { findings: 500, active: 200, queue: 200, done: 50 };
|
|
23
23
|
const TAG = new RegExp(`^\\[(${FINDING_TAGS.join("|")})\\]\\s*`, "i");
|
|
24
24
|
const DATE = /^\d{4}-\d{2}-\d{2}/;
|
|
@@ -233,3 +233,27 @@ export async function saveFinding(base, rawProject, input) {
|
|
|
233
233
|
.find(item => item.text === (result.data?.finding ?? "").replace(/^-\s+/, "").trim()) : undefined;
|
|
234
234
|
return { project, status, finding: saved ? finding(saved) : null };
|
|
235
235
|
}
|
|
236
|
+
// ── POST /tasks/complete ─────────────────────────────────────────────────────
|
|
237
|
+
/** Mark one open task done, by the stable id `/tasks?branch=` gave gitboy when
|
|
238
|
+
* its pull request merged. Exact ids only: no text matching, so a wrong guess
|
|
239
|
+
* can never complete another task. A task already done answers `already-done`. */
|
|
240
|
+
export function completeProjectTask(base, rawProject, input) {
|
|
241
|
+
const { project, root } = locate(base, rawProject);
|
|
242
|
+
if (Buffer.byteLength(JSON.stringify(input ?? null)) > 256)
|
|
243
|
+
throw new BridgeError(413, "The body must be at most 256 bytes.");
|
|
244
|
+
const { id } = taskCompleteSchema.parse(input);
|
|
245
|
+
const doc = readTasks(root, project);
|
|
246
|
+
if (!doc.ok)
|
|
247
|
+
throw new BridgeError(404, "No tasks for this project.");
|
|
248
|
+
const stable = id.slice(4);
|
|
249
|
+
const open = [...doc.data.items.Active, ...doc.data.items.Queue].find(item => item.stableId === stable);
|
|
250
|
+
if (!open) {
|
|
251
|
+
if (doc.data.items.Done.some(item => item.stableId === stable))
|
|
252
|
+
return { project, id, status: "already-done" };
|
|
253
|
+
throw new BridgeError(404, "No task with this id.");
|
|
254
|
+
}
|
|
255
|
+
const done = completeTask(root, project, id);
|
|
256
|
+
if (!done.ok)
|
|
257
|
+
throw new BridgeError(400, safe(done.error));
|
|
258
|
+
return { project, id, status: "completed" };
|
|
259
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { connect } from "node:net";
|
|
2
2
|
import { BridgeError } from "./protocol.js";
|
|
3
|
-
import { findingWriteSchema, isBranchName, isRepoPath, isSearchText, MAX_FILE_PATHS, MAX_FINDING_BODY, PROJECT_NAME, } from "./gitboy-contract.js";
|
|
3
|
+
import { findingWriteSchema, taskCompleteSchema, isBranchName, isRepoPath, isSearchText, MAX_FILE_PATHS, MAX_FINDING_BODY, PROJECT_NAME, } from "./gitboy-contract.js";
|
|
4
4
|
// A scoped SSH key reaches the Hook through this gateway instead of the full
|
|
5
5
|
// byte pipe. The key's forced command names the scope
|
|
6
6
|
// (`sh ~/.local/share/phren/bridge/dispatch-scoped gitboy-read`); the gateway
|
|
@@ -51,12 +51,13 @@ const RULES = {
|
|
|
51
51
|
} },
|
|
52
52
|
],
|
|
53
53
|
"gitboy-write": [
|
|
54
|
+
{ method: "POST", path: new RegExp(`^/v1/projects/${PROJECT}/tasks/complete$`), body: { max: 256, schema: taskCompleteSchema } },
|
|
54
55
|
{ method: "POST", path: new RegExp(`^/v1/projects/${PROJECT}/findings$`), body: { max: MAX_FINDING_BODY, schema: findingWriteSchema } },
|
|
55
56
|
],
|
|
56
57
|
};
|
|
57
58
|
const DESCRIBE = {
|
|
58
59
|
"gitboy-read": "GET /v1/projects/<project>/memory, /memory/files, /memory/search and /tasks",
|
|
59
|
-
"gitboy-write": "POST /v1/projects/<project>/findings",
|
|
60
|
+
"gitboy-write": "POST /v1/projects/<project>/findings and /tasks/complete",
|
|
60
61
|
};
|
|
61
62
|
export function isGatewayScope(value) {
|
|
62
63
|
return GATEWAY_SCOPES.includes(value);
|
|
@@ -27,7 +27,8 @@ import { browseFiles } from "./files.js";
|
|
|
27
27
|
import { MAX_FILE_RANGE, rangeInteger, readFileRange } from "./file-range.js";
|
|
28
28
|
import { resolveFilePath } from "./file-resolve.js";
|
|
29
29
|
import { storeRoute } from "./memory-store.js";
|
|
30
|
-
import { memoryForFiles, memorySearch, PROJECT_MEMORY_ROUTE, projectMemory, saveFinding, tasksForBranch } from "./project-memory.js";
|
|
30
|
+
import { memoryForFiles, memorySearch, PROJECT_MEMORY_ROUTE, projectMemory, saveFinding, tasksForBranch, completeProjectTask } from "./project-memory.js";
|
|
31
|
+
import { PROJECT_GIT_ROUTE, projectGit } from "./project-git.js";
|
|
31
32
|
import { liveBackground, markBackground, paneRecord, recordTitle } from "./session-activity.js";
|
|
32
33
|
import { paneAccountField, paneChatState, panes, rpc, servers, snapshot, validateTarget, workspaceSnapshot } from "./herdr.js";
|
|
33
34
|
import { locateProject } from "./locate.js";
|
|
@@ -313,11 +314,11 @@ export function createRouteHandler(ctx) {
|
|
|
313
314
|
const memoryRoute = PROJECT_MEMORY_ROUTE.exec(url.pathname);
|
|
314
315
|
if (memoryRoute) {
|
|
315
316
|
const [, project, route] = memoryRoute;
|
|
316
|
-
if (request.method !== (route === "findings" ? "POST" : "GET"))
|
|
317
|
+
if (request.method !== (route === "findings" || route === "tasks/complete" ? "POST" : "GET"))
|
|
317
318
|
throw new BridgeError(405, "Unsupported request method.");
|
|
318
319
|
if (!modules.has("memory"))
|
|
319
320
|
throw new BridgeError(404, disabledHint("memory"));
|
|
320
|
-
if (route === "tasks" && !modules.has("tasks"))
|
|
321
|
+
if ((route === "tasks" || route === "tasks/complete") && !modules.has("tasks"))
|
|
321
322
|
throw new BridgeError(404, disabledHint("tasks"));
|
|
322
323
|
if (route === "memory")
|
|
323
324
|
result = projectMemory(modules.store, project);
|
|
@@ -327,9 +328,18 @@ export function createRouteHandler(ctx) {
|
|
|
327
328
|
result = memorySearch(modules.store, project, url.searchParams.get("q") ?? "", Number(url.searchParams.get("limit") ?? "5"));
|
|
328
329
|
else if (route === "tasks")
|
|
329
330
|
result = tasksForBranch(modules.store, project, url.searchParams.get("branch") ?? "");
|
|
331
|
+
else if (route === "tasks/complete")
|
|
332
|
+
result = completeProjectTask(modules.store, project, await body(request));
|
|
330
333
|
else
|
|
331
334
|
result = await saveFinding(modules.store, project, await body(request));
|
|
332
335
|
}
|
|
336
|
+
else if (PROJECT_GIT_ROUTE.test(url.pathname)) {
|
|
337
|
+
if (request.method !== "GET")
|
|
338
|
+
throw new BridgeError(405, "Unsupported request method.");
|
|
339
|
+
if (!modules.has("git"))
|
|
340
|
+
throw new BridgeError(404, disabledHint("git"));
|
|
341
|
+
result = await projectGit(modules.store, PROJECT_GIT_ROUTE.exec(url.pathname)[1], await journal.recent());
|
|
342
|
+
}
|
|
333
343
|
else if (url.pathname.startsWith("/v1/store/")) {
|
|
334
344
|
result = await storeRoute(modules.store, request.method ?? "", url, request.method === "POST" ? await body(request) : undefined);
|
|
335
345
|
}
|
package/dist/bridge-hook.mjs
CHANGED
|
@@ -37849,7 +37849,7 @@ var init_package_metadata = __esm({
|
|
|
37849
37849
|
__dirname = path37.dirname(fileURLToPath2(import.meta.url));
|
|
37850
37850
|
ROOT = path37.join(__dirname, "..");
|
|
37851
37851
|
PACKAGE_JSON_PATH = path37.join(ROOT, "package.json");
|
|
37852
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
37852
|
+
BUNDLED_VERSION = true ? "0.3.43" : "0.0.0";
|
|
37853
37853
|
PACKAGE_JSON = readPackageJson();
|
|
37854
37854
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
37855
37855
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -45973,6 +45973,27 @@ function addTask(phrenPath, project, item, opts) {
|
|
|
45973
45973
|
});
|
|
45974
45974
|
return opts?.responsibility !== void 0 ? withTaskGraphLock(opts.graphRoot ?? phrenPath, create) : create();
|
|
45975
45975
|
}
|
|
45976
|
+
function completeTask(phrenPath, project, match) {
|
|
45977
|
+
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
45978
|
+
if (!bPath) return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
45979
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
45980
|
+
if (!preCheck.ok) return forwardErr(preCheck);
|
|
45981
|
+
return withSafeLock(bPath, () => {
|
|
45982
|
+
const parsed = readTasks(phrenPath, project);
|
|
45983
|
+
if (!parsed.ok) return forwardErr(parsed);
|
|
45984
|
+
const found = findItemByMatch(parsed.data, match);
|
|
45985
|
+
if (found.error) return phrenErr(found.error, found.errorCode ?? PhrenError.AMBIGUOUS_MATCH);
|
|
45986
|
+
if (!found.match) return taskItemNotFound(project, match);
|
|
45987
|
+
const [item] = parsed.data.items[found.match.section].splice(found.match.index, 1);
|
|
45988
|
+
item.section = "Done";
|
|
45989
|
+
item.checked = true;
|
|
45990
|
+
if (item.history !== void 0) item.history.push({ at: (/* @__PURE__ */ new Date()).toISOString(), change: `completed${item.claim ? `; released claim by ${item.claim.computer}` : ""}` });
|
|
45991
|
+
item.claim = void 0;
|
|
45992
|
+
parsed.data.items.Done.unshift(item);
|
|
45993
|
+
writeTaskDoc(parsed.data);
|
|
45994
|
+
return phrenOk(`Marked done in ${project}: ${item.line}`);
|
|
45995
|
+
});
|
|
45996
|
+
}
|
|
45976
45997
|
function updateTask(phrenPath, project, match, updates, graphRoot = phrenPath, expectedRevision) {
|
|
45977
45998
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
45978
45999
|
if (!bPath) return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
@@ -50124,6 +50145,10 @@ function recordFor(server, pane, by, session) {
|
|
|
50124
50145
|
by
|
|
50125
50146
|
};
|
|
50126
50147
|
}
|
|
50148
|
+
function sessionPane(session, s) {
|
|
50149
|
+
const found = objects(s.panes).filter((p) => runsAgent(p) && objects([p.agent_session])[0]?.value === session);
|
|
50150
|
+
return found.length === 1 ? found[0] : void 0;
|
|
50151
|
+
}
|
|
50127
50152
|
function recordedPane(record4, s) {
|
|
50128
50153
|
const pane = objects(s.panes).find((p) => p.pane_id === record4.pane);
|
|
50129
50154
|
if (!pane) return void 0;
|
|
@@ -50141,10 +50166,15 @@ function conductorPane(server, s) {
|
|
|
50141
50166
|
}
|
|
50142
50167
|
const record4 = state.conductor;
|
|
50143
50168
|
if (!record4 || record4.server !== server) return void 0;
|
|
50144
|
-
|
|
50169
|
+
let pane = recordedPane(record4, s);
|
|
50145
50170
|
if (!pane) {
|
|
50146
|
-
|
|
50147
|
-
|
|
50171
|
+
const adopted = record4.session ? sessionPane(record4.session, s) : void 0;
|
|
50172
|
+
if (!adopted) {
|
|
50173
|
+
await writeRoleState({ ...state, conductor: null });
|
|
50174
|
+
return void 0;
|
|
50175
|
+
}
|
|
50176
|
+
await writeRoleState({ ...state, conductor: { ...recordFor(server, adopted, record4.by, record4.session), since: record4.since } });
|
|
50177
|
+
return adopted;
|
|
50148
50178
|
}
|
|
50149
50179
|
const moved = id.safeParse(pane.workspace_id).success && pane.workspace_id !== record4.workspace || id.safeParse(pane.tab_id).success && pane.tab_id !== record4.tab || provider.safeParse(pane.agent).success && pane.agent !== record4.source;
|
|
50150
50180
|
if (moved) await writeRoleState({ ...state, conductor: {
|
|
@@ -56391,7 +56421,7 @@ function isBranchName(value2) {
|
|
|
56391
56421
|
function isSearchText(value2) {
|
|
56392
56422
|
return value2.trim().length > 0 && value2.length <= MAX_SEARCH_QUERY && !/[\x00-\x08\x0b-\x1f\x7f]/.test(value2);
|
|
56393
56423
|
}
|
|
56394
|
-
var PROJECT_NAME2, FINDING_TYPE_VALUES, MAX_FILE_PATHS, MAX_SEARCH_QUERY, MAX_SEARCH_LIMIT, MAX_FINDING_BODY, MAX_FINDING_TEXT, noControls, findingWriteSchema;
|
|
56424
|
+
var PROJECT_NAME2, FINDING_TYPE_VALUES, MAX_FILE_PATHS, MAX_SEARCH_QUERY, MAX_SEARCH_LIMIT, MAX_FINDING_BODY, MAX_FINDING_TEXT, noControls, findingWriteSchema, taskCompleteSchema;
|
|
56395
56425
|
var init_gitboy_contract = __esm({
|
|
56396
56426
|
"src/bridge/gitboy-contract.ts"() {
|
|
56397
56427
|
"use strict";
|
|
@@ -56414,6 +56444,7 @@ var init_gitboy_contract = __esm({
|
|
|
56414
56444
|
name: external_exports.string().min(1).max(200).refine((value2) => !/[\x00-\x1f\x7f]/.test(value2)).optional()
|
|
56415
56445
|
}).strict().optional()
|
|
56416
56446
|
}).strict();
|
|
56447
|
+
taskCompleteSchema = external_exports.object({ id: external_exports.string().regex(/^bid:[0-9a-f]{8}$/) }).strict();
|
|
56417
56448
|
}
|
|
56418
56449
|
});
|
|
56419
56450
|
|
|
@@ -56623,12 +56654,13 @@ var init_scoped_gateway = __esm({
|
|
|
56623
56654
|
} }
|
|
56624
56655
|
],
|
|
56625
56656
|
"gitboy-write": [
|
|
56657
|
+
{ method: "POST", path: new RegExp(`^/v1/projects/${PROJECT}/tasks/complete$`), body: { max: 256, schema: taskCompleteSchema } },
|
|
56626
56658
|
{ method: "POST", path: new RegExp(`^/v1/projects/${PROJECT}/findings$`), body: { max: MAX_FINDING_BODY, schema: findingWriteSchema } }
|
|
56627
56659
|
]
|
|
56628
56660
|
};
|
|
56629
56661
|
DESCRIBE = {
|
|
56630
56662
|
"gitboy-read": "GET /v1/projects/<project>/memory, /memory/files, /memory/search and /tasks",
|
|
56631
|
-
"gitboy-write": "POST /v1/projects/<project>/findings"
|
|
56663
|
+
"gitboy-write": "POST /v1/projects/<project>/findings and /tasks/complete"
|
|
56632
56664
|
};
|
|
56633
56665
|
refuse = (status, error62) => ({ ok: false, status, error: error62 });
|
|
56634
56666
|
REASONS = { 400: "Bad Request", 403: "Forbidden", 408: "Request Timeout", 413: "Content Too Large", 415: "Unsupported Media Type", 503: "Service Unavailable" };
|
|
@@ -71929,6 +71961,22 @@ async function saveFinding(base, rawProject, input2) {
|
|
|
71929
71961
|
const saved = status === "saved" ? sortedFindings(locate(base, rawProject).root, project).find((item) => item.text === (result.data?.finding ?? "").replace(/^-\s+/, "").trim()) : void 0;
|
|
71930
71962
|
return { project, status, finding: saved ? finding(saved) : null };
|
|
71931
71963
|
}
|
|
71964
|
+
function completeProjectTask(base, rawProject, input2) {
|
|
71965
|
+
const { project, root } = locate(base, rawProject);
|
|
71966
|
+
if (Buffer.byteLength(JSON.stringify(input2 ?? null)) > 256) throw new BridgeError(413, "The body must be at most 256 bytes.");
|
|
71967
|
+
const { id: id2 } = taskCompleteSchema.parse(input2);
|
|
71968
|
+
const doc = readTasks(root, project);
|
|
71969
|
+
if (!doc.ok) throw new BridgeError(404, "No tasks for this project.");
|
|
71970
|
+
const stable = id2.slice(4);
|
|
71971
|
+
const open30 = [...doc.data.items.Active, ...doc.data.items.Queue].find((item) => item.stableId === stable);
|
|
71972
|
+
if (!open30) {
|
|
71973
|
+
if (doc.data.items.Done.some((item) => item.stableId === stable)) return { project, id: id2, status: "already-done" };
|
|
71974
|
+
throw new BridgeError(404, "No task with this id.");
|
|
71975
|
+
}
|
|
71976
|
+
const done = completeTask(root, project, id2);
|
|
71977
|
+
if (!done.ok) throw new BridgeError(400, safe(done.error));
|
|
71978
|
+
return { project, id: id2, status: "completed" };
|
|
71979
|
+
}
|
|
71932
71980
|
var PROJECT_MEMORY_ROUTE, MEMORY_LIMITS, TAG, DATE, safe, writes4;
|
|
71933
71981
|
var init_project_memory = __esm({
|
|
71934
71982
|
"src/bridge/project-memory.ts"() {
|
|
@@ -71946,7 +71994,7 @@ var init_project_memory = __esm({
|
|
|
71946
71994
|
init_code_package();
|
|
71947
71995
|
init_retrieval();
|
|
71948
71996
|
init_gitboy_contract();
|
|
71949
|
-
PROJECT_MEMORY_ROUTE = /^\/v1\/projects\/([^/]+)\/(memory|memory\/files|memory\/search|tasks|findings)$/;
|
|
71997
|
+
PROJECT_MEMORY_ROUTE = /^\/v1\/projects\/([^/]+)\/(memory|memory\/files|memory\/search|tasks|tasks\/complete|findings)$/;
|
|
71950
71998
|
MEMORY_LIMITS = { findings: 500, active: 200, queue: 200, done: 50 };
|
|
71951
71999
|
TAG = new RegExp(`^\\[(${FINDING_TAGS.join("|")})\\]\\s*`, "i");
|
|
71952
72000
|
DATE = /^\d{4}-\d{2}-\d{2}/;
|
|
@@ -71955,6 +72003,43 @@ var init_project_memory = __esm({
|
|
|
71955
72003
|
}
|
|
71956
72004
|
});
|
|
71957
72005
|
|
|
72006
|
+
// src/bridge/project-git.ts
|
|
72007
|
+
async function projectGit(base, rawProject, activity) {
|
|
72008
|
+
let project;
|
|
72009
|
+
try {
|
|
72010
|
+
project = decodeURIComponent(rawProject);
|
|
72011
|
+
} catch {
|
|
72012
|
+
throw new BridgeError(400, "Invalid project name.");
|
|
72013
|
+
}
|
|
72014
|
+
if (!isValidProjectName(project)) throw new BridgeError(400, "Invalid project name.");
|
|
72015
|
+
const folders = [];
|
|
72016
|
+
try {
|
|
72017
|
+
const source = getProjectSourcePath(resolveProject(base, project).store.path, project);
|
|
72018
|
+
if (source) folders.push(source);
|
|
72019
|
+
} catch {
|
|
72020
|
+
}
|
|
72021
|
+
for (const candidate of await locateProject(project, activity)) folders.push(candidate.directory);
|
|
72022
|
+
for (const folder of folders) {
|
|
72023
|
+
const root = await gitRoot(folder).catch(() => void 0);
|
|
72024
|
+
if (root) return { project, directory: root, ...await gitPulls(root) };
|
|
72025
|
+
}
|
|
72026
|
+
throw new BridgeError(404, "No checkout of this project on this computer.", { code: "no-checkout" });
|
|
72027
|
+
}
|
|
72028
|
+
var PROJECT_GIT_ROUTE;
|
|
72029
|
+
var init_project_git = __esm({
|
|
72030
|
+
"src/bridge/project-git.ts"() {
|
|
72031
|
+
"use strict";
|
|
72032
|
+
init_project_config();
|
|
72033
|
+
init_store_routing();
|
|
72034
|
+
init_utils();
|
|
72035
|
+
init_git();
|
|
72036
|
+
init_locate();
|
|
72037
|
+
init_projects();
|
|
72038
|
+
init_protocol();
|
|
72039
|
+
PROJECT_GIT_ROUTE = /^\/v1\/projects\/([^/]+)\/git$/;
|
|
72040
|
+
}
|
|
72041
|
+
});
|
|
72042
|
+
|
|
71958
72043
|
// src/bridge/simulators.ts
|
|
71959
72044
|
import { execFile as execFile30 } from "node:child_process";
|
|
71960
72045
|
import { chmod as chmod5, mkdir as mkdir34, readFile as readFile54, rename as rename11, stat as stat30, unlink as unlink9, writeFile as writeFile12 } from "node:fs/promises";
|
|
@@ -73056,14 +73141,19 @@ function createRouteHandler(ctx) {
|
|
|
73056
73141
|
const memoryRoute = PROJECT_MEMORY_ROUTE.exec(url2.pathname);
|
|
73057
73142
|
if (memoryRoute) {
|
|
73058
73143
|
const [, project, route2] = memoryRoute;
|
|
73059
|
-
if (request9.method !== (route2 === "findings" ? "POST" : "GET")) throw new BridgeError(405, "Unsupported request method.");
|
|
73144
|
+
if (request9.method !== (route2 === "findings" || route2 === "tasks/complete" ? "POST" : "GET")) throw new BridgeError(405, "Unsupported request method.");
|
|
73060
73145
|
if (!modules.has("memory")) throw new BridgeError(404, disabledHint("memory"));
|
|
73061
|
-
if (route2 === "tasks" && !modules.has("tasks")) throw new BridgeError(404, disabledHint("tasks"));
|
|
73146
|
+
if ((route2 === "tasks" || route2 === "tasks/complete") && !modules.has("tasks")) throw new BridgeError(404, disabledHint("tasks"));
|
|
73062
73147
|
if (route2 === "memory") result = projectMemory(modules.store, project);
|
|
73063
73148
|
else if (route2 === "memory/files") result = await memoryForFiles(modules.store, project, url2.searchParams.getAll("path"));
|
|
73064
73149
|
else if (route2 === "memory/search") result = memorySearch(modules.store, project, url2.searchParams.get("q") ?? "", Number(url2.searchParams.get("limit") ?? "5"));
|
|
73065
73150
|
else if (route2 === "tasks") result = tasksForBranch(modules.store, project, url2.searchParams.get("branch") ?? "");
|
|
73151
|
+
else if (route2 === "tasks/complete") result = completeProjectTask(modules.store, project, await body(request9));
|
|
73066
73152
|
else result = await saveFinding(modules.store, project, await body(request9));
|
|
73153
|
+
} else if (PROJECT_GIT_ROUTE.test(url2.pathname)) {
|
|
73154
|
+
if (request9.method !== "GET") throw new BridgeError(405, "Unsupported request method.");
|
|
73155
|
+
if (!modules.has("git")) throw new BridgeError(404, disabledHint("git"));
|
|
73156
|
+
result = await projectGit(modules.store, PROJECT_GIT_ROUTE.exec(url2.pathname)[1], await journal.recent());
|
|
73067
73157
|
} else if (url2.pathname.startsWith("/v1/store/")) {
|
|
73068
73158
|
result = await storeRoute(modules.store, request9.method ?? "", url2, request9.method === "POST" ? await body(request9) : void 0);
|
|
73069
73159
|
} else if (request9.method === "GET") {
|
|
@@ -73651,6 +73741,7 @@ var init_server_routes = __esm({
|
|
|
73651
73741
|
init_file_resolve();
|
|
73652
73742
|
init_memory_store();
|
|
73653
73743
|
init_project_memory();
|
|
73744
|
+
init_project_git();
|
|
73654
73745
|
init_session_activity();
|
|
73655
73746
|
init_herdr();
|
|
73656
73747
|
init_locate();
|
|
@@ -75450,7 +75541,7 @@ async function main() {
|
|
|
75450
75541
|
return askpass2(args[1]);
|
|
75451
75542
|
}
|
|
75452
75543
|
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
75453
|
-
return runBridge2(args, "0.3.
|
|
75544
|
+
return runBridge2(args, "0.3.43");
|
|
75454
75545
|
}
|
|
75455
75546
|
main().then((code) => {
|
|
75456
75547
|
process.exitCode = code;
|