Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions bin/pagespace.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,13 @@ async function runOnboarding() {
// will read it from the store on the next launch (token isolation holds: no env round-trip).
const credPath = writeCredentials(buildCredentialRecord({ token, apiUrl: base }));
if (state.defaultDrive) process.env.PAGESPACE_DRIVE = state.defaultDrive;
if (state.defaultModel) process.env.PAGESPACE_MODEL_PAGE = state.defaultModel.id;
console.log(` ✓ default drive: ${state.defaultDrive || "(none)"}`);
if (state.defaultModel) {
console.log(` ✓ default model: ${state.defaultModel.name} (${state.defaultModel.id.slice(0, 8)})`);
const allModels = state.models ?? [];
if (allModels.length > 0) process.env.PAGESPACE_MODEL_PAGES = allModels.map((m) => m.id).join(",");
console.log(` ✓ drive: ${state.defaultDrive || "(none)"}`);
if (allModels.length > 0) {
console.log(` ✓ ${allModels.length} agent model(s): ${allModels.map((m) => m.name).join(", ")}`);
} else {
console.log(" · no agent models found — set PAGESPACE_MODEL_PAGE manually if needed.");
console.log(" · no agent models found — set PAGESPACE_MODEL_PAGES manually if needed.");
}
process.stderr.write(`pagespace · set up complete (${credPath}, 0600). Launching…\n`);
}
Expand Down
22 changes: 16 additions & 6 deletions src/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ export function createPageSpaceOps(
return { isDirectory: () => dir };
},
readdir: async (p) => {
const rel = toMountRel(p);
if (rel === "") {
const drives = await resolver.listDrives();
return drives.map((d) => d.slug);
}
const { driveId, parentId } = await containerId(p);
const kids = await resolver.children(driveId, parentId);
return kids.map((k) => k.title);
Expand All @@ -330,24 +335,29 @@ export function createPageSpaceOps(
exists,
glob: async (pattern, cwd, options) => {
const rel = toMountRel(cwd);
const r = await resolver.resolve(rel);
const driveId = r.driveId;
const startParent = rel === "" ? null : r.page ? r.page.id : null;
const re = globToRegExp(pattern);
const base = norm(cwd);
const out: string[] = [];
const walk = async (parentId: string | null, prefix: string) => {
const walkDrive = async (driveId: string, parentId: string | null, prefix: string) => {
if (out.length >= options.limit) return;
for (const k of await resolver.children(driveId, parentId)) {
const childRel = prefix ? `${prefix}/${k.title}` : k.title;
if (re.test(childRel) && !options.ignore.some((ig) => globToRegExp(ig).test(childRel))) {
out.push(`${base}/${childRel}`);
if (out.length >= options.limit) return;
}
if (k.type === "FOLDER") await walk(k.id, childRel);
if (k.type === "FOLDER") await walkDrive(driveId, k.id, childRel);
}
};
await walk(startParent, "");
if (rel === "") {
for (const drive of await resolver.listDrives()) {
await walkDrive(drive.id, null, drive.slug);
}
} else {
const r = await resolver.resolve(rel);
const startParent = r.page ? r.page.id : null;
await walkDrive(r.driveId, startParent, "");
}
return out.slice(0, options.limit);
},
},
Expand Down
4 changes: 4 additions & 0 deletions src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class PageSpaceResolver {
else this.childrenByDrive.clear();
}

async listDrives(): Promise<Drive[]> {
return [...(await this.drives()).values()];
}

async children(driveId: string, parentId: string | null): Promise<Page[]> {
return (await this.childIndex(driveId)).get(parentId) ?? [];
}
Expand Down
Loading