@attentionform/astra 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.
Files changed (32) hide show
  1. package/LICENSE +206 -0
  2. package/NOTICE +12 -0
  3. package/README.md +211 -2
  4. package/dist/cli.js +43821 -0
  5. package/dist/packages/cli/src/cli/baseline-gate.d.ts +25 -0
  6. package/dist/packages/cli/src/cli/batch-cmd.d.ts +177 -0
  7. package/dist/packages/cli/src/cli/create-cmd.d.ts +10 -0
  8. package/dist/packages/cli/src/cli/errors.d.ts +86 -0
  9. package/dist/packages/cli/src/cli/export-cmd.d.ts +2 -0
  10. package/dist/packages/cli/src/cli/history-cmd.d.ts +5 -0
  11. package/dist/packages/cli/src/cli/history-support.d.ts +38 -0
  12. package/dist/packages/cli/src/cli/import-cmd.d.ts +2 -0
  13. package/dist/packages/cli/src/cli/inspect-cmd.d.ts +3 -0
  14. package/dist/packages/cli/src/cli/io.d.ts +70 -0
  15. package/dist/packages/cli/src/cli/normalize-cmd.d.ts +9 -0
  16. package/dist/packages/cli/src/cli/output.d.ts +98 -0
  17. package/dist/packages/cli/src/cli/run.d.ts +6 -0
  18. package/dist/packages/cli/src/cli/sanitize-cmd.d.ts +26 -0
  19. package/dist/packages/cli/src/cli/search-cmd.d.ts +2 -0
  20. package/dist/packages/cli/src/cli/stats-cmd.d.ts +2 -0
  21. package/dist/packages/cli/src/cli/usage.d.ts +8 -0
  22. package/dist/packages/cli/src/cli/validate-cmd.d.ts +2 -0
  23. package/dist/packages/cli/src/cli/visual-cmd.d.ts +34 -0
  24. package/dist/packages/cli/src/cli.d.ts +44 -0
  25. package/dist/packages/cli/src/export.d.ts +24 -0
  26. package/dist/packages/ooxml-validator/src/index.d.ts +33 -0
  27. package/dist/packages/ooxml-validator/src/one-shot.d.ts +2 -0
  28. package/dist/packages/ooxml-validator/src/protocol.d.ts +30 -0
  29. package/dist/packages/ooxml-validator/src/resolve-binary.d.ts +5 -0
  30. package/dist/packages/ooxml-validator/src/types.d.ts +65 -0
  31. package/dist/packages/ooxml-validator/src/worker-client.d.ts +38 -0
  32. package/package.json +70 -4
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @attentionform/astra — Track-B command line (`astra` bin).
4
+ *
5
+ * Commands (all fail-closed — any operational failure exits non-zero):
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-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
+ * (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] [--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
+ * (ops path `-` reads ops JSON from stdin; see `batch --help`)
12
+ * (ops support CLI-level `insert type:heading level:1..3` and `{action:'clearDoc'}`; see `batch --schema`)
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
+ * export <docx> [--format html|markdown|md|pdf] [-o <outPath>]
15
+ * search <docx> <query> [--limit <n>]
16
+ * create <out.docx> [--template report|memo|blank] [--force] [--from-md <file.md>] [--allowed-dir <dir>] [--dollar-math] [--style-guide <name|path>]
17
+ * import <file.md> [-o <out.docx>] [--template report|memo|blank] [--force] [--allowed-dir <dir>] [--dollar-math]
18
+ * stats <docx>
19
+ *
20
+ * Exit codes: 0 ok · 1 operational failure (invalid docx, bad ops, batch
21
+ * failure/rollback, failed validation — never writes corruption) · 2 usage.
22
+ *
23
+ * Engine wiring:
24
+ * imports resolve to the `@attentionform/astra-engine` package.
25
+ * CLI command names, flags and exit-code contract stay identical
26
+ * across refactors (scripts pin them).
27
+ */
28
+ export * from './cli/output';
29
+ export * from './cli/errors';
30
+ export * from './cli/usage';
31
+ export * from './cli/io';
32
+ export * from './cli/inspect-cmd';
33
+ export * from './cli/validate-cmd';
34
+ export * from './cli/sanitize-cmd';
35
+ export * from './cli/batch-cmd';
36
+ export * from './cli/normalize-cmd';
37
+ export * from './cli/export-cmd';
38
+ export * from './cli/search-cmd';
39
+ export * from './cli/create-cmd';
40
+ export * from './cli/import-cmd';
41
+ export * from './cli/stats-cmd';
42
+ export * from './cli/visual-cmd';
43
+ export * from './cli/history-cmd';
44
+ export * from './cli/run';
@@ -0,0 +1,24 @@
1
+ export interface ExportResult {
2
+ ok: boolean;
3
+ path: string;
4
+ format: 'html' | 'markdown' | 'pdf';
5
+ bytes: number;
6
+ assets?: string[];
7
+ }
8
+ export interface ExportOptions {
9
+ /** Render untagged PDF (default false = tagged render). */
10
+ untagged?: boolean;
11
+ /** Fail closed on preflight blockers (default false = warn-only). */
12
+ strict?: boolean;
13
+ /** Markdown only: embed data URLs (default) or write folder references. */
14
+ imageMode?: 'embed' | 'file';
15
+ /** Markdown file mode: relative folder for image files (default media). */
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
+ };
23
+ }
24
+ export declare function executeExport(docxPath: string, formatInput?: string, outPath?: string, options?: ExportOptions): Promise<ExportResult>;
@@ -0,0 +1,33 @@
1
+ export { resolveEmbeddedBinary, resolveBinaryDetails } from './resolve-binary.js';
2
+ import { OFFICE_VERSIONS, type OfficeVersion, type ValidateOptions, type ValidationError, type ValidationResult, type ValidatorPoolOptions, type BackendInfo, type ValidatorInstance, type ErrorNode, type ValidationErrorClass } from './types.js';
3
+ export { OFFICE_VERSIONS };
4
+ export type { OfficeVersion, ValidateOptions, ValidationError, ValidationResult, ValidatorPoolOptions, BackendInfo, ValidatorInstance, ErrorNode, ValidationErrorClass, };
5
+ /**
6
+ * Validates a single OOXML file from disk.
7
+ * Defaults to 'Microsoft365' to match standard ECMA-376 / ISO-29500 behavior.
8
+ */
9
+ export declare function validateFile(filePath: string, options?: ValidateOptions): Promise<ValidationResult>;
10
+ /**
11
+ * Convenience helper returning a boolean indicating if the document is valid.
12
+ */
13
+ export declare function isValid(filePath: string, options?: ValidateOptions): Promise<boolean>;
14
+ /**
15
+ * Validates an in-memory DOCX buffer without creating temporary files.
16
+ * Defaults to 'Office2019' matching the ASTra engine's standard validation target.
17
+ */
18
+ export declare function validateBuffer(bytes: Buffer | Uint8Array, options?: ValidateOptions): Promise<ValidationResult>;
19
+ /**
20
+ * Creates an isolated validator worker client instance.
21
+ */
22
+ export declare function createValidator(opts?: ValidatorPoolOptions): ValidatorInstance;
23
+ /**
24
+ * Returns diagnostic metadata about the resolved binary and platform package.
25
+ */
26
+ export declare function backendInfo(): Promise<BackendInfo>;
27
+ /**
28
+ * Runs a self-diagnostic validating an embedded known-good and known-bad document.
29
+ */
30
+ export declare function selfTest(): Promise<{
31
+ ok: boolean;
32
+ details: string;
33
+ }>;
@@ -0,0 +1,2 @@
1
+ import { type ValidateOptions, type ValidationResult } from './types.js';
2
+ export declare function runValidatorOneShot(file: string, options?: ValidateOptions): Promise<ValidationResult>;
@@ -0,0 +1,30 @@
1
+ import type { OfficeVersion, ValidationError } from './types.js';
2
+ export interface WorkerRequestHeader {
3
+ id: number;
4
+ op?: 'validate' | 'ping' | 'version' | 'shutdown' | string;
5
+ kind?: 'docx' | 'pptx' | 'xlsx' | string;
6
+ office?: OfficeVersion | string;
7
+ size?: number;
8
+ maxErrors?: number;
9
+ maxDocBytes?: number;
10
+ }
11
+ export interface WorkerResponse {
12
+ id: number | null;
13
+ ok: boolean;
14
+ pong?: boolean;
15
+ sdkVersion?: string;
16
+ office?: string;
17
+ durationMs?: number;
18
+ errorCount?: number;
19
+ truncated?: boolean;
20
+ fatal?: boolean;
21
+ error?: string;
22
+ errors?: ValidationError[];
23
+ }
24
+ export declare function encodeRequest(header: WorkerRequestHeader, bytes?: Uint8Array | Buffer): Buffer;
25
+ export declare class JsonLineDecoder {
26
+ private decoder;
27
+ private buffer;
28
+ push(chunk: Buffer | Uint8Array): WorkerResponse[];
29
+ end(): WorkerResponse[];
30
+ }
@@ -0,0 +1,5 @@
1
+ export declare function resolveBinaryDetails(): {
2
+ binaryPath: string;
3
+ platformPackage: string;
4
+ };
5
+ export declare function resolveEmbeddedBinary(): string;
@@ -0,0 +1,65 @@
1
+ export declare const OFFICE_VERSIONS: readonly ["Office2007", "Office2010", "Office2013", "Office2016", "Office2019", "Office2021", "Microsoft365"];
2
+ export type OfficeVersion = (typeof OFFICE_VERSIONS)[number];
3
+ export interface ErrorNode {
4
+ localName?: string | null;
5
+ namespaceUri?: string | null;
6
+ }
7
+ export type ValidationErrorClass = 'schema' | 'semantic' | 'markup-compat' | 'package' | 'exception' | string;
8
+ export interface ValidationError {
9
+ /** Human-readable description of the problem. */
10
+ description?: string | null;
11
+ /** Package part the error was found in, e.g. `/word/document.xml`. `null` for `errorType: 'Exception'`. */
12
+ path?: string | null;
13
+ /** XPath of the offending element. `null` for `errorType: 'Exception'`. */
14
+ xPath?: string | null;
15
+ /** Open XML SDK error id, e.g. `Sch_UnexpectedElementContentExpectingComplex`. `null` for `errorType: 'Exception'`. */
16
+ id?: string | null;
17
+ /** `Schema`, `Semantic`, `Package`, `MarkupCompatibility`, or `Exception` when the file could not be opened at all. */
18
+ errorType?: string | null;
19
+ /** Part URI string (e.g. `/word/document.xml`). */
20
+ part?: string | null;
21
+ /** Error classification: 'schema' | 'semantic' | 'markup-compat' | 'package' | 'exception'. */
22
+ class?: ValidationErrorClass | null;
23
+ /** Offending XML element information when present. */
24
+ node?: ErrorNode | null;
25
+ /** Related XML element information when present. */
26
+ relatedNode?: ErrorNode | null;
27
+ [key: string]: unknown;
28
+ }
29
+ export interface ValidationResult {
30
+ file: string;
31
+ ok: boolean;
32
+ errors: ValidationError[];
33
+ sdkVersion?: string;
34
+ office?: string;
35
+ durationMs?: number;
36
+ truncated?: boolean;
37
+ errorCount?: number;
38
+ [key: string]: unknown;
39
+ }
40
+ export interface ValidateOptions {
41
+ /** Open XML schema version to validate against. Defaults to `Microsoft365` for one-shot, `Office2019` for buffer. */
42
+ officeVersion?: OfficeVersion;
43
+ maxErrors?: number;
44
+ timeoutMs?: number;
45
+ maxDocBytes?: number;
46
+ }
47
+ export interface ValidatorPoolOptions {
48
+ workers?: number;
49
+ recycleAfter?: number;
50
+ timeoutMs?: number;
51
+ maxDocBytes?: number;
52
+ maxErrors?: number;
53
+ }
54
+ export interface BackendInfo {
55
+ platformPackage: string;
56
+ binaryPath: string;
57
+ sdkVersion: string;
58
+ binarySha256: string;
59
+ workerSupported: boolean;
60
+ }
61
+ export interface ValidatorInstance {
62
+ validate(bytes: Buffer | Uint8Array, opts?: ValidateOptions): Promise<ValidationResult>;
63
+ validateFile(path: string, opts?: ValidateOptions): Promise<ValidationResult>;
64
+ close(): Promise<void>;
65
+ }
@@ -0,0 +1,38 @@
1
+ import { type WorkerRequestHeader, type WorkerResponse } from './protocol.js';
2
+ import type { ValidatorPoolOptions } from './types.js';
3
+ export declare class WorkerClient {
4
+ private binaryPath;
5
+ private recycleAfter;
6
+ private timeoutMs;
7
+ private maxDocBytes;
8
+ private maxErrors;
9
+ private child;
10
+ private liveChildren;
11
+ private queue;
12
+ private current;
13
+ private nextId;
14
+ private requestsHandled;
15
+ private closed;
16
+ private _spawnCount;
17
+ private _spawnedPids;
18
+ constructor(opts?: ValidatorPoolOptions & {
19
+ binaryPath?: string;
20
+ });
21
+ get pid(): number | undefined;
22
+ get spawnCount(): number;
23
+ get spawnedPids(): number[];
24
+ private ensureWorker;
25
+ private refChild;
26
+ private unrefChild;
27
+ send(header: Omit<WorkerRequestHeader, 'id'>, bytes?: Uint8Array | Buffer, overrideTimeoutMs?: number): Promise<WorkerResponse>;
28
+ private processQueue;
29
+ private handleResponse;
30
+ private handleTimeout;
31
+ private handleWriteError;
32
+ private handleProcessError;
33
+ private handleProcessExit;
34
+ private retryOrReject;
35
+ private recycleWorker;
36
+ private killWorker;
37
+ close(): Promise<void>;
38
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@attentionform/astra",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Command-line tool for OOXML (.docx) document engineering",
5
+ "main": "dist/cli.js",
6
+ "types": "dist/packages/cli/src/cli.d.ts",
7
+ "bin": {
8
+ "astra": "./dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE",
14
+ "NOTICE",
15
+ "!dist/packages/engine",
16
+ "!dist/**/*.map"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "license": "BUSL-1.1",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Attentionform/astra.git",
25
+ "directory": "packages/cli"
26
+ },
27
+ "keywords": [
28
+ "cli",
29
+ "astra",
30
+ "ooxml",
31
+ "docx",
32
+ "word",
33
+ "terminal",
34
+ "document",
35
+ "automation"
36
+ ],
37
+ "type": "commonjs",
38
+ "scripts": {
39
+ "build": "node ../../scripts/check-adm-zip-imports.mjs && tsc --noEmit -p tsconfig.json && esbuild src/cli.ts --bundle --packages=external --platform=node --target=node22 --format=cjs --outfile=dist/cli.js --log-level=warning && tsc -p tsconfig.dts.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
40
+ "typecheck": "tsc --noEmit -p tsconfig.json",
41
+ "test": "vitest run",
42
+ "start": "node dist/cli.js",
43
+ "adm-zip-gate": "node ../../scripts/check-adm-zip-imports.mjs"
44
+ },
45
+ "dependencies": {
46
+ "@attentionform/astra-engine": "^0.2.0",
47
+ "@attentionform/ooxml-validator": "^0.2.0",
48
+ "@xmldom/xmldom": "0.8.15",
49
+ "adm-zip": "0.6.1",
50
+ "isomorphic-git": "^1.25.0",
51
+ "marked": "18.0.5",
52
+ "p-limit": "^3.1.0",
53
+ "zod": "4.6.7"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^25.9.1",
57
+ "esbuild": "^0.25.12",
58
+ "typescript": "^5.2.2",
59
+ "vitest": "^4.1.7"
60
+ },
61
+ "engines": {
62
+ "node": ">=22.19.0"
63
+ },
64
+ "homepage": "https://attentionform.com",
65
+ "bugs": {
66
+ "url": "https://github.com/Attentionform/astra/issues"
67
+ },
68
+ "author": {
69
+ "name": "Attentionform",
70
+ "url": "https://attentionform.com"
71
+ }
72
+ }