@attentionform/astra 0.1.0 → 0.2.1

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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The CLI side of the baseline-aware validation gate. A file that already has validator errors can be
3
+ * written when an edit adds none; `--strict` refuses every error as before.
4
+ */
5
+ import { BASELINE_MAX_ERRORS, type BaselineVerdict, type ValidationResult } from '@attentionform/astra-engine';
6
+ export { BASELINE_MAX_ERRORS };
7
+ export type ToleratedVerdict = Extract<BaselineVerdict, {
8
+ kind: 'tolerated';
9
+ }>;
10
+ export type IntroducedVerdict = Extract<BaselineVerdict, {
11
+ kind: 'introduced';
12
+ }>;
13
+ /**
14
+ * Judges the result of a gate. A valid result is clean. Otherwise, unless `strict`, the errors are
15
+ * compared with those of the original bytes, which are validated only now and only when needed.
16
+ */
17
+ export declare function judgeGate(result: ValidationResult, strict: boolean, original: () => Buffer): Promise<BaselineVerdict>;
18
+ /** True when the gate must refuse the write. */
19
+ export declare function refuses(verdict: BaselineVerdict): boolean;
20
+ /** Wording of a refusal for an edit that adds errors to a file that already had some. */
21
+ export declare function introducedText(verdict: IntroducedVerdict, description: string): string;
22
+ /** Fields added to the JSON output when errors the file already had were tolerated. */
23
+ export declare function toleratedFields(verdict: ToleratedVerdict | undefined): Record<string, unknown>;
24
+ /** The line written to stderr when errors the file already had were tolerated. */
25
+ export declare function toleratedNote(verdict: ToleratedVerdict): string;
@@ -43,6 +43,10 @@ export interface RunBatchJobCtx {
43
43
  target: string;
44
44
  sequential: boolean | undefined;
45
45
  skipValidate: boolean;
46
+ /** --strict: refuse every validator error, including errors the file already had. */
47
+ strict: boolean;
48
+ /** --no-history: do not record a history revision, even when the document has a history repository. */
49
+ noHistory?: boolean;
46
50
  flagCeilings: ZipCeilingOverrides;
47
51
  dryRun: boolean;
48
52
  backupState: BackupState;
@@ -112,6 +116,8 @@ export interface StreamCmdArgs {
112
116
  outPath: string | undefined;
113
117
  sequential: boolean | undefined;
114
118
  skipValidate: boolean;
119
+ strict: boolean;
120
+ noHistory: boolean;
115
121
  flagCeilings: ZipCeilingOverrides;
116
122
  dryRun: boolean;
117
123
  backupGiven: boolean;
@@ -139,6 +145,8 @@ export interface StreamSessionOpts {
139
145
  target: string;
140
146
  sequential: boolean | undefined;
141
147
  skipValidate: boolean;
148
+ strict?: boolean;
149
+ noHistory?: boolean;
142
150
  flagCeilings: ZipCeilingOverrides;
143
151
  backupState: BackupState;
144
152
  backupSource: Buffer;
@@ -1,4 +1,10 @@
1
1
  import { type GlobalOpts } from './output';
2
2
  export declare const CREATE_TEMPLATES: readonly ["report", "memo", "blank"];
3
3
  export type CreateTemplate = (typeof CREATE_TEMPLATES)[number];
4
+ /**
5
+ * A note for a template that comes with text of its own, or undefined for `blank`. `report` holds a whole sample
6
+ * report with invented figures, and `memo` holds a heading and a placeholder line.
7
+ * When Markdown is composed via --from-md or import, the pristine template seed is cleanly replaced.
8
+ */
9
+ export declare function templateSampleNote(template: string, composed: boolean): string | undefined;
4
10
  export declare function cmdCreate(out: GlobalOpts, args: string[]): Promise<number>;
@@ -0,0 +1,38 @@
1
+ import { DocxParser } from '@attentionform/astra-engine';
2
+ export declare function capCommitMessage(message: string): string;
3
+ /** Sidecar `.git` state: a real repo directory, a stray non-directory entry, or absent. */
4
+ export type SidecarGitState = 'repo' | 'stray' | 'absent';
5
+ /**
6
+ * Classify the sidecar's `.git` entry. `stray` is a refusal state: a `.git`
7
+ * FILE (e.g. a leftover `gitdir:` link) redirects the repository elsewhere;
8
+ * isomorphic-git follows it, so writes would land outside the sidecar and
9
+ * reads would loop back to the "no sidecar" gate — never treat it as absent.
10
+ * Symlinks are followed like isomorphic-git does: a link to a real directory
11
+ * is a usable repo; a link to a file or a broken link is stray.
12
+ */
13
+ export declare function sidecarGitState(file: string): SidecarGitState;
14
+ /** Is a valid sidecar chain present for this document? */
15
+ export declare function hasHistorySidecar(file: string): boolean;
16
+ /** Tracked package files (everything but document.xml) from a live snapshot. */
17
+ export declare function trackedExtras(snapshot: Map<string, Buffer>): Map<string, Buffer>;
18
+ export declare function extrasRecord(extras: Map<string, Buffer>): Record<string, Buffer>;
19
+ export type BatchRevisionResult = {
20
+ recorded: true;
21
+ commit: string;
22
+ } | {
23
+ recorded: false;
24
+ reason: string;
25
+ } | null;
26
+ /**
27
+ * Records the document just written by a command as a history revision, but only when the document
28
+ * already has a history repository and the command wrote the document itself (not an `--out` copy).
29
+ * Returns null when nothing was due. A failure is reported on stderr and in the result; the command
30
+ * keeps its exit code, because the file was written.
31
+ */
32
+ export declare function recordBatchRevision(args: {
33
+ file: string;
34
+ target: string;
35
+ parser: DocxParser;
36
+ message: string;
37
+ noHistory: boolean;
38
+ }): Promise<BatchRevisionResult>;
@@ -26,6 +26,16 @@ export declare function macroOptsFromFlags(f: MacroFlagChoice): {
26
26
  stripMacros: true;
27
27
  } | undefined;
28
28
  export declare function macroFlagsUsageError(): string;
29
+ /**
30
+ * A package that still holds macro parts has to be saved as .docm or .dotm; Word refuses a .docx that has them.
31
+ * Returns the refusal text when the output name does not fit the parts that stay in the file, else null.
32
+ */
33
+ export declare function macroOutputRefusal(command: string, output: string, macroParts: readonly string[], stripped: boolean): string | null;
34
+ /**
35
+ * `--strip-macros` leaves a plain document, so it cannot be written under a macro-enabled name (.docm, .dotm):
36
+ * Word would refuse the file. Returns the refusal text for such a target, else null.
37
+ */
38
+ export declare function macroStripNameRefusal(command: string, target: string, remedy: string): string | null;
29
39
  /**
30
40
  * Scope ceiling overrides around a DocxParser load. The engine resolves
31
41
  * ceilings from env at check time (pre-read + central-directory gates), so
@@ -33,7 +33,10 @@ export declare function previewNormalizedForDisplay(buf: Buffer, macroOpts?: {
33
33
  stripMacros?: boolean;
34
34
  }): NormalizedRewrite[];
35
35
  /** Display-only repair entry: core parse + rezip (the hook heals), or passthrough on failure. */
36
- export declare function applyNormalizerForDisplay(buf: Buffer): {
36
+ export declare function applyNormalizerForDisplay(buf: Buffer, macroOpts?: {
37
+ allowMacros?: boolean;
38
+ stripMacros?: boolean;
39
+ }): {
37
40
  buffer: Buffer;
38
41
  normalized: NormalizedRewrite[];
39
42
  };
@@ -4,13 +4,13 @@
4
4
  *
5
5
  * Commands (all fail-closed — any operational failure exits non-zero):
6
6
  * inspect <docx> [--fidelity compact|standard|full] [--section <id>] [--max-text <n>] [--width <n>] [--wrap] [--visual] [--format png|jpeg] [--max-ratio <n>] [--max-uncompressed-bytes <n>]
7
- * validate <docx> [--max-ratio <n>] [--max-uncompressed-bytes <n>] [--style-guide <name|path>]
8
- * sanitize <in.docx> <out.docx> [--client-safe] [--redact-pii] [--zero-retention] [--replacement-author <name>] [--accept-all-revisions] [--strip-comments] [--metadata-only]
7
+ * validate <docx> [--max-errors <n>] [--max-ratio <n>] [--max-uncompressed-bytes <n>] [--style-guide <name|path>]
8
+ * sanitize <in.docx> <out.docx> [--client-safe] [--redact-pii] [--zero-retention] [--replacement-author <name>] [--accept-all-revisions] [--strip-comments] [--metadata-only] [--force]
9
9
  * (bare sanitize = metadata preset: zero-retention + accept-all-revisions + strip-comments + neutral author, body text kept; --redact-pii/--client-safe also redact body PII)
10
- * batch <docx> [<ops.json|->] [--target-text <needle> --append <text>] [--append <text>] [--out <docx>] [--sequential|--no-sequential] [--no-validate] [--schema] [--max-ratio <n>] [--max-uncompressed-bytes <n>] [--dry-run] [--backup[=<path>]] [--matrix <vars.csv>] [--reproducible|--no-reproducible] [--stream [--on-error abort|continue] [--max-errors <n>]] [--style-guide <name|path>]
10
+ * batch <docx> [<ops.json|->] [--target-text <needle> --append <text>] [--append <text>] [--out <docx>] [--sequential|--no-sequential] [--no-validate] [--strict] [--no-history] [--schema] [--max-ratio <n>] [--max-uncompressed-bytes <n>] [--dry-run] [--backup[=<path>]] [--matrix <vars.csv>] [--reproducible|--no-reproducible] [--stream [--on-error abort|continue] [--max-errors <n>]] [--style-guide <name|path>]
11
11
  * (ops path `-` reads ops JSON from stdin; see `batch --help`)
12
12
  * (ops support CLI-level `insert type:heading level:1..3` and `{action:'clearDoc'}`; see `batch --schema`)
13
- * normalize <docx> [--out <docx>] [--dry-run] [--backup[=<path>]] (repair-as-action for legacy files; `validate` stays read-only, no --fix alias)
13
+ * normalize <docx> [--out <docx>] [--dry-run] [--strict] [--no-history] [--backup[=<path>]] (repair-as-action for legacy files; `validate` stays read-only, no --fix alias)
14
14
  * export <docx> [--format html|markdown|md|pdf] [-o <outPath>]
15
15
  * search <docx> <query> [--limit <n>]
16
16
  * create <out.docx> [--template report|memo|blank] [--force] [--from-md <file.md>] [--allowed-dir <dir>] [--dollar-math] [--style-guide <name|path>]
@@ -14,5 +14,11 @@ export interface ExportOptions {
14
14
  imageMode?: 'embed' | 'file';
15
15
  /** Markdown file mode: relative folder for image files (default media). */
16
16
  assetPrefix?: string;
17
+ /** Macro choice for the HTML and Markdown paths (the PDF path never opens the package for editing). */
18
+ macroOpts?: {
19
+ allowMacros: true;
20
+ } | {
21
+ stripMacros: true;
22
+ };
17
23
  }
18
24
  export declare function executeExport(docxPath: string, formatInput?: string, outPath?: string, options?: ExportOptions): Promise<ExportResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attentionform/astra",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Command-line tool for OOXML (.docx) document engineering",
5
5
  "main": "dist/cli.js",
6
6
  "types": "dist/packages/cli/src/cli.d.ts",
@@ -43,8 +43,8 @@
43
43
  "adm-zip-gate": "node ../../scripts/check-adm-zip-imports.mjs"
44
44
  },
45
45
  "dependencies": {
46
- "@attentionform/astra-engine": "^0.1.0",
47
- "@attentionform/ooxml-validator": "^0.1.0",
46
+ "@attentionform/astra-engine": "^0.2.1",
47
+ "@attentionform/ooxml-validator": "^0.2.1",
48
48
  "@xmldom/xmldom": "0.8.15",
49
49
  "adm-zip": "0.6.1",
50
50
  "isomorphic-git": "^1.25.0",