@kamilio/wire 0.1.56 → 0.1.58

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 (124) hide show
  1. package/README.md +44 -1
  2. package/dist/adapters/document-shell.d.ts +7 -0
  3. package/dist/adapters/document-shell.d.ts.map +1 -0
  4. package/dist/adapters/document-shell.js +51 -0
  5. package/dist/adapters/document-shell.js.map +1 -0
  6. package/dist/adapters/root.d.ts.map +1 -1
  7. package/dist/adapters/root.js +69 -4
  8. package/dist/adapters/root.js.map +1 -1
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +8 -2
  11. package/dist/cli.js.map +1 -1
  12. package/dist/document-shell-engine.mjs +1880 -0
  13. package/dist/executable.js +1 -1
  14. package/dist/executable.js.map +1 -1
  15. package/dist/hooks.d.ts.map +1 -1
  16. package/dist/hooks.js +19 -19
  17. package/dist/hooks.js.map +1 -1
  18. package/node_modules/provider-asana/dist/asana-project.d.ts +8 -1
  19. package/node_modules/provider-asana/dist/asana-project.d.ts.map +1 -1
  20. package/node_modules/provider-asana/dist/asana-task.d.ts +8 -1
  21. package/node_modules/provider-asana/dist/asana-task.d.ts.map +1 -1
  22. package/node_modules/provider-asana/dist/index.d.ts +16 -2
  23. package/node_modules/provider-asana/dist/index.d.ts.map +1 -1
  24. package/node_modules/provider-chatgpt/dist/chatgpt.d.ts +8 -1
  25. package/node_modules/provider-chatgpt/dist/chatgpt.d.ts.map +1 -1
  26. package/node_modules/provider-chatgpt/dist/index.d.ts +8 -1
  27. package/node_modules/provider-chatgpt/dist/index.d.ts.map +1 -1
  28. package/node_modules/provider-gmail/dist/gmail.d.ts +8 -1
  29. package/node_modules/provider-gmail/dist/gmail.d.ts.map +1 -1
  30. package/node_modules/provider-gmail/dist/index.d.ts +8 -1
  31. package/node_modules/provider-gmail/dist/index.d.ts.map +1 -1
  32. package/node_modules/provider-google-docs/dist/doc-blocks.d.ts.map +1 -1
  33. package/node_modules/provider-google-docs/dist/doc-blocks.js +6 -2
  34. package/node_modules/provider-google-docs/dist/doc-blocks.js.map +1 -1
  35. package/node_modules/provider-google-docs/dist/google-docs.d.ts +8 -1
  36. package/node_modules/provider-google-docs/dist/google-docs.d.ts.map +1 -1
  37. package/node_modules/provider-google-docs/dist/google-docs.js +31 -10
  38. package/node_modules/provider-google-docs/dist/google-docs.js.map +1 -1
  39. package/node_modules/provider-google-docs/dist/google-forms.d.ts +8 -1
  40. package/node_modules/provider-google-docs/dist/google-forms.d.ts.map +1 -1
  41. package/node_modules/provider-google-docs/dist/index.d.ts +16 -2
  42. package/node_modules/provider-google-docs/dist/index.d.ts.map +1 -1
  43. package/node_modules/provider-google-docs/src/doc-blocks.ts +8 -2
  44. package/node_modules/provider-google-docs/src/google-docs.ts +26 -10
  45. package/node_modules/provider-lattice/dist/index.d.ts +16 -2
  46. package/node_modules/provider-lattice/dist/index.d.ts.map +1 -1
  47. package/node_modules/provider-notion/dist/index.d.ts +8 -1
  48. package/node_modules/provider-notion/dist/index.d.ts.map +1 -1
  49. package/node_modules/provider-notion/dist/notion-sync.d.ts +2 -2
  50. package/node_modules/provider-notion/dist/notion-sync.d.ts.map +1 -1
  51. package/node_modules/provider-notion/dist/notion-sync.js +24 -15
  52. package/node_modules/provider-notion/dist/notion-sync.js.map +1 -1
  53. package/node_modules/provider-notion/dist/notion.d.ts +8 -1
  54. package/node_modules/provider-notion/dist/notion.d.ts.map +1 -1
  55. package/node_modules/provider-notion/dist/notion.js +1 -1
  56. package/node_modules/provider-notion/dist/notion.js.map +1 -1
  57. package/node_modules/provider-notion/src/notion-sync.ts +23 -15
  58. package/node_modules/provider-notion/src/notion.ts +1 -1
  59. package/node_modules/provider-slack/dist/index.d.ts +8 -1
  60. package/node_modules/provider-slack/dist/index.d.ts.map +1 -1
  61. package/node_modules/provider-slack/dist/slack.d.ts +8 -1
  62. package/node_modules/provider-slack/dist/slack.d.ts.map +1 -1
  63. package/node_modules/provider-zoom/dist/index.d.ts +8 -1
  64. package/node_modules/provider-zoom/dist/index.d.ts.map +1 -1
  65. package/node_modules/provider-zoom/dist/zoom-hub.d.ts +8 -1
  66. package/node_modules/provider-zoom/dist/zoom-hub.d.ts.map +1 -1
  67. package/node_modules/wire-core/dist/core/editor-receipts.d.ts +5 -0
  68. package/node_modules/wire-core/dist/core/editor-receipts.d.ts.map +1 -0
  69. package/node_modules/wire-core/dist/core/editor-receipts.js +9 -0
  70. package/node_modules/wire-core/dist/core/editor-receipts.js.map +1 -0
  71. package/node_modules/wire-core/dist/core/model.d.ts +6 -1
  72. package/node_modules/wire-core/dist/core/model.d.ts.map +1 -1
  73. package/node_modules/wire-core/dist/core/owner.d.ts +3 -0
  74. package/node_modules/wire-core/dist/core/owner.d.ts.map +1 -0
  75. package/node_modules/wire-core/dist/core/owner.js +16 -0
  76. package/node_modules/wire-core/dist/core/owner.js.map +1 -0
  77. package/node_modules/wire-core/dist/core/source.d.ts +4 -1
  78. package/node_modules/wire-core/dist/core/source.d.ts.map +1 -1
  79. package/node_modules/wire-core/dist/core/source.js +15 -2
  80. package/node_modules/wire-core/dist/core/source.js.map +1 -1
  81. package/node_modules/wire-core/dist/index.d.ts +1 -1
  82. package/node_modules/wire-core/dist/index.d.ts.map +1 -1
  83. package/node_modules/wire-core/dist/index.js +1 -1
  84. package/node_modules/wire-core/dist/index.js.map +1 -1
  85. package/node_modules/wire-core/dist/operations.d.ts +11 -2
  86. package/node_modules/wire-core/dist/operations.d.ts.map +1 -1
  87. package/node_modules/wire-core/dist/operations.js +404 -31
  88. package/node_modules/wire-core/dist/operations.js.map +1 -1
  89. package/node_modules/wire-core/dist/storage/editor-receipts.d.ts +17 -0
  90. package/node_modules/wire-core/dist/storage/editor-receipts.d.ts.map +1 -0
  91. package/node_modules/wire-core/dist/storage/editor-receipts.js +27 -0
  92. package/node_modules/wire-core/dist/storage/editor-receipts.js.map +1 -0
  93. package/node_modules/wire-core/dist/storage/history-integrity.d.ts +4 -0
  94. package/node_modules/wire-core/dist/storage/history-integrity.d.ts.map +1 -0
  95. package/node_modules/wire-core/dist/storage/history-integrity.js +32 -0
  96. package/node_modules/wire-core/dist/storage/history-integrity.js.map +1 -0
  97. package/node_modules/wire-core/dist/storage/history.d.ts +93 -0
  98. package/node_modules/wire-core/dist/storage/history.d.ts.map +1 -0
  99. package/node_modules/wire-core/dist/storage/history.js +450 -0
  100. package/node_modules/wire-core/dist/storage/history.js.map +1 -0
  101. package/node_modules/wire-core/dist/storage/registry.d.ts +2 -2
  102. package/node_modules/wire-core/dist/storage/registry.d.ts.map +1 -1
  103. package/node_modules/wire-core/dist/storage/registry.js +34 -14
  104. package/node_modules/wire-core/dist/storage/registry.js.map +1 -1
  105. package/node_modules/wire-core/dist/storage/workspace.d.ts.map +1 -1
  106. package/node_modules/wire-core/dist/storage/workspace.js +183 -40
  107. package/node_modules/wire-core/dist/storage/workspace.js.map +1 -1
  108. package/node_modules/wire-core/src/core/editor-receipts.ts +8 -0
  109. package/node_modules/wire-core/src/core/model.ts +6 -1
  110. package/node_modules/wire-core/src/core/owner.ts +16 -0
  111. package/node_modules/wire-core/src/core/source.ts +17 -1
  112. package/node_modules/wire-core/src/index.ts +1 -1
  113. package/node_modules/wire-core/src/operations.ts +344 -33
  114. package/node_modules/wire-core/src/storage/editor-receipts.ts +27 -0
  115. package/node_modules/wire-core/src/storage/history-integrity.ts +25 -0
  116. package/node_modules/wire-core/src/storage/history.ts +331 -0
  117. package/node_modules/wire-core/src/storage/registry.ts +22 -15
  118. package/node_modules/wire-core/src/storage/workspace.ts +129 -34
  119. package/package.json +6 -2
  120. package/src/adapters/document-shell.ts +43 -0
  121. package/src/adapters/root.ts +71 -4
  122. package/src/cli.ts +8 -2
  123. package/src/executable.ts +1 -1
  124. package/src/hooks.ts +19 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamilio/wire",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
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 && 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/ && echo 'export { convert } from \"@poe-platform/safe-bash/commands/pandoc\"' | esbuild --bundle --platform=node --format=esm --target=node20 --minify --outfile=dist/docx-converter.mjs && cp ../../node_modules/@poe-platform/safe-bash/LICENSE dist/docx-converter.LICENSE",
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/ && echo 'export { convert } from \"@poe-platform/safe-bash/commands/pandoc\"' | esbuild --bundle --platform=node --format=esm --target=node20 --minify --outfile=dist/docx-converter.mjs && cp ../../node_modules/@poe-platform/safe-bash/LICENSE dist/docx-converter.LICENSE && echo 'export { cloudflareWorkerLimits, createMemoryFileSystem, diffCommands, Shell, standardCommands, textProgramCommands } from \"@poe-platform/safe-bash/core\"' | esbuild --bundle --platform=browser --format=esm --target=es2022 --minify --outfile=dist/document-shell-engine.mjs",
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",
@@ -188,6 +188,10 @@
188
188
  "#docx-converter": {
189
189
  "types": "@poe-platform/safe-bash/commands/pandoc",
190
190
  "default": "./dist/docx-converter.mjs"
191
+ },
192
+ "#document-shell-engine": {
193
+ "types": "@poe-platform/safe-bash/core",
194
+ "default": "./dist/document-shell-engine.mjs"
191
195
  }
192
196
  }
193
197
  }
@@ -0,0 +1,43 @@
1
+ import { cloudflareWorkerLimits, createMemoryFileSystem, diffCommands, Shell, standardCommands, textProgramCommands } from "#document-shell-engine";
2
+
3
+ const encoder = new TextEncoder();
4
+ const documentPath = "/document.md";
5
+
6
+ function memoryFilesystem() {
7
+ return createMemoryFileSystem({ maxBytes: 32 * 1024 * 1024, maxFileBytes: 8 * 1024 * 1024, maxRetainedBytes: 64 * 1024 * 1024, maxMetadataUnits: 524288 });
8
+ }
9
+
10
+ export async function editDocument(markdown: string, script: string) {
11
+ const fs = memoryFilesystem();
12
+ await fs.writeFile(documentPath, encoder.encode(markdown));
13
+ const shell = new Shell({ fs, cwd: "/", limits: cloudflareWorkerLimits }).use(standardCommands()).use(textProgramCommands()).use(diffCommands());
14
+ try {
15
+ const { exitCode, stdout, stderr } = await shell.exec(script);
16
+ if (exitCode !== 0) throw new Error(`Shell exited ${exitCode}; no changes saved.\n${[stdout, stderr].filter(Boolean).join("\n")}`.trimEnd());
17
+ const stat = await fs.lstat(documentPath).catch(() => undefined);
18
+ if (stat?.type !== "file") throw new Error("Keep /document.md as a regular file; no changes saved.");
19
+ const bytes = await fs.readFile(documentPath);
20
+ if (bytes.includes(0)) throw new Error("/document.md must contain UTF-8 text; no changes saved.");
21
+ let edited: string;
22
+ try { edited = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes); }
23
+ catch { throw new Error("/document.md must contain UTF-8 text; no changes saved."); }
24
+ return { edited, stdout, stderr };
25
+ } finally {
26
+ await shell.dispose();
27
+ }
28
+ }
29
+
30
+ export async function documentDiff(from: string, to: string, before: string, after: string): Promise<string> {
31
+ if (before === after) return "";
32
+ const fs = memoryFilesystem();
33
+ await fs.writeFile("/a", encoder.encode(before));
34
+ await fs.writeFile("/b", encoder.encode(after));
35
+ const shell = new Shell({ fs, cwd: "/", limits: cloudflareWorkerLimits }).use(diffCommands());
36
+ try {
37
+ const result = await shell.exec('diff -u -L "$FROM" -L "$TO" /a /b', { env: { FROM: from, TO: to } });
38
+ if (result.exitCode > 1) throw new Error(result.stderr || "Could not compare documents.");
39
+ return result.stdout;
40
+ } finally {
41
+ await shell.dispose();
42
+ }
43
+ }
@@ -206,6 +206,10 @@ function wireUserErrorMessage(message: string): boolean {
206
206
  || /^Resource path is not registered: /.test(message)
207
207
  || /^Resource (path |identifier |URL )?not found: /.test(message)
208
208
  || /^Ambiguous resource path /.test(message)
209
+ || /^(Unresolved Wire conflict|Working file changed since the conflict|Stale shell edit|No saved conflict|Unknown document revision|No saved (?:base|local|remote) revision|Linked Markdown is missing|Another Wire operation owns this document|Local file changed during (?:sync|detach)|This registry does not provide durable document history|This provider cannot conditionally publish|Resolve and sync the Wire draft before detaching|Notion cannot condition a save|Google Sheets cannot condition a save)/.test(message)
210
+ || /^((?:Invalid|Missing|Orphaned) Wire editor receipt|Editor receipts require|An older editor buffer|Document already has a different sync owner)/.test(message)
211
+ || /^(Configured Wire registry is missing|Wire storage is busy|Wire switch destination already exists)/.test(message)
212
+ || /^Wire history and tracked Markdown must be on the same filesystem/.test(message)
209
213
  || /^Login not saved$/.test(message)
210
214
  || /authentication (is missing|is missing or expired|failed|expired).*Run `wire (ashby|asana|chatgpt|codesignal|gmail|google-docs|notion|slack|zoom) login`/i.test(message)
211
215
  || /^Asana API /.test(message)
@@ -441,18 +445,20 @@ type AsanaExplorer = {
441
445
  };
442
446
 
443
447
  export function createRoot(wire: Wire, currentDirectory: string, auth?: Auth, readInput?: TextInputReader, options: WireRootOptions = { allowPaste: true }, sendSlack?: (destination: string, markdown: string) => Promise<SlackSentMessage>, lookupSlack?: (query: string) => Promise<readonly JsonObject[]>, editSlack?: (url: string, markdown: string) => Promise<SlackSentMessage>, lookupNotion?: (query: string) => Promise<readonly JsonObject[]>, asana?: AsanaExplorer, latticeRoot?: () => Promise<string>): WireRoot {
444
- const attachFromCliUrl = (url: string) => {
448
+ const attachFromCliUrl = (url: string, editorReceipts?: boolean) => {
445
449
  const removedCommand = removedCliCommandNames[url as keyof typeof removedCliCommandNames];
446
450
  if (removedCommand !== undefined) throw new UserError(`Unknown command: ${url}. ${removedCommand}`);
447
451
  if (!/^[a-zA-Z][a-zA-Z\d+.-]*:\/\//.test(url)) throw new UserError(`Expected source URL: ${url}`);
448
- return userFacing(() => wire.attach(url, currentDirectory));
452
+ return userFacing(() => wire.attach(url, currentDirectory, editorReceipts));
449
453
  };
450
454
  const defaultAttach = defineCommand({
451
455
  name: "attach",
452
456
  description: "Track a source URL as local Markdown. Shorthand: wire <url>.",
453
457
  positional: ["url"],
454
- params: S.Object({ url: S.String({ description: "Supported source URL to attach." }) }),
455
- handler: ({ params }) => attachFromCliUrl(params.url),
458
+ params: S.Object({ url: S.String({ description: "Supported source URL to attach." }),
459
+ "editor-receipts": S.Optional(S.Boolean({ description: "Google Docs: keep a local Markdown comment identifying the revision each editor buffer saw." })),
460
+ }),
461
+ handler: ({ params }) => attachFromCliUrl(params.url, params["editor-receipts"]),
456
462
  render: wirePresentation.attach,
457
463
  });
458
464
  const preview = defineCommand({
@@ -471,6 +477,9 @@ export function createRoot(wire: Wire, currentDirectory: string, auth?: Auth, re
471
477
  handler: ({ params }) => userFacing(() => wire.sync(params.resource, currentDirectory)),
472
478
  render: wirePresentation.sync,
473
479
  });
480
+ const resource = S.String({ description: "Registered resource URL, resource ID, or Markdown path." });
481
+ const historyStatusText = (status: Awaited<ReturnType<Wire["historyStatus"]>>) =>
482
+ `${status.path}: ${status.conflict ? "conflict" : status.modified ? "local changes" : "clean"}`;
474
483
  const authCommand = (service: (typeof authServices)[number]) => {
475
484
  const title = serviceTitle(service);
476
485
  const group = authGroup(service, `Manage ${title} login.`, "Capture cookies once; normal commands reuse saved cookies.", auth!, readInput, options);
@@ -660,6 +669,64 @@ export function createRoot(wire: Wire, currentDirectory: string, auth?: Auth, re
660
669
  render: wirePresentation.switchBackend,
661
670
  }),
662
671
  sync,
672
+ defineCommand({
673
+ name: "status", scope: ["cli"], description: "Show local changes or conflicts for one tracked document.",
674
+ positional: ["resource"], params: S.Object({ resource }),
675
+ handler: ({ params }) => userFacing(() => wire.historyStatus(params.resource, currentDirectory)),
676
+ render: render(historyStatusText),
677
+ }),
678
+ defineCommand({
679
+ name: "history", scope: ["cli"], description: "List local revisions, newest first.",
680
+ positional: ["resource"], params: S.Object({ resource }),
681
+ handler: ({ params }) => userFacing(() => wire.historyLog(params.resource, currentDirectory)),
682
+ render: render<Awaited<ReturnType<Wire["historyLog"]>>>(revisions =>
683
+ revisions.map(r => `${r.id} ${r.at} ${r.kind}`).join("\n") || "No revisions recorded."),
684
+ }),
685
+ defineCommand({
686
+ name: "diff", scope: ["cli"], description: "Compare two versions. Defaults to the last sync and working copy.",
687
+ positional: ["resource"], params: S.Object({ resource,
688
+ from: S.Optional(S.String({ description: "Revision ID, base, working, local, remote, editor, or shell." })),
689
+ to: S.Optional(S.String({ description: "Revision ID, base, working, local, remote, editor, or shell." })),
690
+ }),
691
+ handler: ({ params }) => userFacing(async () => {
692
+ const d = await wire.historyDiff(params.resource, currentDirectory, params.from, params.to);
693
+ const { documentDiff } = await import("./document-shell.js");
694
+ return { from: d.from, to: d.to, diff: await documentDiff(d.from, d.to, d.before, d.after) };
695
+ }),
696
+ render: render<{ diff: string }>(result => result.diff || "No changes."),
697
+ }),
698
+ defineCommand({
699
+ name: "conflicts", scope: ["cli"], description: "Show both saved sides of an unresolved conflict.",
700
+ positional: ["resource"], params: S.Object({ resource }),
701
+ handler: ({ params }) => userFacing(async () => (await wire.historyStatus(params.resource, currentDirectory)).conflict),
702
+ render: render<Awaited<ReturnType<Wire["historyStatus"]>>["conflict"]>(c => c && "editor" in c ?
703
+ `editor: ${c.editor}\nshell: ${c.shell}\nCompare with wire diff <resource> --from editor --to shell. Edit the working file and resolve working, or choose editor or shell.` : c ?
704
+ `base: ${c.base}\nlocal: ${c.local}\nremote: ${c.remote}\nCompare with wire diff <resource> --from local --to remote, then wire resolve <resource> <choice>.` : "No conflicts."),
705
+ }),
706
+ defineCommand({
707
+ name: "resolve", scope: ["cli"], description: "Resolve a conflict locally. Sync to publish.",
708
+ positional: ["resource", "choice"], params: S.Object({ resource,
709
+ choice: S.Enum(["local", "remote", "working", "editor", "shell"] as const, { description: "Choose a saved side of the conflict, or working to keep your edited file." }),
710
+ }),
711
+ handler: ({ params }) => userFacing(() => wire.resolveConflict(params.resource, currentDirectory, params.choice)),
712
+ render: render(historyStatusText),
713
+ }),
714
+ defineCommand({
715
+ name: "shell", scope: ["cli"], description: "Run a quoted safe-bash script on /document.md. Successful edits stay local until sync.",
716
+ positional: ["resource", "script"], params: S.Object({ resource,
717
+ script: S.String({ description: "Shell script; /document.md is the only tracked file in the in-memory filesystem." }),
718
+ }),
719
+ handler: ({ params }) => userFacing(async () => {
720
+ const d = await wire.historyDiff(params.resource, currentDirectory, "working", "working");
721
+ const { editDocument } = await import("./document-shell.js");
722
+ const { edited, stdout, stderr } = await editDocument(d.before, params.script).catch(error => { throw new UserError(thrownMessage(error)); });
723
+ const changed = edited !== d.before;
724
+ if (changed) await wire.checkpoint(params.resource, currentDirectory, d.before, edited, d.token);
725
+ return { changed, stdout, stderr };
726
+ }),
727
+ render: render<{ changed: boolean; stdout: string; stderr: string }>(r =>
728
+ [r.stdout.trimEnd(), r.stderr.trimEnd(), r.changed ? "Saved locally. Run wire sync to publish." : "No changes."].filter(Boolean).join("\n")),
729
+ }),
663
730
  defineCommand({
664
731
  name: "download",
665
732
  description: "Download a source URL as local Markdown without tracking it.",
package/src/cli.ts CHANGED
@@ -110,6 +110,12 @@ function normalizeBareDebugArgv(argv: readonly string[]): readonly string[] {
110
110
 
111
111
  const fixedCommandPositionals = Object.freeze({
112
112
  attach: Object.freeze({ expected: 1, name: "url" }),
113
+ conflicts: Object.freeze({ expected: 1, name: "resource" }),
114
+ diff: Object.freeze({ expected: 1, name: "resource" }),
115
+ history: Object.freeze({ expected: 1, name: "resource" }),
116
+ resolve: Object.freeze({ expected: 2, name: "choice" }),
117
+ shell: Object.freeze({ expected: 2, name: "script" }),
118
+ status: Object.freeze({ expected: 1, name: "resource" }),
113
119
  detach: Object.freeze({ expected: 1, name: "resource" }),
114
120
  download: Object.freeze({ expected: 1, name: "url" }),
115
121
  init: Object.freeze({ expected: 0, name: "" }),
@@ -222,7 +228,7 @@ function positionalWords(argv: readonly string[]): readonly string[] | null {
222
228
  continue;
223
229
  } else if (arg === "--output" || (arg === "--backend" && words[0] === "init") || (arg === "--debug" && argv[index + 1] !== undefined && debugModeNames.has(argv[index + 1]!))) {
224
230
  index += 1;
225
- } else if (arg === "--debug" || (arg === "--paste" && authServices.has(words[0]!) && words[1] === "login") || arg.startsWith("--debug=") || arg.startsWith("--output=") || (arg.startsWith("--backend=") && words[0] === "init")) {
231
+ } else if ((arg === "--editor-receipts" && (words[0] === "attach" || (words[0] && isSourceUrl(words[0])))) || arg === "--debug" || (arg === "--paste" && authServices.has(words[0]!) && words[1] === "login") || arg.startsWith("--debug=") || arg.startsWith("--output=") || (arg.startsWith("--backend=") && words[0] === "init")) {
226
232
  continue;
227
233
  } else if (arg.startsWith("-")) {
228
234
  return null;
@@ -267,7 +273,7 @@ function missingPositionals(argv: readonly string[]): Readonly<{ commandPath: st
267
273
  if (!(command in fixedCommandPositionals)) return null;
268
274
  const positional = fixedCommandPositionals[command as keyof typeof fixedCommandPositionals];
269
275
  if (words.length - 1 >= positional.expected || positional.expected === 0) return null;
270
- return Object.freeze({ commandPath: command, name: positional.name });
276
+ return Object.freeze({ commandPath: command, name: words.length === 1 && positional.expected === 2 ? "resource" : positional.name });
271
277
  }
272
278
 
273
279
  function renderMissingPositionals(argv: readonly string[]): boolean {
package/src/executable.ts CHANGED
@@ -125,7 +125,7 @@ export function createExecutableRoot(environment: NodeEnvironment, currentDirect
125
125
  });
126
126
  const configuredWire = Object.freeze({
127
127
  ...baseWire,
128
- attach: async (url: string, path: string) => { activeConfigurationPath = path; return baseWire.attach(url, path); },
128
+ attach: async (url: string, path: string, editorReceipts?: boolean) => { activeConfigurationPath = path; return baseWire.attach(url, path, editorReceipts); },
129
129
  create: async (url: string, path: string) => { activeConfigurationPath = path; return baseWire.create(url, path); },
130
130
  view: async (url: string) => { activeConfigurationPath = currentDirectory; const id = codeSignalInterviewId(url); return id ? previewCodeSignal(runtime, id) : baseWire.view(url); },
131
131
  downloadSource: async (url: string, path: string) => { activeConfigurationPath = path; return baseWire.downloadSource(url, path); },
package/src/hooks.ts CHANGED
@@ -7,7 +7,7 @@ import { promisify } from "node:util";
7
7
  import type { Resource, Wire, WireResult } from "wire-core";
8
8
  import { configuredWireRoot, loadWireConfig, openWireRegistry, wireRelativePath } from "wire-core";
9
9
  import type { WireWatchSyncHook } from "wire-core/internal/operations";
10
- import { wireWatchHooks } from "wire-core/internal/operations";
10
+ import { sourceLock, wireWatchHooks, withHistoryLock } from "wire-core/internal/operations";
11
11
 
12
12
  const execFileAsync = promisify(execFile);
13
13
 
@@ -106,21 +106,22 @@ function outputEnvironment(stdout: string): Record<string, string> {
106
106
  return values;
107
107
  }
108
108
 
109
- async function updateMovedResult(options: WireHookOptions, wireRoot: string, result: WireResult, movedPath: string): Promise<WireResult> {
109
+ async function updateMovedResult(options: WireHookOptions, wireRoot: string, result: WireResult, movedPath: string, tracked: boolean): Promise<WireResult> {
110
110
  const workspace = dirname(wireRoot);
111
111
  const outputPath = isAbsolute(movedPath) ? movedPath : resolve(workspace, movedPath);
112
112
  const relativePath = wireRelativePath(outputPath, wireRoot);
113
113
  const primary = primaryFilesystemLink(result.resource);
114
- const resource = {
115
- ...result.resource,
116
- filesystem_links: [
117
- ...result.resource.filesystem_links.filter((link) => !(link.path === primary.path && link.role === "primary")),
118
- { ...primary, path: relativePath },
119
- ],
120
- };
121
- if (result.summary.action !== "detached") {
122
- const registry = await openWireRegistry(wireRoot, options.home);
123
- if ((await registry.listResources()).some((item) => item.id === result.resource.id)) await registry.put(resource);
114
+ const moveLink = (r: Resource): Resource => ({ ...r, filesystem_links: r.filesystem_links.map(link =>
115
+ link.role === "primary" && link.path === primary.path ? { ...link, path: relativePath } : link) });
116
+ let resource = moveLink(result.resource);
117
+ if (result.summary.action !== "detached" && tracked) {
118
+ const source = result.resource.identifiers.find(i => i.service + ":" + i.identifier === result.resource.id)!;
119
+ resource = await withHistoryLock(wireRoot, sourceLock({ ...source, type: result.resource.type }), async () => {
120
+ const registry = await openWireRegistry(wireRoot, options.home);
121
+ const latest = await registry.get(result.resource.id);
122
+ if (primaryFilesystemLink(latest).path !== primary.path) throw new Error("The registered path changed while the hook was running. Wire kept the newer path.");
123
+ return registry.put(moveLink(latest));
124
+ });
124
125
  }
125
126
  return { ...result, resource, path: outputPath, summary: { ...result.summary, local: outputPath } };
126
127
  }
@@ -139,7 +140,7 @@ async function runHookCommands(wireRoot: string, event: WireHookEvent, environme
139
140
  return current;
140
141
  }
141
142
 
142
- async function runResourceHooks(options: WireHookOptions, command: string, result: WireResult): Promise<HookState> {
143
+ async function runResourceHooks(options: WireHookOptions, command: string, result: WireResult, tracked = true): Promise<HookState> {
143
144
  const wireRoot = await configuredWireRoot(result.path, options.home);
144
145
  if (wireRoot === null) return { result, environment: {} };
145
146
  let currentResult = result;
@@ -153,7 +154,7 @@ async function runResourceHooks(options: WireHookOptions, command: string, resul
153
154
  environment = { ...environment, ...output };
154
155
  const outputPath = output["WIRE_PATH"];
155
156
  if (outputPath !== undefined && resolve(dirname(wireRoot), outputPath) !== currentResult.path) {
156
- currentResult = await updateMovedResult(options, wireRoot, currentResult, outputPath);
157
+ currentResult = await updateMovedResult(options, wireRoot, currentResult, outputPath, tracked);
157
158
  environment = { ...environment, ...resourceEnvironment(command, options.currentDirectory, wireRoot, currentResult) };
158
159
  }
159
160
  }
@@ -170,8 +171,8 @@ async function runSummaryHooks(options: WireHookOptions, event: WireHookEvent, c
170
171
  });
171
172
  }
172
173
 
173
- async function runSingleResultHooks(options: WireHookOptions, command: string, result: WireResult): Promise<WireResult> {
174
- const state = result.summary.action === "failed" ? { result, environment: {} } : await runResourceHooks(options, command, result);
174
+ async function runSingleResultHooks(options: WireHookOptions, command: string, result: WireResult, tracked = true): Promise<WireResult> {
175
+ const state = result.summary.action === "failed" ? { result, environment: {} } : await runResourceHooks(options, command, result, tracked);
175
176
  await runSummaryHooks(options, "post-command", command, state.result.path, [state.result], state.environment);
176
177
  return state.result;
177
178
  }
@@ -198,10 +199,10 @@ export function withWireHooks(wire: Wire, options: WireHookOptions): Wire {
198
199
  const watchSyncHook: WireWatchSyncHook = (command, result) => runSingleResultHooks(options, command, result);
199
200
  return Object.freeze({
200
201
  ...wire,
201
- attach: async (url, path) => runSingleResultHooks(options, "attach", await wire.attach(url, path)),
202
+ attach: async (url, path, editorReceipts) => runSingleResultHooks(options, "attach", await wire.attach(url, path, editorReceipts)),
202
203
  create: async (url, path) => runSingleResultHooks(options, "attach", await wire.create(url, path)),
203
204
  sync: async (value, path) => runSingleResultHooks(options, "sync", await wire.sync(value, path)),
204
- downloadSource: async (url, path) => runSingleResultHooks(options, "download", await wire.downloadSource(url, path)),
205
+ downloadSource: async (url, path) => runSingleResultHooks(options, "download", await wire.downloadSource(url, path), false),
205
206
  download: async (value, path) => runSingleResultHooks(options, "download", await wire.download(value, path)),
206
207
  detach: async (value, path) => runSingleResultHooks(options, "detach", await wire.detach(value, path)),
207
208
  unlink: async (value, path) => runSingleResultHooks(options, "detach", await wire.unlink(value, path)),