@wirecat/notion-cli 0.0.0-stage → 0.2.0
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/CHANGELOG.md +73 -0
- package/LICENSE +204 -0
- package/README.md +42 -2
- package/contracts/wirecat.json +1964 -0
- package/dist/bin/notion.d.ts +3 -0
- package/dist/bin/notion.d.ts.map +1 -0
- package/dist/bin/notion.js +40 -0
- package/dist/bin/notion.js.map +1 -0
- package/dist/bundle/all-profiles-JGYLQZ5C.js +278 -0
- package/dist/bundle/anthropic-S2VSMIKQ.js +91 -0
- package/dist/bundle/app-server-SASYDBCA.js +240 -0
- package/dist/bundle/bun-LU5LP3JI.js +169 -0
- package/dist/bundle/bun-sqlite-JBSINB4O.js +76 -0
- package/dist/bundle/chunk-22QQUKWA.js +53 -0
- package/dist/bundle/chunk-2F4QQ7WB.js +73 -0
- package/dist/bundle/chunk-2F6VO5HA.js +73 -0
- package/dist/bundle/chunk-2LWO3PDX.js +726 -0
- package/dist/bundle/chunk-3AL7QUS3.js +2778 -0
- package/dist/bundle/chunk-3Z4YTSRY.js +731 -0
- package/dist/bundle/chunk-4HWJOU7N.js +38 -0
- package/dist/bundle/chunk-4IPURN72.js +1221 -0
- package/dist/bundle/chunk-4ZTVJHWU.js +206 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5IYKVRH2.js +44811 -0
- package/dist/bundle/chunk-5NFK5EM2.js +362 -0
- package/dist/bundle/chunk-5QIQEUOG.js +188 -0
- package/dist/bundle/chunk-5RDNBG7D.js +72 -0
- package/dist/bundle/chunk-5RSC54NA.js +1328 -0
- package/dist/bundle/chunk-6EVKHZKN.js +158 -0
- package/dist/bundle/chunk-6RA3EABS.js +4012 -0
- package/dist/bundle/chunk-AOCUKEAX.js +131 -0
- package/dist/bundle/chunk-B26TQZKZ.js +217 -0
- package/dist/bundle/chunk-B7ON6KPT.js +1197 -0
- package/dist/bundle/chunk-BNPTZ5ZB.js +161 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-D7QSEEYW.js +274 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DH5PRHT4.js +392 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EUIVXFLJ.js +259 -0
- package/dist/bundle/chunk-FPY6EJ7B.js +9568 -0
- package/dist/bundle/chunk-FT3LN3HP.js +6848 -0
- package/dist/bundle/chunk-FWVBPRL4.js +4436 -0
- package/dist/bundle/chunk-FXEJY4OL.js +12538 -0
- package/dist/bundle/chunk-G3EZFRSS.js +1297 -0
- package/dist/bundle/chunk-GZOUFX3C.js +230 -0
- package/dist/bundle/chunk-HL52XXZX.js +78 -0
- package/dist/bundle/chunk-KCLOUUYF.js +100 -0
- package/dist/bundle/chunk-KFVDL2QS.js +146 -0
- package/dist/bundle/chunk-KGERXYTV.js +24 -0
- package/dist/bundle/chunk-KM6WHPHI.js +288 -0
- package/dist/bundle/chunk-LAYPFBOM.js +95 -0
- package/dist/bundle/chunk-LLG2POQ7.js +170 -0
- package/dist/bundle/chunk-M3KB25D3.js +1392 -0
- package/dist/bundle/chunk-M7S2NDWB.js +76 -0
- package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
- package/dist/bundle/chunk-MY742GAD.js +1977 -0
- package/dist/bundle/chunk-MZU2YFBZ.js +823 -0
- package/dist/bundle/chunk-NOQ7B5N7.js +58 -0
- package/dist/bundle/chunk-NQWV4WQO.js +300 -0
- package/dist/bundle/chunk-ODBZNSZ6.js +1028 -0
- package/dist/bundle/chunk-OTV53F34.js +370 -0
- package/dist/bundle/chunk-P7CUM5IB.js +18 -0
- package/dist/bundle/chunk-RV64YUQX.js +185 -0
- package/dist/bundle/chunk-SHJQ6JKG.js +106 -0
- package/dist/bundle/chunk-SWAOWNKW.js +52 -0
- package/dist/bundle/chunk-SZOVLP44.js +29 -0
- package/dist/bundle/chunk-TPX2M45D.js +385 -0
- package/dist/bundle/chunk-TSDBSIFM.js +66 -0
- package/dist/bundle/chunk-VBHETQVV.js +64146 -0
- package/dist/bundle/chunk-VCIALTEM.js +3139 -0
- package/dist/bundle/chunk-VKE77B3F.js +2 -0
- package/dist/bundle/chunk-WCSOH4JS.js +142 -0
- package/dist/bundle/chunk-WF4D56CA.js +54 -0
- package/dist/bundle/chunk-WJHZMR2W.js +335 -0
- package/dist/bundle/chunk-X4TIMMKJ.js +16 -0
- package/dist/bundle/chunk-XF26XKTS.js +82 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YMYUBZWT.js +1068 -0
- package/dist/bundle/chunk-YNTLT3Z3.js +2310 -0
- package/dist/bundle/chunk-YVI5SQPY.js +46 -0
- package/dist/bundle/chunk-Z56QFOBR.js +63 -0
- package/dist/bundle/chunk-ZKAEZXUP.js +787 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/chunk-ZZ32DXTH.js +23 -0
- package/dist/bundle/command-contract-JS5V27NX.js +38 -0
- package/dist/bundle/command-server-entry-UFSG7KRO.js +167 -0
- package/dist/bundle/decode-7LLWTSPT.js +297 -0
- package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
- package/dist/bundle/dispatch-2GY6JIJH.js +411 -0
- package/dist/bundle/dist-ILNOLGYN.js +7577 -0
- package/dist/bundle/echarts-BXX4OQWC.js +42501 -0
- package/dist/bundle/embed-JXFNBTKH.js +38 -0
- package/dist/bundle/embedder-57YZ44KO.js +111 -0
- package/dist/bundle/failure-MYT4HPE3.js +25 -0
- package/dist/bundle/first-run-3PF7T74J.js +29 -0
- package/dist/bundle/first-screen-7BEROEQR.js +36 -0
- package/dist/bundle/instructions-2VECIDXF.js +11 -0
- package/dist/bundle/mcp-O6ACR2DX.js +167 -0
- package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
- package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
- package/dist/bundle/meeting-combined-PPUQ3KBR.js +24 -0
- package/dist/bundle/meeting-model-ZNMYKMCD.js +26 -0
- package/dist/bundle/meeting-semantic-ETN3A4BJ.js +22 -0
- package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-MPEQSFI3.js +176 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-WA32MYSJ.js +74 -0
- package/dist/bundle/notion.js +185 -0
- package/dist/bundle/oauth-IAFZG3IR.js +20 -0
- package/dist/bundle/open-M3JQUC5G.js +23 -0
- package/dist/bundle/openai-HXUEHUSD.js +240 -0
- package/dist/bundle/process-F6TKXWWA.js +91 -0
- package/dist/bundle/program-Y7JAB6TG.js +33219 -0
- package/dist/bundle/prompt-IMUQLZD2.js +17 -0
- package/dist/bundle/recognize-2MZAYHAA.js +26 -0
- package/dist/bundle/remote-OV4LB6VR.js +32 -0
- package/dist/bundle/rerank-ZIULUS34.js +52 -0
- package/dist/bundle/schemas-DIVZS6TU.js +12214 -0
- package/dist/bundle/serve-YU7QBP6L.js +199 -0
- package/dist/bundle/server-FKQET4ZO.js +71 -0
- package/dist/bundle/server-LGMNONSB.js +202 -0
- package/dist/bundle/services-5WY4DCPJ.js +581 -0
- package/dist/bundle/sqlite-runtime-5MXZDETH.js +20 -0
- package/dist/bundle/state-LWMZH2KI.js +36 -0
- package/dist/bundle/store-EPZYV4VW.js +168 -0
- package/dist/bundle/store-QE6FEIZD.js +286 -0
- package/dist/bundle/store-maintenance-command-ZUUUFCHL.js +62 -0
- package/dist/commands/api.d.ts +4 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +140 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/databases.d.ts +3 -0
- package/dist/commands/databases.d.ts.map +1 -0
- package/dist/commands/databases.js +65 -0
- package/dist/commands/databases.js.map +1 -0
- package/dist/commands/documents.d.ts +4 -0
- package/dist/commands/documents.d.ts.map +1 -0
- package/dist/commands/documents.js +41 -0
- package/dist/commands/documents.js.map +1 -0
- package/dist/commands/library.d.ts +10 -0
- package/dist/commands/library.d.ts.map +1 -0
- package/dist/commands/library.js +468 -0
- package/dist/commands/library.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +105 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +51 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +67 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +45603 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +3 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +2089 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/metadata.d.ts +6 -0
- package/dist/generated/metadata.d.ts.map +1 -0
- package/dist/generated/metadata.js +24 -0
- package/dist/generated/metadata.js.map +1 -0
- package/dist/generated/schemas.d.ts +1223 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +11557 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +11120 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +30 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge.d.ts +27 -0
- package/dist/knowledge.d.ts.map +1 -0
- package/dist/knowledge.js +87 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/library.d.ts +44 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +149 -0
- package/dist/library.js.map +1 -0
- package/dist/notion/client.d.ts +45 -0
- package/dist/notion/client.d.ts.map +1 -0
- package/dist/notion/client.js +121 -0
- package/dist/notion/client.js.map +1 -0
- package/dist/notion/errors.d.ts +24 -0
- package/dist/notion/errors.d.ts.map +1 -0
- package/dist/notion/errors.js +127 -0
- package/dist/notion/errors.js.map +1 -0
- package/dist/notion/ids.d.ts +7 -0
- package/dist/notion/ids.d.ts.map +1 -0
- package/dist/notion/ids.js +37 -0
- package/dist/notion/ids.js.map +1 -0
- package/dist/notion/links.d.ts +6 -0
- package/dist/notion/links.d.ts.map +1 -0
- package/dist/notion/links.js +22 -0
- package/dist/notion/links.js.map +1 -0
- package/dist/notion/notion.d.ts +95 -0
- package/dist/notion/notion.d.ts.map +1 -0
- package/dist/notion/notion.js +269 -0
- package/dist/notion/notion.js.map +1 -0
- package/dist/notion/port.d.ts +13 -0
- package/dist/notion/port.d.ts.map +1 -0
- package/dist/notion/port.js +60 -0
- package/dist/notion/port.js.map +1 -0
- package/dist/notion/read-posts.d.ts +36 -0
- package/dist/notion/read-posts.d.ts.map +1 -0
- package/dist/notion/read-posts.js +24 -0
- package/dist/notion/read-posts.js.map +1 -0
- package/dist/notion/reads.d.ts +331 -0
- package/dist/notion/reads.d.ts.map +1 -0
- package/dist/notion/reads.js +18 -0
- package/dist/notion/reads.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +62 -0
- package/dist/program.js.map +1 -0
- package/dist/sync/cursor.d.ts +135 -0
- package/dist/sync/cursor.d.ts.map +1 -0
- package/dist/sync/cursor.js +113 -0
- package/dist/sync/cursor.js.map +1 -0
- package/dist/sync/files.d.ts +77 -0
- package/dist/sync/files.d.ts.map +1 -0
- package/dist/sync/files.js +12 -0
- package/dist/sync/files.js.map +1 -0
- package/dist/sync/front-matter.d.ts +10 -0
- package/dist/sync/front-matter.d.ts.map +1 -0
- package/dist/sync/front-matter.js +114 -0
- package/dist/sync/front-matter.js.map +1 -0
- package/dist/sync/markdown.d.ts +11 -0
- package/dist/sync/markdown.d.ts.map +1 -0
- package/dist/sync/markdown.js +42 -0
- package/dist/sync/markdown.js.map +1 -0
- package/dist/sync/source.d.ts +11 -0
- package/dist/sync/source.d.ts.map +1 -0
- package/dist/sync/source.js +995 -0
- package/dist/sync/source.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +85 -4
- package/skills/notion-cli/SKILL.md +45 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { answerEntity, commandPath, itemOf, listOf, outputFor, positiveCount, queryTerms, REMOTE_READ, renderAnswer, termField, withQuery, } from "@wirecat/cli-core/cli";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { withNotion } from "../context.js";
|
|
5
|
+
import { IDENTITY } from "../identity.js";
|
|
6
|
+
import { notionId } from "../notion/ids.js";
|
|
7
|
+
import { databaseRowSchema, databaseSchema } from "../notion/notion.js";
|
|
8
|
+
const CLI = IDENTITY.command;
|
|
9
|
+
/** Notion's page size: a default of 100, which is also its most ([pagination](https://developers.notion.com/reference/pagination)). */
|
|
10
|
+
const LARGEST_PAGE = 100;
|
|
11
|
+
const DEFAULT_PAGE = 50;
|
|
12
|
+
/** Notion's search matches its `query` against titles ([search](https://developers.notion.com/reference/post-search)). */
|
|
13
|
+
const DATABASES_QUERY = {
|
|
14
|
+
entity: "database",
|
|
15
|
+
backend: "native",
|
|
16
|
+
fields: [termField("title", "txt", "title:Roadmap")],
|
|
17
|
+
};
|
|
18
|
+
const listCommand = () => withQuery(answerEntity(annotate(new Command("list"), {
|
|
19
|
+
effects: REMOTE_READ,
|
|
20
|
+
offline: false,
|
|
21
|
+
examples: [
|
|
22
|
+
`${CLI} personal databases list`,
|
|
23
|
+
`${CLI} personal databases list title:Roadmap --json=id,data_source_id,title`,
|
|
24
|
+
],
|
|
25
|
+
}), "database", databaseRowSchema), DATABASES_QUERY)
|
|
26
|
+
.summary("list the databases this token can see, live, one row per data source")
|
|
27
|
+
.description("list the databases this token can see, live from Notion's search: one row for each data source, with the " +
|
|
28
|
+
"database it belongs to. Notion's search can lag behind a new database by a few minutes")
|
|
29
|
+
.option("--limit <n>", `at most this many, up to ${LARGEST_PAGE}; ${DEFAULT_PAGE} if not given`, positiveCount("--limit"))
|
|
30
|
+
.option("--cursor <cursor>", "go on from where the last page stopped; page.next gives it")
|
|
31
|
+
.action(async function (words) {
|
|
32
|
+
const title = queryTerms(words, DATABASES_QUERY, commandPath(this)).get("title");
|
|
33
|
+
const { limit = DEFAULT_PAGE, cursor } = this.opts();
|
|
34
|
+
const size = Math.min(limit, LARGEST_PAGE);
|
|
35
|
+
const found = await withNotion(this, (notion) => notion.databases({ limit: size, cursor, title }));
|
|
36
|
+
renderAnswer(this, outputFor(this), listOf(commandPath(this), {
|
|
37
|
+
items: found.items,
|
|
38
|
+
limit: size,
|
|
39
|
+
has_more: found.hasMore,
|
|
40
|
+
paging: "cursor",
|
|
41
|
+
...(found.cursor === undefined ? {} : { cursor: found.cursor }),
|
|
42
|
+
...(words.length ? { args: { query: words.join(" ") } } : {}),
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
const showCommand = () => answerEntity(annotate(new Command("show"), {
|
|
46
|
+
effects: REMOTE_READ,
|
|
47
|
+
offline: false,
|
|
48
|
+
examples: [
|
|
49
|
+
`${CLI} personal databases show 0123456789abcdef0123456789abcdef`,
|
|
50
|
+
`${CLI} personal databases show https://www.notion.so/0123456789abcdef0123456789abcdef --json`,
|
|
51
|
+
],
|
|
52
|
+
}), "database", databaseSchema)
|
|
53
|
+
.summary("show one database live: its data sources, their ids and properties")
|
|
54
|
+
.description("show one database live from Notion: its title, where it sits, and each of its data sources with its id and " +
|
|
55
|
+
"its properties, with the options of each select and status; a query of the database names a data source id")
|
|
56
|
+
.argument("<database>", "the database's id or its Notion link")
|
|
57
|
+
.action(async function (database) {
|
|
58
|
+
const id = notionId(database, "database");
|
|
59
|
+
renderAnswer(this, outputFor(this), itemOf(await withNotion(this, (notion) => notion.database(id))));
|
|
60
|
+
});
|
|
61
|
+
export const databasesCommand = () => annotate(new Command("databases"), { effects: REMOTE_READ })
|
|
62
|
+
.description("read Notion databases and their data sources")
|
|
63
|
+
.addCommand(listCommand())
|
|
64
|
+
.addCommand(showCommand());
|
|
65
|
+
//# sourceMappingURL=databases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"databases.js","sourceRoot":"","sources":["../../src/commands/databases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,MAAM,EACN,MAAM,EACN,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,GACV,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEvE,MAAM,GAAG,GAAG,QAAQ,CAA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MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AACtG,CAAC,CAAC,CAAA;AAEN,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAY,EAAE,CAC5C,QAAQ,CAAC,IAAI,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;KACzD,WAAW,CAAC,8CAA8C,CAAC;KAC3D,UAAU,CAAC,WAAW,EAAE,CAAC;KACzB,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../src/commands/documents.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC,2FAA2F;AAC3F,eAAO,MAAM,UAAU,eAyCjB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { visibleControls } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { answerEntity, itemOf, outputFor, REMOTE_READ, renderAnswer } from "@wirecat/cli-core/cli";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { withNotion } from "../context.js";
|
|
6
|
+
import { IDENTITY } from "../identity.js";
|
|
7
|
+
import { notionId } from "../notion/ids.js";
|
|
8
|
+
import { documentSchema } from "../notion/notion.js";
|
|
9
|
+
const CLI = IDENTITY.command;
|
|
10
|
+
/** `documents get`: one page live, beside the shared commands that read the local copy. */
|
|
11
|
+
export const getCommand = () => answerEntity(annotate(new Command("get"), {
|
|
12
|
+
effects: REMOTE_READ,
|
|
13
|
+
offline: false,
|
|
14
|
+
examples: [
|
|
15
|
+
`${CLI} personal documents get https://www.notion.so/Roadmap-0123456789abcdef0123456789abcdef`,
|
|
16
|
+
`${CLI} personal documents get 0123456789abcdef0123456789abcdef --json`,
|
|
17
|
+
],
|
|
18
|
+
}), "document_markdown", documentSchema)
|
|
19
|
+
.summary("read one page live from Notion, as Markdown")
|
|
20
|
+
.description("read one page live from Notion as Notion-flavoured Markdown. A page too long for one answer is read in parts; " +
|
|
21
|
+
"a part the token may not see is listed in missing_block_ids, and a page that is not whole answers " +
|
|
22
|
+
"meta.complete false and exits non-zero. Signed file links lose their signature, " +
|
|
23
|
+
"so the output never carries a link that opens the file")
|
|
24
|
+
.argument("<page>", "the page's id or its Notion link")
|
|
25
|
+
.action(async function (page) {
|
|
26
|
+
const id = notionId(page);
|
|
27
|
+
const { document, issues } = await withNotion(this, (notion) => notion.document(id));
|
|
28
|
+
const output = outputFor(this);
|
|
29
|
+
const missing = document.missing_block_ids.length;
|
|
30
|
+
const why = missing > 0
|
|
31
|
+
? `${missing} blocks are missing: not shared with this token, or past what one read fetches`
|
|
32
|
+
: "Notion gave only part of the page";
|
|
33
|
+
renderAnswer(this, output, itemOf(document, {
|
|
34
|
+
...(issues.length > 0 ? { missing: [{ field: "markdown", why }], meta: { issues } } : {}),
|
|
35
|
+
}),
|
|
36
|
+
// Other members wrote this text; a terminal would run an escape sequence in it (WC-SECR-11).
|
|
37
|
+
(body) => `${visibleControls(body.item.markdown)}\n`);
|
|
38
|
+
if (issues.length > 0 && output.format !== "json" && output.format !== "jsonl")
|
|
39
|
+
output.renderer.warn(`the page is incomplete: ${why}`);
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/commands/documents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB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,mCAAmC,CAAA;IACzC,YAAY,CACV,IAAI,EACJ,MAAM,EACN,MAAM,CAAC,QAAQ,EAAE;QACf,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1F,CAAC;IACF,6FAA6F;IAC7F,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,eAAe,CAAE,IAA2B,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAC7E,CAAA;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO;QAC5E,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAA;AAC1D,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DocumentWords } from "@wirecat/cli-core/documents/cli";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
export declare const NOTION_WORDS: DocumentWords;
|
|
4
|
+
/**
|
|
5
|
+
* cli-core's shared `folders`, `sync`, `status`, `documents`, `search`, `catalog` and knowledge groups over Notion and
|
|
6
|
+
* the shared store, with notion's own `folders browse`, `documents get` and `documents add`. The ports take no command,
|
|
7
|
+
* so each run's command is caught as it starts; an MCP server builds the tree anew for every call.
|
|
8
|
+
*/
|
|
9
|
+
export declare const libraryCommands: () => Command[];
|
|
10
|
+
//# sourceMappingURL=library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../src/commands/library.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAEzF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAqCnC,eAAO,MAAM,YAAY,EAAE,aAkB1B,CAAA;AAuCD;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAO,OAAO,EAyazC,CAAA"}
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate, metaOf } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { progressOf } from "@wirecat/cli-core/background";
|
|
4
|
+
import { actorOf, answerEntity, FETCH, itemOf, listOf, outputFor, REMOTE_READ, refuseOffline, renderAnswer, resolveAISettings, writesOwnerFiles, } from "@wirecat/cli-core/cli";
|
|
5
|
+
import { catalogFiles, syncDocuments } from "@wirecat/cli-core/documents";
|
|
6
|
+
import { addDocumentCommands } from "@wirecat/cli-core/documents/cli";
|
|
7
|
+
import { modelGateway, modelTarget } from "@wirecat/cli-core/models";
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
import * as v from "valibot";
|
|
10
|
+
import { contextOf, notionReadsFor, tokenOf } from "../context.js";
|
|
11
|
+
import { IDENTITY } from "../identity.js";
|
|
12
|
+
import { ingestionOf, knowledgeOf } from "../knowledge.js";
|
|
13
|
+
import { chosenFolders, claimAccount, foldersChangedAt, knownOf, MAX_ENTRIES, PROVIDER, principalOf, readSnapshot, rootsOf, saveFolders, syncState, TEXT_LIMIT, walkUnderWay, withProfileLock, withStore, } from "../library.js";
|
|
14
|
+
import { notionId } from "../notion/ids.js";
|
|
15
|
+
import { isNotionDocument, isNotionFolder, notionSource, passUnderWay, WORKSPACE_ROOT, } from "../sync/source.js";
|
|
16
|
+
import { VERSION } from "../version.js";
|
|
17
|
+
import { getCommand } from "./documents.js";
|
|
18
|
+
const CLI = IDENTITY.command;
|
|
19
|
+
export const NOTION_WORDS = {
|
|
20
|
+
app: CLI,
|
|
21
|
+
remote: "notion",
|
|
22
|
+
provider: "Notion",
|
|
23
|
+
source: PROVIDER.name,
|
|
24
|
+
text: {
|
|
25
|
+
documents: "read Notion pages, live or from the local copy",
|
|
26
|
+
documentsList: "list the synced pages and database rows with their Notion links",
|
|
27
|
+
documentArgument: "page id, Notion link, or a search hit's document: ref",
|
|
28
|
+
knowledgeArgument: "page or database id or Notion link in the local copy, or a document:<n> ref",
|
|
29
|
+
catalog: "browse the synced pages and databases offline",
|
|
30
|
+
catalogArgument: "page or database id, or its Notion link",
|
|
31
|
+
treeArgument: "page or database id or link; defaults to the chosen folders, or the whole workspace",
|
|
32
|
+
folders: "choose the Notion pages and databases sync copies; none chosen copies everything the token sees",
|
|
33
|
+
folderArgument: "page or database id, or its Notion link",
|
|
34
|
+
syncLimit: "how many pages to read from Notion in this run",
|
|
35
|
+
identitiesList: "list the creator and last editor Notion shows for a page",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const DOCUMENT_REF = /^document:[1-9]\d*$/u;
|
|
39
|
+
const idOf = (input, what = "page") => (input === WORKSPACE_ROOT ? input : notionId(input, what));
|
|
40
|
+
const documentRow = (file, reference) => ({
|
|
41
|
+
id: file.id,
|
|
42
|
+
name: file.name,
|
|
43
|
+
kind: file.providerMetadata.kind,
|
|
44
|
+
url: file.url,
|
|
45
|
+
parents: file.parents,
|
|
46
|
+
modified_at: file.modifiedAt ?? null,
|
|
47
|
+
created_at: file.createdAt ?? null,
|
|
48
|
+
reference,
|
|
49
|
+
});
|
|
50
|
+
const browseRow = v.looseObject({
|
|
51
|
+
id: v.string(),
|
|
52
|
+
name: v.string(),
|
|
53
|
+
kind: v.picklist(["page", "database"]),
|
|
54
|
+
url: v.string(),
|
|
55
|
+
chosen: v.boolean(),
|
|
56
|
+
});
|
|
57
|
+
/** An issue names its source and why; the id and the words stay in the answer's `warnings`. */
|
|
58
|
+
const issuesOf = (warnings) => {
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
return warnings.flatMap((warning) => {
|
|
61
|
+
const key = `${warning.code}:${warning.reason}`;
|
|
62
|
+
if (seen.has(key))
|
|
63
|
+
return [];
|
|
64
|
+
seen.add(key);
|
|
65
|
+
return [{ code: warning.code, reason: warning.reason, source: PROVIDER.name }];
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const errorOf = (error) => isCliError(error) ? error : new CliError("provider_error", "a Notion read failed", { reason: "notion.failed" });
|
|
69
|
+
/**
|
|
70
|
+
* cli-core's shared `folders`, `sync`, `status`, `documents`, `search`, `catalog` and knowledge groups over Notion and
|
|
71
|
+
* the shared store, with notion's own `folders browse`, `documents get` and `documents add`. The ports take no command,
|
|
72
|
+
* so each run's command is caught as it starts; an MCP server builds the tree anew for every call.
|
|
73
|
+
*/
|
|
74
|
+
export const libraryCommands = () => {
|
|
75
|
+
const holder = new Command(CLI);
|
|
76
|
+
let running;
|
|
77
|
+
const command = () => {
|
|
78
|
+
if (!running)
|
|
79
|
+
throw new CliError("configuration_error", "a shared documents port ran outside a command");
|
|
80
|
+
return running;
|
|
81
|
+
};
|
|
82
|
+
const context = () => contextOf(command());
|
|
83
|
+
const env = () => context().env;
|
|
84
|
+
const profile = () => context().profile;
|
|
85
|
+
const state = () => syncState(env(), profile(), principalOf(env(), profile())).read();
|
|
86
|
+
let warnings = [];
|
|
87
|
+
let next;
|
|
88
|
+
const syncAgain = (limit) => {
|
|
89
|
+
const timeout = command().optsWithGlobals().timeout;
|
|
90
|
+
return {
|
|
91
|
+
kind: "command",
|
|
92
|
+
step: "sync.run",
|
|
93
|
+
command: "sync",
|
|
94
|
+
args: { limit, ...(timeout === undefined ? {} : { timeout }) },
|
|
95
|
+
why: "the sync stopped before the end of its pass; running it again goes on from there",
|
|
96
|
+
safe_to_auto_execute: true,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const output = (body) => {
|
|
100
|
+
const issues = issuesOf(warnings);
|
|
101
|
+
const answer = {
|
|
102
|
+
...body,
|
|
103
|
+
...(next && !body.next?.length ? { next } : {}),
|
|
104
|
+
...(issues.length ? { meta: { ...body.meta, issues: [...(body.meta?.issues ?? []), ...issues] } } : {}),
|
|
105
|
+
};
|
|
106
|
+
renderAnswer(command(), outputFor(command()), answer);
|
|
107
|
+
};
|
|
108
|
+
const imported = (input) => {
|
|
109
|
+
const held = syncState(env(), profile(), "").read();
|
|
110
|
+
const id = DOCUMENT_REF.test(input)
|
|
111
|
+
? Object.entries(held.documents).find(([, doc]) => doc.reference === input)?.[0]
|
|
112
|
+
: idOf(input);
|
|
113
|
+
const doc = id ? held.documents[id] : undefined;
|
|
114
|
+
const snapshot = id && doc ? readSnapshot(env(), profile(), id) : undefined;
|
|
115
|
+
if (!id || !doc || !snapshot)
|
|
116
|
+
throw new CliError("not_found", "this page is not in the selected profile's local copy", {
|
|
117
|
+
reason: "document.not-imported",
|
|
118
|
+
});
|
|
119
|
+
return { id, ref: doc.reference, hash: doc.hash, snapshot, metadata: documentRow(doc.metadata, doc.reference) };
|
|
120
|
+
};
|
|
121
|
+
/** The document a knowledge command names: a synced page, or a database the catalog holds. */
|
|
122
|
+
const refOf = async (store, principal, input) => {
|
|
123
|
+
if (DOCUMENT_REF.test(input))
|
|
124
|
+
return input;
|
|
125
|
+
const id = idOf(input);
|
|
126
|
+
const held = syncState(env(), profile(), principal).read().documents[id];
|
|
127
|
+
if (held)
|
|
128
|
+
return held.reference;
|
|
129
|
+
const entry = await ingestionOf(store).catalog.get(principal, id);
|
|
130
|
+
if (entry)
|
|
131
|
+
return entry.ref;
|
|
132
|
+
throw new CliError("not_found", "this page or database is not in the selected profile's local copy", {
|
|
133
|
+
reason: "document.not-imported",
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
/** A write to the local copy holds the sync's lock; a read does not wait for a sync to end. */
|
|
137
|
+
const locked = (write, fn) => write ? withProfileLock(env(), profile(), fn) : fn(() => undefined);
|
|
138
|
+
const writes = () => metaOf(command()).effects?.local === "write";
|
|
139
|
+
const decider = () => {
|
|
140
|
+
const actor = actorOf(command());
|
|
141
|
+
return actor === "owner" ? "owner" : { bot: actor, reason: `asked by ${actor} through ${CLI}` };
|
|
142
|
+
};
|
|
143
|
+
const sourceFor = (reads, held = false, deadline) => notionSource(reads, {
|
|
144
|
+
roots: rootsOf(env(), profile()),
|
|
145
|
+
...(held ? { known: () => knownOf(syncState(env(), profile(), "").read()) } : {}),
|
|
146
|
+
warn: (warning) => warnings.push(warning),
|
|
147
|
+
...(deadline ? { deadline } : {}),
|
|
148
|
+
});
|
|
149
|
+
/** One Notion run: the token read first, every request inside cli-core's run (WC-LIFE-15). */
|
|
150
|
+
const withNotionReads = (body) => {
|
|
151
|
+
const token = tokenOf(command());
|
|
152
|
+
return context().run((events) => body(notionReadsFor(command(), token, events)));
|
|
153
|
+
};
|
|
154
|
+
const documents = addDocumentCommands(holder, {
|
|
155
|
+
words: NOTION_WORDS,
|
|
156
|
+
output,
|
|
157
|
+
folders: {
|
|
158
|
+
add: async (input) => {
|
|
159
|
+
const id = notionId(input);
|
|
160
|
+
const file = await withNotionReads((reads) => sourceFor(reads).metadata(id));
|
|
161
|
+
if (file.trashed || !["page", "database"].includes(file.providerMetadata.kind))
|
|
162
|
+
throw new CliError("validation_error", "choose a page or a database the token can see", {
|
|
163
|
+
reason: "folder.not-a-folder",
|
|
164
|
+
});
|
|
165
|
+
const roots = chosenFolders(env(), profile());
|
|
166
|
+
if (!roots.includes(file.id))
|
|
167
|
+
saveFolders(env(), profile(), [...roots, file.id]);
|
|
168
|
+
return { id: file.id, name: file.name };
|
|
169
|
+
},
|
|
170
|
+
list: (filter) => rootsOf(env(), profile())
|
|
171
|
+
.filter((id) => filter.id === undefined || filter.id === id)
|
|
172
|
+
.map((id) => ({ id })),
|
|
173
|
+
remove: (input) => {
|
|
174
|
+
if (input === WORKSPACE_ROOT)
|
|
175
|
+
throw new CliError("validation_error", "the whole workspace is synced when no folder is chosen", {
|
|
176
|
+
reason: "folder.workspace",
|
|
177
|
+
});
|
|
178
|
+
const id = notionId(input);
|
|
179
|
+
const roots = chosenFolders(env(), profile());
|
|
180
|
+
if (!roots.includes(id))
|
|
181
|
+
throw new CliError("not_found", `${id} is not a chosen folder; folders list shows them`, {
|
|
182
|
+
reason: "folder.not-chosen",
|
|
183
|
+
});
|
|
184
|
+
const left = roots.filter((root) => root !== id);
|
|
185
|
+
saveFolders(env(), profile(), left);
|
|
186
|
+
if (!left.length) {
|
|
187
|
+
outputFor(command()).renderer.warn("no folder is chosen now, so the next sync copies the whole workspace the token sees");
|
|
188
|
+
next = [
|
|
189
|
+
{
|
|
190
|
+
kind: "command",
|
|
191
|
+
step: "folders.browse",
|
|
192
|
+
command: "folders browse",
|
|
193
|
+
args: {},
|
|
194
|
+
why: "the next sync copies the whole workspace; choose a page or database to keep it narrow",
|
|
195
|
+
safe_to_auto_execute: true,
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
return id;
|
|
200
|
+
},
|
|
201
|
+
browse: (folders) => {
|
|
202
|
+
answerEntity(annotate(folders.command("browse"), {
|
|
203
|
+
effects: REMOTE_READ,
|
|
204
|
+
offline: false,
|
|
205
|
+
examples: [`${CLI} personal folders browse`, `${CLI} personal folders browse --parent PAGE_ID --json`],
|
|
206
|
+
}), "notion_folder", browseRow)
|
|
207
|
+
.summary("list Notion pages and databases one level at a time, live")
|
|
208
|
+
.description("list Notion pages and databases one level at a time, live, to choose one for folders add")
|
|
209
|
+
.option("--parent <id>", "page id or Notion link to list inside; the top of the workspace without it")
|
|
210
|
+
.action(async (args) => {
|
|
211
|
+
const parent = args.parent === undefined ? WORKSPACE_ROOT : notionId(args.parent);
|
|
212
|
+
const chosen = new Set(chosenFolders(env(), profile()));
|
|
213
|
+
const children = await withNotionReads((reads) => sourceFor(reads).children(parent));
|
|
214
|
+
const items = children
|
|
215
|
+
.filter((file) => file.providerMetadata.kind === "page" || file.providerMetadata.kind === "database")
|
|
216
|
+
.map((file) => ({
|
|
217
|
+
id: file.id,
|
|
218
|
+
name: file.name,
|
|
219
|
+
kind: file.providerMetadata.kind,
|
|
220
|
+
url: file.url,
|
|
221
|
+
chosen: chosen.has(file.id),
|
|
222
|
+
}));
|
|
223
|
+
output(listOf("folders browse", { items, limit: Math.max(1, items.length), has_more: false }));
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
sync: {
|
|
228
|
+
diagnostic: (text) => outputFor(command()).streams.diagnostic(text),
|
|
229
|
+
profile,
|
|
230
|
+
maxEntries: MAX_ENTRIES,
|
|
231
|
+
sync: async ({ limit, rescan, embed, budget, deadline }) => {
|
|
232
|
+
refuseOffline(command(), "Notion");
|
|
233
|
+
warnings = [];
|
|
234
|
+
const name = profile();
|
|
235
|
+
const roots = rootsOf(env(), name);
|
|
236
|
+
const result = await withNotionReads(async (reads) => {
|
|
237
|
+
const source = sourceFor(reads, true, deadline);
|
|
238
|
+
const live = await source.identity();
|
|
239
|
+
claimAccount(env(), name, live, context().tokens);
|
|
240
|
+
return withProfileLock(env(), name, (assertHeld) => withStore(env(), true, async (store) => {
|
|
241
|
+
const ingestion = ingestionOf(store);
|
|
242
|
+
const synced = await syncDocuments({
|
|
243
|
+
source,
|
|
244
|
+
index: {
|
|
245
|
+
...ingestion,
|
|
246
|
+
openPictures: async () => {
|
|
247
|
+
throw new CliError("not_found", "a Notion page has no picture to search");
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
state: syncState(env(), name, live),
|
|
251
|
+
principal: live,
|
|
252
|
+
roots,
|
|
253
|
+
textLimit: TEXT_LIMIT,
|
|
254
|
+
max: limit,
|
|
255
|
+
maxEntries: MAX_ENTRIES,
|
|
256
|
+
isFolder: isNotionFolder,
|
|
257
|
+
isDocument: isNotionDocument,
|
|
258
|
+
skipReason: () => undefined,
|
|
259
|
+
retryable: () => false,
|
|
260
|
+
errorOf,
|
|
261
|
+
assertHeld,
|
|
262
|
+
storeVersion: VERSION,
|
|
263
|
+
...(context().environment.signal ? { signal: context().environment.signal } : {}),
|
|
264
|
+
...(rescan ? { rescan } : {}),
|
|
265
|
+
...(budget ? { budget } : {}),
|
|
266
|
+
...(deadline ? { deadline } : {}),
|
|
267
|
+
});
|
|
268
|
+
if (!embed)
|
|
269
|
+
return synced;
|
|
270
|
+
const { embedNotes } = await import("@wirecat/cli-core/services");
|
|
271
|
+
return { ...synced, embeddings: await embedNotes(store, { maxChunks: 600, env: env(), command: CLI }) };
|
|
272
|
+
}));
|
|
273
|
+
});
|
|
274
|
+
// The engine counts a round of changes as done; Notion's own pass may still have tasks for the next sync.
|
|
275
|
+
const underWay = passUnderWay(syncState(env(), name, "").read().cursor);
|
|
276
|
+
if (underWay)
|
|
277
|
+
next = [syncAgain(limit)];
|
|
278
|
+
return {
|
|
279
|
+
...result,
|
|
280
|
+
...(underWay ? { complete: false } : {}),
|
|
281
|
+
warnings: warnings.map(({ id, code, reason, message }) => ({ id: id ?? null, code, reason, message })),
|
|
282
|
+
};
|
|
283
|
+
},
|
|
284
|
+
status: () => {
|
|
285
|
+
const name = profile();
|
|
286
|
+
const held = syncState(env(), name, "").read();
|
|
287
|
+
const documents = Object.keys(held.documents).length;
|
|
288
|
+
const pending = held.pending?.jobs.length ?? 0;
|
|
289
|
+
const queued = new Set(held.pending?.jobs.map((job) => job.id));
|
|
290
|
+
const done = Object.keys(held.documents).filter((id) => !queued.has(id)).length;
|
|
291
|
+
const changed = foldersChangedAt(env(), name);
|
|
292
|
+
// Until the plan is made, or while Notion's own pass goes on, nothing says how much is left.
|
|
293
|
+
const unplanned = walkUnderWay(env(), name) ||
|
|
294
|
+
passUnderWay(held.cursor) ||
|
|
295
|
+
(changed !== undefined && (!held.lastSync || Date.parse(changed) > Date.parse(held.lastSync)));
|
|
296
|
+
return {
|
|
297
|
+
profile: name,
|
|
298
|
+
selected_folders: chosenFolders(env(), name),
|
|
299
|
+
scope: chosenFolders(env(), name).length ? "chosen folders" : "the whole workspace the token sees",
|
|
300
|
+
documents,
|
|
301
|
+
pending,
|
|
302
|
+
skipped: held.skipped.map(({ id, reason }) => ({ id, reason })),
|
|
303
|
+
last_sync: held.lastSync ?? null,
|
|
304
|
+
progress: progressOf({
|
|
305
|
+
job: "sync",
|
|
306
|
+
profile: name,
|
|
307
|
+
done,
|
|
308
|
+
...(unplanned || (!held.lastSync && !held.pending) ? {} : { total: done + pending }),
|
|
309
|
+
...(held.lastSync ? { updatedAt: held.lastSync } : {}),
|
|
310
|
+
complete: Boolean(held.lastSync) && !held.pending && !unplanned,
|
|
311
|
+
}),
|
|
312
|
+
coverage: "pages, pages under pages and database rows, as Notion Markdown; files inside pages are not copied",
|
|
313
|
+
remote_checked: false,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
documents: {
|
|
318
|
+
list: (query, page) => {
|
|
319
|
+
const principal = principalOf(env(), profile());
|
|
320
|
+
return withStore(env(), false, async (store) => {
|
|
321
|
+
const found = await knowledgeOf(store, principal).documents(principal, query, page);
|
|
322
|
+
const held = state().documents;
|
|
323
|
+
return {
|
|
324
|
+
items: found.items.map((note) => {
|
|
325
|
+
const id = (note.path ?? "").replace(/\.md$/u, "");
|
|
326
|
+
const doc = held[id];
|
|
327
|
+
return doc ? documentRow(doc.metadata, doc.reference) : { id, name: note.title, reference: note.ref };
|
|
328
|
+
}),
|
|
329
|
+
hasMore: found.hasMore,
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
document: (input) => {
|
|
334
|
+
const { id, metadata, snapshot } = imported(input);
|
|
335
|
+
return { id, metadata, snapshot };
|
|
336
|
+
},
|
|
337
|
+
lastSync: () => syncState(env(), profile(), "").read().lastSync,
|
|
338
|
+
},
|
|
339
|
+
search: {
|
|
340
|
+
search: (query, options) => {
|
|
341
|
+
const principal = principalOf(env(), profile());
|
|
342
|
+
return withStore(env(), false, async (store) => {
|
|
343
|
+
const folder = await ingestionOf(store).collection(principal, false);
|
|
344
|
+
if (!folder)
|
|
345
|
+
return { query, by: "words", hits: [], has_more: false };
|
|
346
|
+
const { searchNotes } = await import("@wirecat/cli-core/services");
|
|
347
|
+
const { items, hasMore, nextOffset, ...rest } = await searchNotes(store, query, {
|
|
348
|
+
...options,
|
|
349
|
+
folderIds: [folder.id],
|
|
350
|
+
env: env(),
|
|
351
|
+
command: CLI,
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
...rest,
|
|
355
|
+
hits: items.map((hit) => ({ id: (hit.path ?? "").replace(/\.md$/u, ""), ...hit })),
|
|
356
|
+
has_more: hasMore,
|
|
357
|
+
...(nextOffset === undefined ? {} : { next_offset: nextOffset }),
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
// The whole workspace is the scope when no folder is chosen, so there is always something chosen.
|
|
362
|
+
imported: () => ({
|
|
363
|
+
profile: profile(),
|
|
364
|
+
chosen: true,
|
|
365
|
+
documents: Object.keys(syncState(env(), profile(), "").read().documents).length,
|
|
366
|
+
}),
|
|
367
|
+
},
|
|
368
|
+
catalog: {
|
|
369
|
+
run: (fn, write) => {
|
|
370
|
+
const principal = principalOf(env(), profile());
|
|
371
|
+
return withStore(env(), write, (store) => locked(write, async (assertHeld) => {
|
|
372
|
+
const ingestion = ingestionOf(store);
|
|
373
|
+
assertHeld();
|
|
374
|
+
const value = await fn({
|
|
375
|
+
catalog: {
|
|
376
|
+
import: (account) => ingestion.catalog.import(account, catalogFiles(syncState(env(), profile(), account).read(), rootsOf(env(), profile()))),
|
|
377
|
+
get: (account, id) => ingestion.catalog.get(account, id),
|
|
378
|
+
list: (account, query) => ingestion.catalog.list(account, query),
|
|
379
|
+
},
|
|
380
|
+
knowledge: knowledgeOf(store, principal),
|
|
381
|
+
}, principal);
|
|
382
|
+
assertHeld();
|
|
383
|
+
return value;
|
|
384
|
+
}));
|
|
385
|
+
},
|
|
386
|
+
id: (input) => idOf(input),
|
|
387
|
+
roots: () => rootsOf(env(), profile()),
|
|
388
|
+
},
|
|
389
|
+
knowledge: {
|
|
390
|
+
run: (input, fn) => {
|
|
391
|
+
const write = writes();
|
|
392
|
+
const principal = principalOf(env(), profile());
|
|
393
|
+
return withStore(env(), write, (store) => locked(write, async (assertHeld) => {
|
|
394
|
+
const ref = await refOf(store, principal, input);
|
|
395
|
+
assertHeld();
|
|
396
|
+
const value = await fn(knowledgeOf(store, principal), principal, ref);
|
|
397
|
+
assertHeld();
|
|
398
|
+
return value;
|
|
399
|
+
}));
|
|
400
|
+
},
|
|
401
|
+
document: (input) => {
|
|
402
|
+
const { id, ref, hash, snapshot } = imported(input);
|
|
403
|
+
return { id, ref, hash, snapshot };
|
|
404
|
+
},
|
|
405
|
+
complete: () => {
|
|
406
|
+
const { values } = resolveAISettings(IDENTITY.envPrefix, [], env());
|
|
407
|
+
const variables = env();
|
|
408
|
+
return modelGateway({
|
|
409
|
+
resolve: (purpose) => modelTarget(values, purpose),
|
|
410
|
+
// Called only by `memories extract`, which the owner or an agent runs on purpose.
|
|
411
|
+
consent: () => true,
|
|
412
|
+
key: (provider) => variables[`${IDENTITY.envPrefix}_${provider.toUpperCase()}_API_KEY`] ??
|
|
413
|
+
variables[`${provider.toUpperCase()}_API_KEY`],
|
|
414
|
+
...(context().environment.signal ? { signal: context().environment.signal } : {}),
|
|
415
|
+
}).complete;
|
|
416
|
+
},
|
|
417
|
+
author: () => {
|
|
418
|
+
const actor = actorOf(command());
|
|
419
|
+
return actor === "owner" ? "owner" : { bot: actor, kind: "agent" };
|
|
420
|
+
},
|
|
421
|
+
decider,
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
documents.addCommand(getCommand());
|
|
425
|
+
annotate(documents.command("add"), {
|
|
426
|
+
effects: FETCH,
|
|
427
|
+
mcp: false,
|
|
428
|
+
offline: false,
|
|
429
|
+
examples: [
|
|
430
|
+
`${CLI} personal documents add https://www.notion.so/Roadmap-0123456789abcdef0123456789abcdef`,
|
|
431
|
+
`${CLI} personal documents add PAGE_ID --subject person:PERSON_UID`,
|
|
432
|
+
],
|
|
433
|
+
})
|
|
434
|
+
.summary("keep one Notion page's text in memory, read live, without syncing a folder")
|
|
435
|
+
.description("read one page live and keep its text among the sources added by hand, where memo and search all find it; " +
|
|
436
|
+
"adding it again keeps its new text as the next revision")
|
|
437
|
+
.argument("<page>", "the page's id or its Notion link")
|
|
438
|
+
.option("--title <title>", "the title to keep it under; the page's own when omitted")
|
|
439
|
+
.option("--subject <ref>", "a person, organization, project, task or meeting it is about; repeat to add more", (value, previous = []) => [...previous, value])
|
|
440
|
+
.action(async (input, args) => {
|
|
441
|
+
const id = notionId(input);
|
|
442
|
+
const content = await withNotionReads((reads) => sourceFor(reads).content(id, TEXT_LIMIT));
|
|
443
|
+
const added = await withStore(env(), true, (store) => store.notes.saveAddedSource({
|
|
444
|
+
kind: "page",
|
|
445
|
+
text: content.text,
|
|
446
|
+
read: content.text ? "extracted" : "no-text",
|
|
447
|
+
title: args.title ?? content.metadata.name,
|
|
448
|
+
url: content.metadata.url,
|
|
449
|
+
sourceKey: `notion:${id}`,
|
|
450
|
+
...(args.subject ? { subjects: args.subject } : {}),
|
|
451
|
+
by: decider(),
|
|
452
|
+
}));
|
|
453
|
+
output(itemOf(added));
|
|
454
|
+
});
|
|
455
|
+
const find = (group, name) => group.commands.find((one) => one.name() === name);
|
|
456
|
+
const folders = find(holder, "folders");
|
|
457
|
+
// Choosing a folder changes what the next sync keeps and removes, so an agent asks for it through the write tool.
|
|
458
|
+
writesOwnerFiles(find(folders, "add"));
|
|
459
|
+
annotate(find(folders, "browse"), { partial: true });
|
|
460
|
+
for (const group of holder.commands)
|
|
461
|
+
group.hook("preAction", (_group, action) => {
|
|
462
|
+
running = action;
|
|
463
|
+
warnings = [];
|
|
464
|
+
next = undefined;
|
|
465
|
+
});
|
|
466
|
+
return [...holder.commands];
|
|
467
|
+
};
|
|
468
|
+
//# sourceMappingURL=library.js.map
|