@open-document/core 0.16.0 → 0.17.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.
Files changed (56) hide show
  1. package/dist/{build-BS_CoazO.js → build-BzNZnIhF.js} +1 -1
  2. package/dist/{check-tTjyMCrU.js → check-C7kxlAFW.js} +11 -4
  3. package/dist/cli/bin.js +24 -11
  4. package/dist/{context-Cli81dhF.js → context-CFPnmNCR.js} +1 -1
  5. package/dist/{dev-n222xdoE.js → dev-BUo7OESU.js} +1 -1
  6. package/dist/{diff-DB_qruzT.js → diff-B950T0O6.js} +2 -2
  7. package/dist/{export-CCFtdscQ.js → export-CHN1CiGv.js} +3 -3
  8. package/dist/{flow-CS5apebG.d.ts → flow-DlV3t5ML.d.ts} +24 -4
  9. package/dist/{import-D7k0yYZh.js → import-CLSnIxvN.js} +11 -7
  10. package/dist/index.d.ts +26 -2
  11. package/dist/index.js +55 -1
  12. package/dist/ops/index.d.ts +138 -4
  13. package/dist/ops/index.js +3 -3
  14. package/dist/{ops-CouYBa1O.js → ops-BgbM5Irm.js} +197 -9
  15. package/dist/{preview-DV0GDIsj.js → preview-BVwVqS-I.js} +1 -1
  16. package/dist/proofread-BpR_3GZz.js +35 -0
  17. package/dist/{session-Cx7Msl_F.js → session-DmbXf3u7.js} +5135 -67
  18. package/dist/{templates-C-7VcMMV.js → templates-BsWxs7oo.js} +3 -3
  19. package/dist/translations-CW5OVM0L.js +42 -0
  20. package/dist/vite/index.js +1 -1
  21. package/package.json +1 -1
  22. package/skills/doc-authoring/references/pagination.md +1 -1
  23. package/skills/fill-form/SKILL.md +42 -0
  24. package/skills/fit-pages/SKILL.md +48 -0
  25. package/skills/import-document/SKILL.md +58 -0
  26. package/skills/proofread/SKILL.md +44 -0
  27. package/skills/refresh-report/SKILL.md +48 -0
  28. package/skills/sync-translation/SKILL.md +55 -0
  29. package/src/agent/prompt.ts +1 -1
  30. package/src/app/components/checkbox.tsx +68 -0
  31. package/src/app/components/doc-sidebar.tsx +5 -3
  32. package/src/app/components/flow-page.tsx +7 -2
  33. package/src/app/components/panel/edit-save-card.tsx +3 -0
  34. package/src/app/lib/agent-bridge.ts +37 -4
  35. package/src/app/lib/diagnostics.ts +46 -5
  36. package/src/app/lib/export-docx.ts +5 -2
  37. package/src/app/lib/export-dom.ts +13 -0
  38. package/src/app/lib/export-html.ts +6 -1
  39. package/src/app/lib/export-image.ts +9 -4
  40. package/src/app/lib/export-pdf.ts +17 -4
  41. package/src/app/lib/flow-measure.ts +9 -5
  42. package/src/app/lib/flow.ts +3 -2
  43. package/src/app/lib/i18n-ja/browser.ts +1 -0
  44. package/src/app/lib/i18n-ko/browser.ts +1 -0
  45. package/src/app/lib/i18n-zh-cn/browser.ts +1 -0
  46. package/src/app/lib/i18n-zh-tw/browser.ts +1 -0
  47. package/src/app/lib/page-budget.ts +81 -0
  48. package/src/app/lib/proofread-script.ts +61 -0
  49. package/src/app/lib/proofread.ts +399 -0
  50. package/src/app/lib/recent-docs.ts +27 -0
  51. package/src/app/lib/sdk.ts +44 -2
  52. package/src/app/lib/text-runs.ts +83 -0
  53. package/src/app/lib/use-doc-pages.ts +10 -3
  54. package/src/app/routes/doc-preview.tsx +1 -1
  55. package/src/app/routes/doc.tsx +26 -2
  56. package/src/app/routes/home.tsx +39 -5
@@ -1,4 +1,4 @@
1
- import { A as assertExpectedSource, H as resolveEntry, M as withFileLock, N as OpsError, j as hashSource, n as createRenderSession, t as RenderUnavailableError } from "./session-Cx7Msl_F.js";
1
+ import { B as listDocIds, F as OpsError, G as resolveEntry, M as assertExpectedSource, N as hashSource, P as withFileLock, U as readMetaField, n as createRenderSession, q as setMetaString, t as RenderUnavailableError } from "./session-DmbXf3u7.js";
2
2
  import path from "node:path";
3
3
  import fs from "node:fs/promises";
4
4
  import { execFile } from "node:child_process";
@@ -219,17 +219,17 @@ ${body}
219
219
  }
220
220
  //#endregion
221
221
  //#region src/ops/diff.ts
222
- const run = promisify(execFile);
222
+ const run$1 = promisify(execFile);
223
223
  const MAX_BUFFER = 67108864;
224
- async function git(cwd, args) {
225
- const { stdout } = await run("git", args, {
224
+ async function git$1(cwd, args) {
225
+ const { stdout } = await run$1("git", args, {
226
226
  cwd,
227
227
  maxBuffer: MAX_BUFFER
228
228
  });
229
229
  return stdout;
230
230
  }
231
231
  async function gitBytes(cwd, args) {
232
- const { stdout } = await run("git", args, {
232
+ const { stdout } = await run$1("git", args, {
233
233
  cwd,
234
234
  maxBuffer: MAX_BUFFER,
235
235
  encoding: "buffer"
@@ -243,7 +243,7 @@ async function gitBytes(cwd, args) {
243
243
  * the current version renders with.
244
244
  */
245
245
  async function checkout(ctx, docId, commit) {
246
- const prefix = (await git(ctx.userCwd, ["rev-parse", "--show-prefix"])).trim();
246
+ const prefix = (await git$1(ctx.userCwd, ["rev-parse", "--show-prefix"])).trim();
247
247
  const dir = path.join(ctx.userCwd, ".open-doc-diff", `${commit.slice(0, 12)}-${docId}`);
248
248
  await fs.rm(dir, {
249
249
  recursive: true,
@@ -257,7 +257,7 @@ async function checkout(ctx, docId, commit) {
257
257
  ];
258
258
  let exists = false;
259
259
  for (const rel of wanted) {
260
- const listed = await git(ctx.userCwd, [
260
+ const listed = await git$1(ctx.userCwd, [
261
261
  "ls-tree",
262
262
  "-r",
263
263
  "--full-tree",
@@ -319,7 +319,7 @@ async function diffDocument(ctx, docId, opts = {}) {
319
319
  const since = opts.since ?? "HEAD";
320
320
  let commit;
321
321
  try {
322
- commit = (await git(ctx.userCwd, [
322
+ commit = (await git$1(ctx.userCwd, [
323
323
  "rev-parse",
324
324
  "--verify",
325
325
  `${since}^{commit}`
@@ -565,4 +565,192 @@ async function editDocument(ctx, docId, find, replace, opts = {}) {
565
565
  });
566
566
  }
567
567
  //#endregion
568
- export { searchDocument as a, readDocumentLines as i, outlineDocument as n, diffDocument as o, outlineSource as r, editDocument as t };
568
+ //#region src/ops/translations.ts
569
+ const run = promisify(execFile);
570
+ const DIFF_LIMIT = 2e5;
571
+ async function git(cwd, args) {
572
+ const { stdout } = await run("git", args, {
573
+ cwd,
574
+ maxBuffer: 33554432
575
+ });
576
+ return stdout;
577
+ }
578
+ async function gitOk(cwd, args) {
579
+ try {
580
+ await git(cwd, args);
581
+ return true;
582
+ } catch {
583
+ return false;
584
+ }
585
+ }
586
+ function folderOf(ctx, docId) {
587
+ return path.relative(ctx.userCwd, path.join(ctx.docsRoot, docId)).split(path.sep).join("/");
588
+ }
589
+ async function readSource(ctx, docId) {
590
+ const entry = resolveEntry(ctx, docId);
591
+ return entry ? fs.readFile(entry, "utf8") : null;
592
+ }
593
+ async function statusOf(ctx, id, source, opts) {
594
+ const of = readMetaField(source, "translationOf");
595
+ if (!of) return null;
596
+ const translatedAt = readMetaField(source, "translatedAt");
597
+ const base = {
598
+ id,
599
+ lang: readMetaField(source, "lang"),
600
+ of,
601
+ state: "current",
602
+ ...translatedAt ? { translatedAt } : {},
603
+ changedFiles: [],
604
+ commits: []
605
+ };
606
+ const original = await readSource(ctx, of);
607
+ if (original === null) return {
608
+ ...base,
609
+ state: "missing-source"
610
+ };
611
+ base.sourceLang = readMetaField(original, "lang");
612
+ if (!opts.repo) return {
613
+ ...base,
614
+ state: "no-git"
615
+ };
616
+ if (!translatedAt) return {
617
+ ...base,
618
+ state: "unsynced"
619
+ };
620
+ if (!await gitOk(ctx.userCwd, [
621
+ "cat-file",
622
+ "-e",
623
+ `${translatedAt}^{commit}`
624
+ ])) return {
625
+ ...base,
626
+ state: "unknown-revision"
627
+ };
628
+ const folder = folderOf(ctx, of);
629
+ const tracked = (await git(ctx.userCwd, [
630
+ "diff",
631
+ "--name-only",
632
+ translatedAt,
633
+ "--",
634
+ folder
635
+ ])).split("\n").filter(Boolean);
636
+ const untracked = (await git(ctx.userCwd, [
637
+ "ls-files",
638
+ "--others",
639
+ "--exclude-standard",
640
+ "--",
641
+ folder
642
+ ])).split("\n").filter(Boolean);
643
+ const changedFiles = [.../* @__PURE__ */ new Set([...tracked, ...untracked])].sort();
644
+ const commits = (await git(ctx.userCwd, [
645
+ "log",
646
+ "--format=%h%x09%s",
647
+ `${translatedAt}..HEAD`,
648
+ "--",
649
+ folder
650
+ ])).split("\n").filter(Boolean).map((line) => {
651
+ const [short, ...subject] = line.split(" ");
652
+ return {
653
+ short,
654
+ subject: subject.join(" ")
655
+ };
656
+ });
657
+ const status = {
658
+ ...base,
659
+ state: changedFiles.length > 0 ? "stale" : "current",
660
+ changedFiles,
661
+ commits
662
+ };
663
+ if (opts.diff && changedFiles.length > 0) {
664
+ let diff = await git(ctx.userCwd, [
665
+ "diff",
666
+ translatedAt,
667
+ "--",
668
+ folder
669
+ ]);
670
+ for (const file of untracked) {
671
+ const text = await fs.readFile(path.join(ctx.userCwd, file), "utf8").catch(() => "");
672
+ diff += `--- /dev/null\n+++ b/${file}\n${text.split("\n").map((l) => `+${l}`).join("\n")}\n`;
673
+ }
674
+ status.diff = diff.length > DIFF_LIMIT ? diff.slice(0, DIFF_LIMIT) : diff;
675
+ if (diff.length > DIFF_LIMIT) status.diffTruncated = true;
676
+ }
677
+ return status;
678
+ }
679
+ /**
680
+ * Every document that declares `meta.translationOf`, and whether its source
681
+ * moved on since the version it was translated from (`meta.translatedAt`, a
682
+ * commit). Pass `docId` for one translation, and `diff` for what changed.
683
+ */
684
+ async function translationStatus(ctx, opts = {}) {
685
+ const repo = await gitOk(ctx.userCwd, ["rev-parse", "--is-inside-work-tree"]) === true;
686
+ const ids = opts.docId ? [opts.docId] : await listDocIds(ctx);
687
+ const out = [];
688
+ for (const id of ids) {
689
+ const source = await readSource(ctx, id);
690
+ if (source === null) {
691
+ if (opts.docId) throw new OpsError(404, `document not found: ${id}`);
692
+ continue;
693
+ }
694
+ const status = await statusOf(ctx, id, source, {
695
+ diff: opts.diff,
696
+ repo
697
+ });
698
+ if (status) out.push(status);
699
+ else if (opts.docId) throw new OpsError(422, `${id} has no meta.translationOf`);
700
+ }
701
+ return out;
702
+ }
703
+ /**
704
+ * Records that a translation now matches its source as of `revision` — by
705
+ * default the last commit that touched the source. Refuses while the source
706
+ * has uncommitted changes, which no commit could name.
707
+ */
708
+ async function markTranslated(ctx, docId, revision) {
709
+ const entry = resolveEntry(ctx, docId);
710
+ if (!entry) throw new OpsError(404, `document not found: ${docId}`);
711
+ if (!await gitOk(ctx.userCwd, ["rev-parse", "--is-inside-work-tree"])) throw new OpsError(412, "the workspace is not a git repository; translations are traced by commit");
712
+ const source = await fs.readFile(entry, "utf8");
713
+ const of = readMetaField(source, "translationOf");
714
+ if (!of) throw new OpsError(422, `${docId} has no meta.translationOf`);
715
+ if (!resolveEntry(ctx, of)) throw new OpsError(404, `source document not found: ${of}`);
716
+ const folder = folderOf(ctx, of);
717
+ let commit;
718
+ if (revision) try {
719
+ commit = (await git(ctx.userCwd, [
720
+ "rev-parse",
721
+ "--verify",
722
+ `${revision}^{commit}`
723
+ ])).trim();
724
+ } catch {
725
+ throw new OpsError(400, `not a commit: ${revision}`);
726
+ }
727
+ else {
728
+ if ((await git(ctx.userCwd, [
729
+ "status",
730
+ "--porcelain",
731
+ "--",
732
+ folder
733
+ ])).trim()) throw new OpsError(409, `${of} has uncommitted changes; commit them first so the translation can name the version it matches`);
734
+ commit = (await git(ctx.userCwd, [
735
+ "log",
736
+ "-1",
737
+ "--format=%H",
738
+ "--",
739
+ folder
740
+ ])).trim();
741
+ if (!commit) throw new OpsError(409, `${of} has never been committed`);
742
+ }
743
+ await withFileLock(entry, async () => {
744
+ const current = await fs.readFile(entry, "utf8");
745
+ const next = setMetaString(current, "translatedAt", commit);
746
+ if (next === null) throw new OpsError(422, `${docId} has no \`export const meta\` object`);
747
+ if (next !== current) await fs.writeFile(entry, next, "utf8");
748
+ });
749
+ return {
750
+ id: docId,
751
+ of,
752
+ translatedAt: commit
753
+ };
754
+ }
755
+ //#endregion
756
+ export { outlineSource as a, diffDocument as c, outlineDocument as i, translationStatus as n, readDocumentLines as o, editDocument as r, searchDocument as s, markTranslated as t };
@@ -1,4 +1,4 @@
1
- import { r as createViteConfig } from "./session-Cx7Msl_F.js";
1
+ import { r as createViteConfig } from "./session-DmbXf3u7.js";
2
2
  import { mergeConfig, preview as preview$1 } from "vite";
3
3
  //#region src/cli/preview.ts
4
4
  async function preview(opts = {}) {
@@ -0,0 +1,35 @@
1
+ import { B as listDocIds, S as closeRenderSession, w as proofreadDocument } from "./session-DmbXf3u7.js";
2
+ import "./ops-BgbM5Irm.js";
3
+ import { t as cliContext } from "./context-CFPnmNCR.js";
4
+ import chalk from "chalk";
5
+ //#region src/cli/proofread.ts
6
+ function line(finding) {
7
+ const where = `p.${finding.page}`;
8
+ const detail = [chalk.dim(`${finding.rule}`), finding.loc && chalk.dim(`@ ${finding.loc}`)].filter(Boolean).join(" ");
9
+ return ` ${chalk.yellow("!")} ${chalk.dim(where.padEnd(5))} ${finding.message}\n ${chalk.dim(finding.snippet)}\n ${detail}`;
10
+ }
11
+ /**
12
+ * Reads the text every sheet prints and reports consistency slips. It is
13
+ * advice, so it exits zero even with findings; `check` is the gate.
14
+ */
15
+ async function proofreadDocs(docIds, opts = {}) {
16
+ const ctx = await cliContext();
17
+ const targets = docIds.length > 0 ? docIds : await listDocIds(ctx);
18
+ if (targets.length === 0) throw new Error("No documents found under docs/.");
19
+ const reports = [];
20
+ try {
21
+ for (const docId of targets) {
22
+ const report = await proofreadDocument(ctx, docId);
23
+ reports.push(report);
24
+ if (opts.json) continue;
25
+ const summary = report.warnings === 0 ? chalk.green("clean") : chalk.yellow(`${report.warnings} warning(s)${report.omitted > 0 ? `, ${report.omitted} more not shown` : ""}`);
26
+ process.stdout.write(`${chalk.bold(docId)} ${chalk.dim(`${report.pageCount} pages · ${report.lang}`)} — ${summary}\n`);
27
+ for (const finding of report.findings) process.stdout.write(`${line(finding)}\n`);
28
+ }
29
+ } finally {
30
+ await closeRenderSession();
31
+ }
32
+ if (opts.json) process.stdout.write(`${JSON.stringify(reports, null, 2)}\n`);
33
+ }
34
+ //#endregion
35
+ export { proofreadDocs };