@kamilio/wire 0.1.36 → 0.1.37

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 (34) hide show
  1. package/README.md +6 -0
  2. package/dist/adapters/drive-pdf.d.ts +2 -0
  3. package/dist/adapters/drive-pdf.d.ts.map +1 -0
  4. package/dist/adapters/drive-pdf.js +109 -0
  5. package/dist/adapters/drive-pdf.js.map +1 -0
  6. package/dist/adapters/gdrive.d.ts +6 -0
  7. package/dist/adapters/gdrive.d.ts.map +1 -0
  8. package/dist/adapters/gdrive.js +211 -0
  9. package/dist/adapters/gdrive.js.map +1 -0
  10. package/dist/adapters/pdf-notices/THIRD_PARTY_NOTICES.md +631 -0
  11. package/dist/adapters/pdf-notices/licenses/AGG-2.3.txt +7 -0
  12. package/dist/adapters/pdf-notices/licenses/MIT.txt +21 -0
  13. package/dist/adapters/pdf-notices/licenses/PDFIUM-BSD.txt +27 -0
  14. package/dist/adapters/pdf-notices/licenses/PDFJS-APACHE-2.0.txt +177 -0
  15. package/dist/adapters/pdf-notices/licenses/PYPDF-BSD.txt +29 -0
  16. package/dist/adapters/pdf-notices/licenses/PYTHON-PSF.txt +254 -0
  17. package/dist/adapters/pdf-notices/licenses/V8-BSD.txt +61 -0
  18. package/dist/adapters/root.d.ts +2 -0
  19. package/dist/adapters/root.d.ts.map +1 -1
  20. package/dist/adapters/root.js +10 -0
  21. package/dist/adapters/root.js.map +1 -1
  22. package/dist/cli.d.ts.map +1 -1
  23. package/dist/cli.js +3 -1
  24. package/dist/cli.js.map +1 -1
  25. package/dist/executable.d.ts.map +1 -1
  26. package/dist/executable.js +2 -1
  27. package/dist/executable.js.map +1 -1
  28. package/dist/pdf-reader.mjs +171 -0
  29. package/package.json +9 -3
  30. package/src/adapters/drive-pdf.ts +106 -0
  31. package/src/adapters/gdrive.ts +213 -0
  32. package/src/adapters/root.ts +11 -1
  33. package/src/cli.ts +2 -1
  34. package/src/executable.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamilio/wire",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "description": "Attach Notion, Google Docs, Slack, Gmail, Asana, ChatGPT, and Zoom resources as local Markdown you can sync.",
5
5
  "keywords": [
6
6
  "markdown",
@@ -91,7 +91,7 @@
91
91
  "yaml"
92
92
  ],
93
93
  "scripts": {
94
- "build": "tsc -p tsconfig.json",
94
+ "build": "tsc -p tsconfig.json && echo 'export { PdfDocument, dictGet } from \"@poe-platform/safe-bash/pdf-ast\"' | esbuild --bundle --platform=node --format=esm --target=node20 --minify --outfile=dist/pdf-reader.mjs && cp -R ../../node_modules/@poe-platform/safe-bash/third-party/pdf-ast/. dist/adapters/pdf-notices/",
95
95
  "dev-link": "npm link",
96
96
  "prepack": "cp ../../README.md README.md && rm -rf node_modules && mkdir -p node_modules/@mixmark-io node_modules/@xmldom && for package in provider-asana provider-chatgpt provider-gmail provider-google-docs provider-lattice provider-notion provider-slack provider-zoom wire-core; do cp -R ../$package node_modules/$package; done && for package in @mixmark-io/domino @xmldom/xmldom entities turndown marked ajv commander fast-deep-equal fast-string-truncated-width fast-string-width fast-wrap-ansi fast-uri ignore jose jsonc-parser json-schema-traverse pct-encode require-from-string sisteransi smol-toml tiny-stdio-mcp-server toolcraft toolcraft-schema uri-template uri-template-lite yaml; do cp -R ../../node_modules/$package node_modules/$package; done",
97
97
  "postpack": "rm -rf node_modules README.md",
@@ -179,5 +179,11 @@
179
179
  "uri-template-lite",
180
180
  "wire-core",
181
181
  "yaml"
182
- ]
182
+ ],
183
+ "imports": {
184
+ "#pdf-reader": {
185
+ "types": "@poe-platform/safe-bash/pdf-ast",
186
+ "default": "./dist/pdf-reader.mjs"
187
+ }
188
+ }
183
189
  }
@@ -0,0 +1,106 @@
1
+ import { PdfDocument, dictGet } from "#pdf-reader";
2
+
3
+ export function pdfMarkdown(bytes: Uint8Array): string | null {
4
+ const doc = PdfDocument.load(bytes);
5
+ const lines = (i: number) => doc.extractPage(i, "raw").blocks.flatMap((b) => b.lines);
6
+ const cover = lines(0).map((l) => l.text);
7
+ const toc = cover.indexOf("TABLE OF CONTENTS");
8
+ if (toc < 1 || !(cover.includes("RESPONSES OVERVIEW") || cover.includes("MANAGER REVIEW"))) {
9
+ const text = doc.extractText({ mode: "logical" }).replace(/\f/g, "\n\n").trim();
10
+ return text ? text + "\n" : null;
11
+ }
12
+
13
+ // Some older packets specify MacRoman without a Unicode map. Decode the
14
+ // original character code only for those fonts; other encodings stay intact.
15
+ const macFonts = new Set<string>();
16
+ for (const { value } of doc.cos.objects.values()) {
17
+ if (value.kind !== "dict" || dictGet(value, "ToUnicode")) continue;
18
+ const encoding = dictGet(value, "Encoding"),
19
+ name = dictGet(value, "BaseFont");
20
+ if (encoding?.kind === "name" && encoding.decoded === "MacRomanEncoding" && name?.kind === "name")
21
+ macFonts.add(name.decoded);
22
+ }
23
+ const decoder = new TextDecoder("macintosh");
24
+ const out = ["# " + cover[0], ...cover.slice(1, toc).map((s) => "**" + s + "**")];
25
+ let lastY = 0,
26
+ question = false,
27
+ scale = false,
28
+ privateQuestion = false;
29
+ let byQuestion = false;
30
+ for (let i = 1; i < doc.pageCount; i++) {
31
+ for (const line of lines(i)) {
32
+ const [x, y] = line.bbox;
33
+ const size = line.words[0]?.fontSize;
34
+ const s = line.words
35
+ .map((word) =>
36
+ word.glyphs
37
+ .map((glyph, i, glyphs) => {
38
+ const prev = glyphs[i - 1];
39
+ const breakAfterLabel =
40
+ prev &&
41
+ /bold/i.test(prev.fontName) &&
42
+ !/bold/i.test(glyph.fontName) &&
43
+ /[a-z]$/.test(prev.unicode) &&
44
+ /^[A-Z]/.test(glyph.unicode);
45
+ const wordGap =
46
+ prev &&
47
+ glyph.bbox[0] - prev.bbox[2] > glyph.fontSize * 0.14 &&
48
+ /[\p{L}\p{N}]$/u.test(prev.unicode) &&
49
+ /^[\p{L}\p{N}]/u.test(glyph.unicode);
50
+ const text =
51
+ glyph.charCode >= 128 &&
52
+ glyph.charCode <= 255 &&
53
+ macFonts.has(glyph.fontName) &&
54
+ glyph.unicode === String.fromCharCode(glyph.charCode)
55
+ ? decoder.decode(Uint8Array.of(glyph.charCode))
56
+ : glyph.unicode;
57
+ return (breakAfterLabel || wordGap ? " " : "") + text;
58
+ })
59
+ .join(""),
60
+ )
61
+ .join(" ")
62
+ .trim();
63
+ if (y < 52 || !s) continue; // Running footer in the review export.
64
+ if (s === "Manager version only") {
65
+ privateQuestion = true;
66
+ continue;
67
+ }
68
+ if (size !== undefined && size >= 17 && Math.abs(x - 30) < 1) {
69
+ byQuestion = s === "Responses overview by question";
70
+ out.push("## " + s);
71
+ question = scale = false;
72
+ } else if (Math.abs(x - 30) < 1 && size !== undefined && Math.abs(size - 12) < 0.6 && /^\d+\. /.test(s)) {
73
+ if (privateQuestion) out.push("**Manager version only**");
74
+ privateQuestion = false;
75
+ out.push("### " + s);
76
+ question = true;
77
+ scale = false;
78
+ } else if (question && Math.abs(x - 30) < 1 && size !== undefined && Math.abs(size - 12) < 0.6) {
79
+ out[out.length - 1] += " " + s;
80
+ } else if (
81
+ (Math.abs(x - 60) < 1.5 || (x >= 30 && x < 60 && /^[A-Z]{1,4}$/.test(line.words[0]!.text))) &&
82
+ /\s(Self|Manager|Peer|Direct report|Upward)$/i.test(s)
83
+ ) {
84
+ const words = line.words.filter((w) => w.bbox[0] >= 58);
85
+ out.push("#### " + words.map((w) => w.text).join(" "));
86
+ question = scale = false;
87
+ } else if (byQuestion && question && s === "Manager") {
88
+ // The scale repeats the selected value in the reviewer's RATING card.
89
+ scale = true;
90
+ } else if (!scale) {
91
+ const label = s === "MULTIPLE CHOICE" || s === "RATING";
92
+ if (Math.abs(x - 30) < 1 && s.startsWith("Your response ")) out.push("*" + s + "*");
93
+ else if (label) out.push("**" + s + "**");
94
+ else if (/^[•◦▪]\s*/.test(s)) {
95
+ const bullet = s.replace(/^[•◦▪]\s*/, s.startsWith("◦") ? " - " : "- ");
96
+ if (/^(?:- | - )/m.test(out.at(-1)!)) out[out.length - 1] += "\n" + bullet;
97
+ else out.push(bullet);
98
+ } else if (question || lastY - y > 21 || /^\d+[.)]\s/.test(s) || /^#|^\*\*/.test(out.at(-1)!)) out.push(s);
99
+ else out[out.length - 1] += " " + s;
100
+ question = false;
101
+ }
102
+ lastY = y;
103
+ }
104
+ }
105
+ return out.join("\n\n") + "\n";
106
+ }
@@ -0,0 +1,213 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { lstat, mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
+ import { basename, extname, join } from "node:path";
4
+ import type { RuntimeCapabilities } from "wire-core";
5
+
6
+ const google = "application/vnd.google-apps.";
7
+ const formats: Record<string, [string, string]> = {
8
+ document: [".md", "text/markdown"],
9
+ spreadsheet: [".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
10
+ presentation: [".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"],
11
+ drawing: [".svg", "image/svg+xml"],
12
+ };
13
+ type File = { id: string; name: string; mimeType: string; version: string };
14
+ type Entry = { id: string; version?: string; hash?: string; noText?: true };
15
+ type State = { folder: string; entries: Record<string, Entry> };
16
+ const digest = (data: Uint8Array) => createHash("sha256").update(data).digest("hex");
17
+ async function stat(path: string) {
18
+ try {
19
+ return await lstat(path);
20
+ } catch (e) {
21
+ if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e;
22
+ }
23
+ }
24
+ async function save(path: string, data: string | Uint8Array) {
25
+ const tmp = path + "." + randomUUID();
26
+ await writeFile(tmp, data, { flag: "wx", mode: 0o600 });
27
+ await rename(tmp, path);
28
+ }
29
+
30
+ type DriveRuntime = Pick<RuntimeCapabilities, "googleFormsTokens" | "http">;
31
+ const folderUrl = /^https:\/\/drive\.google\.com\/drive\/(?:u\/\d+\/)?folders\/([\w-]+)\/?(?:[?#].*)?$/;
32
+ const safeName = (name: string) => name.replace(/[/\\:\x00-\x1f]/g, "_").replace(/^\.+/, "_") || "_";
33
+ async function drive(runtime: DriveRuntime, path: string, params: Record<string, string>) {
34
+ const token = await runtime.googleFormsTokens.load();
35
+ const response = await runtime.http.request(
36
+ "https://www.googleapis.com/drive/v3/files" + path + "?" + new URLSearchParams(params),
37
+ {
38
+ headers: { authorization: "Bearer " + token.token },
39
+ },
40
+ );
41
+ if (!response.ok) throw new Error("Drive HTTP " + response.status + ": " + (await response.text()).slice(0, 600));
42
+ return response;
43
+ }
44
+
45
+ async function* children(runtime: DriveRuntime, parent: string) {
46
+ let pageToken = "";
47
+ do {
48
+ const page = (await (
49
+ await drive(runtime, "", {
50
+ q: "'" + parent + "' in parents and trashed=false",
51
+ fields: "nextPageToken,files(id,name,mimeType,version)",
52
+ supportsAllDrives: "true",
53
+ includeItemsFromAllDrives: "true",
54
+ pageSize: "1000",
55
+ ...(pageToken ? { pageToken } : {}),
56
+ })
57
+ ).json()) as { nextPageToken?: string; files: File[] };
58
+ yield* page.files;
59
+ pageToken = page.nextPageToken ?? "";
60
+ } while (pageToken);
61
+ }
62
+
63
+ export async function previewDrive(runtime: DriveRuntime, url: string) {
64
+ const id = folderUrl.exec(url)?.[1] ?? /^https:\/\/drive\.google\.com\/file\/d\/([\w-]+)(?:[/?#].*)?$/.exec(url)?.[1];
65
+ if (!id) throw new Error("Expected a Drive folder or file URL.");
66
+ const item: File = await (
67
+ await drive(runtime, "/" + id, { fields: "id,name,mimeType", supportsAllDrives: "true" })
68
+ ).json();
69
+ if (item.mimeType === google + "folder") {
70
+ const rows = ["# " + item.name, ""];
71
+ for await (const f of children(runtime, id)) {
72
+ const link = f.mimeType === google + "folder" ? "drive/folders/" + f.id : "file/d/" + f.id + "/view";
73
+ rows.push("- [" + f.name.replace(/[\[\]\n]/g, "_") + "](https://drive.google.com/" + link + ")");
74
+ }
75
+ return rows.join("\n");
76
+ }
77
+ const format =
78
+ item.mimeType === google + "document"
79
+ ? "text/markdown"
80
+ : item.mimeType === google + "spreadsheet"
81
+ ? "text/csv"
82
+ : item.mimeType === google + "presentation"
83
+ ? "text/plain"
84
+ : undefined;
85
+ if (format) return (await drive(runtime, "/" + id + "/export", { mimeType: format })).text();
86
+ if (item.mimeType === "application/pdf" || /\.pdf$/i.test(item.name)) {
87
+ const response = await drive(runtime, "/" + id, { alt: "media", supportsAllDrives: "true" });
88
+ return (
89
+ (await import("./drive-pdf.js")).pdfMarkdown(new Uint8Array(await response.arrayBuffer())) ??
90
+ item.name + ": image-only PDF (no text layer)."
91
+ );
92
+ }
93
+ if (item.mimeType.startsWith("text/"))
94
+ return (await drive(runtime, "/" + id, { alt: "media", supportsAllDrives: "true" })).text();
95
+ return "# " + item.name + "\n\n" + item.mimeType;
96
+ }
97
+
98
+ export async function scrapeDrive(runtime: DriveRuntime, cwd: string, url?: string) {
99
+ const match = url?.match(folderUrl);
100
+ if (url && !match) throw new Error("Expected a Google Drive folder URL.");
101
+ if (match) {
102
+ const root = await (await drive(runtime, "/" + match[1], { fields: "name,mimeType", supportsAllDrives: "true" })).json();
103
+ if (root.mimeType !== google + "folder") throw new Error("The URL must identify a Drive folder.");
104
+ const name = safeName(root.name);
105
+ if (basename(cwd) !== name) {
106
+ cwd = join(cwd, name);
107
+ if (!(await stat(cwd))) await mkdir(cwd, { mode: 0o700 });
108
+ if (!(await lstat(cwd)).isDirectory()) throw new Error("Expected a local directory: " + cwd);
109
+ }
110
+ }
111
+ const manifest = join(cwd, ".wire-gdrive.json");
112
+ const state: State = (await stat(manifest))?.isFile()
113
+ ? JSON.parse(await readFile(manifest, "utf8"))
114
+ : { folder: match?.[1], entries: {} };
115
+ if (!state.folder) throw new Error("Pass a Drive folder URL on the first scrape.");
116
+ if (!match) await drive(runtime, "/" + encodeURIComponent(state.folder), { fields: "id", supportsAllDrives: "true" });
117
+ if (match && state.folder !== match[1]) throw new Error("This directory tracks a different Drive folder.");
118
+ let downloaded = 0,
119
+ unchanged = 0;
120
+ const errors: string[] = [],
121
+ skipped: string[] = [],
122
+ images: string[] = [];
123
+ async function visit(parent: string, dir: string) {
124
+ for await (const f of children(runtime, parent)) {
125
+ try {
126
+ if (f.name.endsWith(".cannedSearch") || f.name === ".DS_Store") continue;
127
+ const folder = f.mimeType === google + "folder",
128
+ pdf = f.mimeType === "application/pdf" || /\.pdf$/i.test(f.name);
129
+ const format = formats[f.mimeType.slice(google.length)];
130
+ if (!folder && !format && f.mimeType.startsWith(google)) {
131
+ skipped.push(f.name);
132
+ continue;
133
+ }
134
+ const name = safeName(f.name);
135
+ const suff = format?.[0] ?? "";
136
+ let path = join(dir, name + (name.endsWith(suff) ? "" : suff));
137
+ const paths = () => (pdf ? [path, path + ".md"] : [path]);
138
+ const key = (p: string) => "./" + p.normalize("NFC").toLowerCase();
139
+ const occupied = async () => {
140
+ for (const p of paths()) {
141
+ const owner = state.entries[key(p)];
142
+ if (owner ? owner.id !== f.id : await stat(join(cwd, p))) return true;
143
+ }
144
+ return false;
145
+ };
146
+ if (await occupied()) {
147
+ const ext = extname(path);
148
+ path = (ext ? path.slice(0, -ext.length) : path) + " (" + f.id + ")" + ext;
149
+ if (await occupied()) throw new Error("Destination name is already in use.");
150
+ }
151
+ const full = join(cwd, path);
152
+ if (folder) {
153
+ if (!(await stat(full))) await mkdir(full, { mode: 0o700 });
154
+ if (!(await lstat(full)).isDirectory()) throw new Error("Expected a local directory.");
155
+ state.entries[key(path)] = { id: f.id };
156
+ await visit(f.id, path);
157
+ continue;
158
+ }
159
+ let current = true;
160
+ for (const p of paths()) {
161
+ if (p !== path && state.entries[key(path)]?.noText) continue;
162
+ const entry = state.entries[key(p)],
163
+ info = await stat(join(cwd, p));
164
+ if (info && (!info.isFile() || digest(await readFile(join(cwd, p))) !== entry?.hash))
165
+ throw new Error("Local file changed: " + p);
166
+ if (!info || entry?.version !== f.version) current = false;
167
+ }
168
+ if (current) {
169
+ if (state.entries[key(path)]?.noText) images.push(path);
170
+ unchanged++;
171
+ continue;
172
+ }
173
+ const response = format
174
+ ? await drive(runtime, "/" + f.id + "/export", { mimeType: format[1] })
175
+ : await drive(runtime, "/" + f.id, { alt: "media", supportsAllDrives: "true" });
176
+ const bytes = new Uint8Array(await response.arrayBuffer());
177
+ await save(full, bytes);
178
+ state.entries[key(path)] = { id: f.id, version: f.version, hash: digest(bytes) };
179
+ if (pdf) {
180
+ const { pdfMarkdown } = await import("./drive-pdf.js");
181
+ const text = pdfMarkdown(bytes);
182
+ if (text === null) {
183
+ state.entries[key(path)]!.noText = true;
184
+ images.push(path);
185
+ downloaded++;
186
+ continue;
187
+ }
188
+ const md = Buffer.from(text);
189
+ await save(full + ".md", md);
190
+ state.entries[key(path + ".md")] = { id: f.id, version: f.version, hash: digest(md) };
191
+ }
192
+ downloaded++;
193
+ } catch (e) {
194
+ errors.push(join(dir, f.name) + ": " + (e as Error).message);
195
+ }
196
+ }
197
+ }
198
+ try {
199
+ await visit(state.folder, "");
200
+ } finally {
201
+ await save(manifest, JSON.stringify(state, null, 2) + "\n");
202
+ }
203
+ const summary =
204
+ "Drive: " +
205
+ downloaded +
206
+ " downloaded, " +
207
+ unchanged +
208
+ " unchanged." +
209
+ (images.length ? "\nPDFs with no text layer (originals kept): " + images.join(", ") : "") +
210
+ (skipped.length ? "\nUnsupported Drive items: " + skipped.join(", ") : "");
211
+ if (errors.length) throw new Error(summary + "\n" + errors.join("\n"));
212
+ return summary;
213
+ }
@@ -10,7 +10,7 @@ import { formatAgenda, type readAgenda } from "./calendar.js";
10
10
 
11
11
  export type WireRoot = Group;
12
12
  export type TextInputReader = () => Promise<string>;
13
- export type WireRootOptions = Readonly<{ allowPaste: boolean; calendarAgenda?: (date?: string, calendarId?: string) => ReturnType<typeof readAgenda>; latticeSync?: (url: string | undefined, file?: string) => Promise<string>; latticeRequests?: (url: string) => Promise<string>; latticeTemplate?: (url: string) => Promise<string>; latticeFill?: (url: string, file: string) => Promise<string>; scrapeZoom?: () => ReturnType<typeof zoomProvider.scrape> }>;
13
+ export type WireRootOptions = Readonly<{ allowPaste: boolean; previewDrive?: (url: string) => Promise<string>; scrapeDrive?: (url?: string) => Promise<string>; calendarAgenda?: (date?: string, calendarId?: string) => ReturnType<typeof readAgenda>; latticeSync?: (url: string | undefined, file?: string) => Promise<string>; latticeRequests?: (url: string) => Promise<string>; latticeTemplate?: (url: string) => Promise<string>; latticeFill?: (url: string, file: string) => Promise<string>; scrapeZoom?: () => ReturnType<typeof zoomProvider.scrape> }>;
14
14
 
15
15
  const authServices = ["asana", "chatgpt", "gmail", "google-docs", "notion", "slack", "zoom"] as const;
16
16
  const removedCliCommandNames = Object.freeze({
@@ -589,6 +589,16 @@ export function createRoot(wire: Wire, currentDirectory: string, auth?: Auth, re
589
589
  scope: ["cli", "mcp", "sdk"],
590
590
  children: [
591
591
  defaultAttach,
592
+ ...(options.scrapeDrive ? [defineGroup({ name: "gdrive", description: "Download Google Drive folders.", scope: ["cli"], children: [
593
+ ...(options.previewDrive ? [defineCommand({ name: "preview", description: "List a Drive folder or read a file without saving it.", scope: ["cli"], positional: ["url"],
594
+ params: S.Object({ url: S.String({description: "Google Drive folder or file URL."}) }),
595
+ handler: ({ params }) => userFacing(() => options.previewDrive!(params.url)), render: render<string>(v => v),
596
+ })] : []),
597
+ defineCommand({ name: "scrape", description: "Download into a directory named after the Drive folder. Run there without a URL to refresh.", scope: ["cli"], positional: ["url"],
598
+ params: S.Object({ url: S.Optional(S.String({ description: "Google Drive folder URL." })) }),
599
+ handler: ({ params }) => userFacing(() => options.scrapeDrive!(params.url)), render: render<string>(v => v),
600
+ }),
601
+ ] })] : []),
592
602
  ...(options.calendarAgenda ? [defineGroup({ name: "google-calendar", description: "Read Google Calendar.", scope: ["cli"], children: [
593
603
  defineCommand({ name: "agenda", description: "List events overlapping a local day across readable calendars.", scope: ["cli"],
594
604
  params: S.Object({
package/src/cli.ts CHANGED
@@ -243,6 +243,7 @@ function excessPositionals(argv: readonly string[]): Readonly<{ commandPath: str
243
243
  if (command === "slack" && slackResourceCommands.has(words[1]!)) return { commandPath: `slack ${words[1]}`, expected: 1, received: words.length - 2 };
244
244
  if ((command === "slack" || command === "notion" || command === "asana") && words[1] === "users" && words[2] === "lookup") return { commandPath: `${command} users lookup`, expected: 1, received: words.length - 3 };
245
245
  if (command === "slack" && (words[1] === "send" || words[1] === "edit")) return { commandPath: `slack ${words[1]}`, expected: 2, received: words.length - 2 };
246
+ if (command === "gdrive" && (words[1] === "scrape" || words[1] === "preview")) return { commandPath: `gdrive ${words[1]}`, expected: 1, received: words.length - 2 };
246
247
  if (command === "zoom" && words[1] === "scrape") return { commandPath: "zoom scrape", expected: 0, received: words.length - 2 };
247
248
  if (authServices.has(command)) {
248
249
  const authCommand = words[1];
@@ -361,7 +362,7 @@ function renderUnknownRootInput(argv: readonly string[]): boolean {
361
362
  const words = positionalWords(argv);
362
363
  if (words === null || words.length === 0) return false;
363
364
  const command = words[0]!;
364
- if ((!hasRootSeparator(argv) && (command in fixedCommandPositionals || command === "lattice" || command === "google-calendar" || authServices.has(command) || command in removedCommandNames)) || isSourceUrl(command)) return false;
365
+ if ((!hasRootSeparator(argv) && (command in fixedCommandPositionals || command === "lattice" || command === "google-calendar" || command === "gdrive" || authServices.has(command) || command in removedCommandNames)) || isSourceUrl(command)) return false;
365
366
  if (isSourceLikeWithoutScheme(command)) {
366
367
  renderCliError(argv, expectedSourceMessage("Expected source URL or command", command), "wire --help", expectedSourceMessage("Expected source URL or command", cliValue(command)));
367
368
  return true;
package/src/executable.ts CHANGED
@@ -9,6 +9,7 @@ import { listLatticeReviewRequests, latticeReviewDraft, syncLatticeDrafts } from
9
9
  import { zoomProvider } from "provider-zoom";
10
10
  import { lookupNotionUsers } from "provider-notion";
11
11
 
12
+ import { previewDrive, scrapeDrive } from "./adapters/gdrive.js";
12
13
  import { readAgenda } from "./adapters/calendar.js";
13
14
  import { createRoot } from "./adapters/root.js";
14
15
  import { composeAuth } from "./auth.js";
@@ -139,7 +140,7 @@ export function createExecutableRoot(environment: NodeEnvironment, currentDirect
139
140
  switchBackend: baseWire.switchBackend,
140
141
  });
141
142
  const wire = withWireHooks(configuredWire, { currentDirectory, home, environment: configuredEnvironment() });
142
- return createRoot(wire, currentDirectory, auth, readStandardInput, { ...options, calendarAgenda: (date, id) => readAgenda(processCapability, configuration.get("WIRE_REPOSITORY_ROOT"), date, id), latticeSync: (url,file) => syncLatticeDrafts(runtime,url,currentDirectory,file), latticeRequests: url => listLatticeReviewRequests(runtime,url), latticeTemplate: url => latticeReviewDraft(runtime,url), latticeFill: async (url,file) => latticeReviewDraft(runtime,url,await runtime.filesystem.readText(resolve(currentDirectory,file))), scrapeZoom: () => zoomProvider.scrape(runtime, currentDirectory) }, (destination, markdown) => sendSlackMessage(runtime, destination, markdown), (query) => lookupSlackUsers(runtime, query), (url, markdown) => editSlackMessage(runtime, url, markdown), (query) => lookupNotionUsers(runtime, query), {
143
+ return createRoot(wire, currentDirectory, auth, readStandardInput, { ...options, previewDrive: url => previewDrive(runtime,url), scrapeDrive: url => scrapeDrive(runtime, currentDirectory, url), calendarAgenda: (date, id) => readAgenda(processCapability, configuration.get("WIRE_REPOSITORY_ROOT"), date, id), latticeSync: (url,file) => syncLatticeDrafts(runtime,url,currentDirectory,file), latticeRequests: url => listLatticeReviewRequests(runtime,url), latticeTemplate: url => latticeReviewDraft(runtime,url), latticeFill: async (url,file) => latticeReviewDraft(runtime,url,await runtime.filesystem.readText(resolve(currentDirectory,file))), scrapeZoom: () => zoomProvider.scrape(runtime, currentDirectory) }, (destination, markdown) => sendSlackMessage(runtime, destination, markdown), (query) => lookupSlackUsers(runtime, query), (url, markdown) => editSlackMessage(runtime, url, markdown), (query) => lookupNotionUsers(runtime, query), {
143
144
  lookup: (query) => lookupAsanaUsers(runtime, query), projects: () => listAsanaProjects(runtime), project: (project) => showAsanaProject(runtime, project), tasks: (project) => listAsanaTasks(runtime, project), show: (task) => showAsanaTask(runtime, task),
144
145
  writes: { move: (task, project, section) => moveAsanaTask(runtime, task, project, section), create: (project, title, section, body, assignee) => createAsanaTask(runtime, project, title, section, body, assignee), edit: (task, fields) => editAsanaTask(runtime, task, fields), comment: (task, body) => addAsanaComment(runtime, task, body), editComment: (comment, body) => editAsanaComment(runtime, comment, body) },
145
146
  }, async () => {