diff --git a/changes/release-1.0.md b/changes/release-1.0.md new file mode 100644 index 0000000..ab238c0 --- /dev/null +++ b/changes/release-1.0.md @@ -0,0 +1,23 @@ +### Changed — may break callers + +- **drive runs on cli-core 1.0 and cli-base 1.0** (cli-core 1.0.0, was 0.750.0; cli-base 1.0.0, was 0.132.0). + cli-core 1.0 moves the message store to version 74 the first time it opens it: an id is never handed out twice, + and a JSON column holds valid JSON. After that, only tools on cli-core 1.0 open the store. Watch for: upgrade every + installed WireCat CLI to its 1.0 release first, and stop `serve`, `mcp` and every sync while the store migrates; + the migration writes a rollback copy first and refuses to run without one. See + [cli-core's changelog](https://github.com/WireCatLabs/cli-core/blob/main/CHANGELOG.md). + +### Fixed + +- **Over MCP, a Drive file or folder is passed as the agent wrote it.** The file id or URL of `drive files get`, + `copy`, `move`, `trash`, `download` and `export`, of `drive comments`, `permissions`, `revisions` and + `activities`, the folder of `drive catalog tree`, and the command path of `drive commands` were made absolute + against the client's folder, as if they named a file on this computer. + +### Security + +- **An MCP call cannot name a credential folder, a WireCat tool's folder or the message store.** Every option and + argument that takes a local file or folder (`drive files upload `, `drive files download --output`, + `--body-file` and the rest) is checked by its real path before the call runs, so neither a link nor `..` gets + past. A refused call answers `permission_error` (`access.denied`) with the option in `param`. A run in a terminal + is unchanged. diff --git a/package.json b/package.json index 31ae409..35fd518 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "@googleapis/drive": "27.0.0", "@googleapis/driveactivity": "11.0.1", "@googleapis/sheets": "18.1.1", - "@wirecat/cli-base": "0.132.0", - "@wirecat/cli-core": "0.750.0", + "@wirecat/cli-base": "1.0.0", + "@wirecat/cli-core": "1.0.0", "commander": "15.0.0", "google-auth-library": "11.3.1", "mammoth": "1.13.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 34b97f7..36d1678 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,11 +25,11 @@ importers: specifier: 18.1.1 version: 18.1.1 '@wirecat/cli-base': - specifier: 0.132.0 - version: 0.132.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) + specifier: 1.0.0 + version: 1.0.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) '@wirecat/cli-core': - specifier: 0.750.0 - version: 0.750.0(@wirecat/cli-base@0.132.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) + specifier: 1.0.0 + version: 1.0.0(@wirecat/cli-base@1.0.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) commander: specifier: 15.0.0 version: 15.0.0 @@ -1213,16 +1213,16 @@ packages: '@wasm-audio-decoders/opus-ml@0.0.3': resolution: {integrity: sha512-SEeTmk0eb3q5etJA/NHCRWW6BivTx9tqvNTmG0kg2ynuATEQRUZnwQE6Ibvl1BBvqIGHqI57+qyJMWmJBwb5XQ==} - '@wirecat/cli-base@0.132.0': - resolution: {integrity: sha512-y43hIGVFDUgVFTksTFnlK0KdLuROBDcv0smqme4/WSjkUS3PaGQnuAvu09G2VvW0zmvM2+OHFuQaZEN3Hir8nQ==} - engines: {node: '>=22'} + '@wirecat/cli-base@1.0.0': + resolution: {integrity: sha512-PJ61d6z0CsWOmoWgf7uvlEo3EstpL2DplXiORPIqgmh0bn/ZGMOhRpDqN43Kh7WickaFSmeX74YQigHXkRO6rA==} + engines: {node: ^22.16.0 || >=24} hasBin: true peerDependencies: '@scalar/openapi-upgrader': ^0.4.6 - commander: '>=15' + commander: ^15.0.0 esbuild: ^0.28.0 swagger-converter: ^2.1.0 - vitest: '>=5' + vitest: ^5.0.0 peerDependenciesMeta: '@scalar/openapi-upgrader': optional: true @@ -1241,14 +1241,14 @@ packages: '@wirecat/cli-core-sqlite@1.1.0': resolution: {integrity: sha512-GpGlh/dAIX/nblBYCdT6DfWSLFxav9mxxeELQAfEuw+QZdT9unKxbi5xa02s/s4JS1P7n0PQx2sCABj4FlMRNw==} - '@wirecat/cli-core@0.750.0': - resolution: {integrity: sha512-9xUOyRg8cAmb64EJ37thM6AbNNy3xbgVRMhCjTjKU9xN0osUWO1euXB8IN+qmgn1W7aQU2tuXP4XcsuJUY2Evw==} + '@wirecat/cli-core@1.0.0': + resolution: {integrity: sha512-0avQTqu3FAFKE0s+8Pz1Up/TMHTYqCdDn37lcZmkH30sMCMrgJwHzoG4Q0fjVzPsB85u+zBVHHhtQjF/eSTpuw==} engines: {node: ^22.16.0 || >=24} hasBin: true peerDependencies: '@napi-rs/canvas': '>=0.1.69 <2' - '@wirecat/cli-base': '>=0.125.0 <1.0.0' - commander: '>=15' + '@wirecat/cli-base': ^1.0.0-0 + commander: ^15.0.0 mysql2: ^3.24.6 pg: ^8.23.1 ssh2: ^1.17.0 @@ -3533,7 +3533,7 @@ snapshots: dependencies: '@wasm-audio-decoders/common': 9.0.7 - '@wirecat/cli-base@0.132.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5)': + '@wirecat/cli-base@1.0.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5)': dependencies: '@valibot/to-json-schema': 1.8.0(valibot@1.5.0(typescript@7.0.2)) cli-table3: 0.6.5 @@ -3554,7 +3554,7 @@ snapshots: '@wirecat/cli-core-sqlite@1.1.0': {} - '@wirecat/cli-core@0.750.0(@wirecat/cli-base@0.132.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': + '@wirecat/cli-core@1.0.0(@wirecat/cli-base@1.0.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': dependencies: '@anthropic-ai/sdk': 1.3.0(zod@4.6.7) '@bomb.sh/tab': 0.0.22(commander@15.0.0) @@ -3564,7 +3564,7 @@ snapshots: '@valibot/to-json-schema': 1.8.0(valibot@1.5.0(typescript@7.0.2)) '@wasm-audio-decoders/flac': 0.2.11 '@wasm-audio-decoders/ogg-vorbis': 0.1.20 - '@wirecat/cli-base': 0.132.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) + '@wirecat/cli-base': 1.0.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) '@wirecat/cli-core-onnx': 1.2.0 '@wirecat/cli-core-sqlite': 1.1.0 '@xmldom/xmldom': 0.9.12 diff --git a/src/api-contract.ts b/src/api-contract.ts index 0487bdc..8ce17e5 100644 --- a/src/api-contract.ts +++ b/src/api-contract.ts @@ -1,5 +1,5 @@ import { CliError } from "@wirecat/cli-base" -import type { ManifestOperation } from "@wirecat/cli-base/codegen" +import type { ManifestOperation } from "@wirecat/cli-base/codegen/runtime" import { apiJson, apiPlainJson, checkApiBody, checkApiParameter, parseApiJson } from "@wirecat/cli-core/cli" import { operations } from "./generated/manifest.js" import { schemas } from "./generated/schemas.js" diff --git a/src/catalog.ts b/src/catalog.ts index 28fd3f8..54c28c8 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -1,4 +1,4 @@ -import type { CatalogEntry, CatalogInput, CatalogQuery } from "@wirecat/cli-core/store" +import type { CatalogEntry, CatalogInput, CatalogQuery } from "@wirecat/cli-core/store/areas" import { type FileMetadata, FOLDER } from "./model.js" export const catalogInput = (file: FileMetadata): CatalogInput => ({ diff --git a/src/commands/catalog.ts b/src/commands/catalog.ts index 1878320..8a1f600 100644 --- a/src/commands/catalog.ts +++ b/src/commands/catalog.ts @@ -1,3 +1,4 @@ +import { notLocalPaths } from "@wirecat/cli-core/cli" import { addDocumentCatalogCommands } from "@wirecat/cli-core/documents/cli" import type { Command } from "commander" import { catalogFiles } from "../catalog.js" @@ -52,4 +53,7 @@ export const installCatalogCommands = (program: Command, helpers: Helpers) => { id: fileId, roots: () => activeProfile(env, selected()).roots, }) + // cli-core marks only catalog's ; `catalog tree [folder]` takes a Drive folder too. + const catalog = program.commands.find((command) => command.name() === "catalog") + if (catalog) notLocalPaths(catalog, "folder") } diff --git a/src/commands/discovery.ts b/src/commands/discovery.ts index 34b3096..41e5c3d 100644 --- a/src/commands/discovery.ts +++ b/src/commands/discovery.ts @@ -5,6 +5,7 @@ import { DISCOVERY_DESCRIPTIONS, environmentOf, NO_EFFECTS, + notLocalPaths, sharedCommandTemplate, } from "@wirecat/cli-core/cli" import type { Command } from "commander" @@ -15,7 +16,9 @@ import type { CommandContext } from "./context.js" const installCommandsCommandDefinition = (program: Command, { print, streams }: CommandContext) => { examples( - annotate(program.command("commands"), { effects: NO_EFFECTS }).description(DISCOVERY_DESCRIPTIONS.commands), + notLocalPaths(annotate(program.command("commands"), { effects: NO_EFFECTS }), "path").description( + DISCOVERY_DESCRIPTIONS.commands, + ), ["drive commands", "drive commands files copy --json"], ) .argument("[path...]", "only this command or group, as words") diff --git a/src/commands/remote.ts b/src/commands/remote.ts index cabaedd..399a363 100644 --- a/src/commands/remote.ts +++ b/src/commands/remote.ts @@ -14,6 +14,7 @@ import { LOCAL_READ, listOf, NO_EFFECTS, + notLocalPaths, queryTerms, readApiBody, snakeKeys, @@ -170,7 +171,7 @@ export const installRemoteCommands = (program: Command, helpers: RemoteCommands) api.addCommand(child) } installSheetsCommands(program, helpers) - const files = annotate(program.command("files"), { effects: GOOGLE_READ }).description( + const files = notLocalPaths(annotate(program.command("files"), { effects: GOOGLE_READ }), "file").description( "read and change files in Google Drive; nothing is imported", ) for (const exporting of [false, true]) { @@ -426,9 +427,10 @@ export const installRemoteCommands = (program: Command, helpers: RemoteCommands) .action(async (id: string, args) => output(itemOf(await call("docs.documents.batchUpdate", { documentId: fileId(id) }, args.body))), ) - const activities = annotate(program.command("activities"), { effects: GOOGLE_READ }).description( - "read who did what with a file in Google Drive", - ) + const activities = notLocalPaths( + annotate(program.command("activities"), { effects: GOOGLE_READ }), + "file", + ).description("read who did what with a file in Google Drive") const activityRow = v.looseObject({ timestamp: v.optional(v.string()) }) const activityQuery = unfilteredQuery("drive_remote_activity", activityRow) bindQuery( @@ -460,7 +462,7 @@ export const installRemoteCommands = (program: Command, helpers: RemoteCommands) }) for (const resource of ["comments", "permissions", "revisions"] as const) { const one = resource.slice(0, -1) - const group = annotate(program.command(resource), { effects: GOOGLE_READ }).description( + const group = notLocalPaths(annotate(program.command(resource), { effects: GOOGLE_READ }), "file").description( `read the ${resource} of a file in Google Drive`, ) if (resource === "comments") { diff --git a/src/documents-add.ts b/src/documents-add.ts index f6ae586..e34a3d4 100644 --- a/src/documents-add.ts +++ b/src/documents-add.ts @@ -1,5 +1,5 @@ import { CliError, isCliError } from "@wirecat/cli-base" -import type { AddedSource, AddedSourceInput } from "@wirecat/cli-core/store" +import type { AddedSource, AddedSourceInput } from "@wirecat/cli-core/store/areas" import { activeProfile, fileId, diff --git a/src/file-edit.test.ts b/src/file-edit.test.ts index 223c2bc..a69ff42 100644 --- a/src/file-edit.test.ts +++ b/src/file-edit.test.ts @@ -362,4 +362,11 @@ describe("the MCP catalogue", () => { "files history": false, }) }) + + it("offers no sheets or documents create: Google Drive names a new file by the id it gives", () => { + const tools = toolsFromCommands(describeProgram(commandTree()), { includeUnavailable: true, exclude: [["mcp"]] }) + const paths = tools.map((tool) => tool.path.join(" ")) + expect(paths).not.toContain("files sheets create") + expect(paths).not.toContain("files documents create") + }) }) diff --git a/src/generated/definitions.ts b/src/generated/definitions.ts index 43f37a2..a78f0ec 100644 --- a/src/generated/definitions.ts +++ b/src/generated/definitions.ts @@ -2,7 +2,7 @@ // Source: spec/google/*.json, verified by provenance.json // Run: pnpm generate -import type { SchemaNode } from "@wirecat/cli-base/codegen" +import type { SchemaNode } from "@wirecat/cli-base/codegen/runtime" export const definitions: Readonly> = { DriveOperation: { diff --git a/src/generated/manifest.ts b/src/generated/manifest.ts index 2b791b7..ed5ee5e 100644 --- a/src/generated/manifest.ts +++ b/src/generated/manifest.ts @@ -2,7 +2,7 @@ // Source: spec/google/*.json, verified by provenance.json // Run: pnpm generate -import type { ManifestOperation, SecurityScheme } from "@wirecat/cli-base/codegen" +import type { ManifestOperation, SecurityScheme } from "@wirecat/cli-base/codegen/runtime" export const operations: readonly ManifestOperation[] = [ { diff --git a/src/knowledge.test.ts b/src/knowledge.test.ts index f1aef8a..94db68a 100644 --- a/src/knowledge.test.ts +++ b/src/knowledge.test.ts @@ -1,6 +1,7 @@ import { listQuery } from "@wirecat/cli-core/cli" import { proposalRegistry } from "@wirecat/cli-core/services" -import { IMPORTED_DOCUMENT_QUERY, openStore } from "@wirecat/cli-core/store" +import { openStore } from "@wirecat/cli-core/store" +import { IMPORTED_DOCUMENT_QUERY } from "@wirecat/cli-core/store/areas" import { describe, expect, it } from "vitest" import { openIndex } from "./store.js" import { content, file, fixture } from "./testing.js" diff --git a/src/knowledge.ts b/src/knowledge.ts index 410b1ff..dce1d21 100644 --- a/src/knowledge.ts +++ b/src/knowledge.ts @@ -4,7 +4,8 @@ import { documentKnowledge as sharedKnowledge, } from "@wirecat/cli-core/documents" import { factItem, memoryItem } from "@wirecat/cli-core/documents/cli" -import type { LinkInput, MessageStore, PersonRecord } from "@wirecat/cli-core/store" +import type { MessageStore, PersonRecord } from "@wirecat/cli-core/store" +import type { LinkInput } from "@wirecat/cli-core/store/areas" import type { FileMetadata, GoogleUser } from "./model.js" export interface DocumentKnowledge extends SharedDocumentKnowledge { context(principal: string, ref: string): Promise diff --git a/src/model.ts b/src/model.ts index 57fe556..16e4c71 100644 --- a/src/model.ts +++ b/src/model.ts @@ -11,7 +11,7 @@ import type { SourceWork, } from "@wirecat/cli-core/documents" import type { DocumentHistoryPort } from "@wirecat/cli-core/documents/cli" -import type { AddedSource, AddedSourceInput } from "@wirecat/cli-core/store" +import type { AddedSource, AddedSourceInput } from "@wirecat/cli-core/store/areas" export type { PictureWriter, TabText } from "@wirecat/cli-core/documents" export const FOLDER = "application/vnd.google-apps.folder" diff --git a/src/schema.ts b/src/schema.ts index 5116a36..76a4dea 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1,4 +1,4 @@ -import { identifier, type SchemaNode } from "@wirecat/cli-base/codegen" +import { identifier, type SchemaNode } from "@wirecat/cli-base/codegen/runtime" import { operationOf } from "./api-contract.js" import { definitions } from "./generated/definitions.js" export const requestSchema = (method: string) => {