@trazum/cli 2.5.1 → 2.6.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 (83) hide show
  1. package/README.md +75 -6
  2. package/dist/filter.d.ts +2 -0
  3. package/dist/filter.d.ts.map +1 -0
  4. package/dist/filter.js +187 -0
  5. package/dist/filter.js.map +1 -0
  6. package/dist/gateway-server.d.ts +2 -0
  7. package/dist/gateway-server.d.ts.map +1 -1
  8. package/dist/gateway-server.js +49 -9
  9. package/dist/gateway-server.js.map +1 -1
  10. package/dist/gateway-spend.d.ts +32 -0
  11. package/dist/gateway-spend.d.ts.map +1 -0
  12. package/dist/gateway-spend.js +116 -0
  13. package/dist/gateway-spend.js.map +1 -0
  14. package/dist/html.d.ts.map +1 -1
  15. package/dist/html.js +22 -1
  16. package/dist/html.js.map +1 -1
  17. package/dist/i18n/en.d.ts.map +1 -1
  18. package/dist/i18n/en.js +45 -3
  19. package/dist/i18n/en.js.map +1 -1
  20. package/dist/i18n/es.d.ts.map +1 -1
  21. package/dist/i18n/es.js +45 -3
  22. package/dist/i18n/es.js.map +1 -1
  23. package/dist/i18n/types.d.ts +13 -1
  24. package/dist/i18n/types.d.ts.map +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +125 -61
  27. package/dist/index.js.map +1 -1
  28. package/dist/markdown.d.ts.map +1 -1
  29. package/dist/markdown.js +19 -1
  30. package/dist/markdown.js.map +1 -1
  31. package/dist/pdf.d.ts.map +1 -1
  32. package/dist/pdf.js +38 -1
  33. package/dist/pdf.js.map +1 -1
  34. package/dist/serve-import-schema.d.ts +34 -0
  35. package/dist/serve-import-schema.d.ts.map +1 -0
  36. package/dist/serve-import-schema.js +31 -0
  37. package/dist/serve-import-schema.js.map +1 -0
  38. package/dist/serve-import.d.ts +43 -0
  39. package/dist/serve-import.d.ts.map +1 -0
  40. package/dist/serve-import.js +49 -0
  41. package/dist/serve-import.js.map +1 -0
  42. package/dist/serve-savings-schema.d.ts +65 -0
  43. package/dist/serve-savings-schema.d.ts.map +1 -0
  44. package/dist/serve-savings-schema.js +54 -0
  45. package/dist/serve-savings-schema.js.map +1 -0
  46. package/dist/serve-savings.d.ts +55 -0
  47. package/dist/serve-savings.d.ts.map +1 -0
  48. package/dist/serve-savings.js +144 -0
  49. package/dist/serve-savings.js.map +1 -0
  50. package/dist/serve-schema.d.ts +606 -0
  51. package/dist/serve-schema.d.ts.map +1 -0
  52. package/dist/serve-schema.js +151 -0
  53. package/dist/serve-schema.js.map +1 -0
  54. package/dist/serve.d.ts.map +1 -1
  55. package/dist/serve.js +37 -5
  56. package/dist/serve.js.map +1 -1
  57. package/dist/task-files.d.ts +9 -0
  58. package/dist/task-files.d.ts.map +1 -0
  59. package/dist/task-files.js +136 -0
  60. package/dist/task-files.js.map +1 -0
  61. package/dist/task.d.ts +2 -0
  62. package/dist/task.d.ts.map +1 -0
  63. package/dist/task.js +137 -0
  64. package/dist/task.js.map +1 -0
  65. package/package.json +2 -2
  66. package/src/filter.ts +150 -0
  67. package/src/gateway-server.ts +46 -10
  68. package/src/gateway-spend.ts +120 -0
  69. package/src/html.ts +25 -1
  70. package/src/i18n/en.ts +47 -4
  71. package/src/i18n/es.ts +47 -4
  72. package/src/i18n/types.ts +14 -1
  73. package/src/index.ts +115 -63
  74. package/src/markdown.ts +20 -1
  75. package/src/pdf.ts +36 -1
  76. package/src/serve-import-schema.ts +31 -0
  77. package/src/serve-import.ts +57 -0
  78. package/src/serve-savings-schema.ts +53 -0
  79. package/src/serve-savings.ts +140 -0
  80. package/src/serve-schema.ts +155 -0
  81. package/src/serve.ts +38 -5
  82. package/src/task-files.ts +114 -0
  83. package/src/task.ts +119 -0
package/src/task.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { analyzeTask, compareTasks, parseTaskReport, taskPolicy, MAX_INPUT_CHARS } from '@trazum/core';
2
+ import { changeTaskInstructions, readTaskText, writeTaskText } from './task-files.js';
3
+
4
+ const HELP = `Usage:
5
+ trazum task analyze --id <id> --type <type> --criterion <text>
6
+ --claude-code <file> [--codex <file>] [--claude-code <file> ...]
7
+ [--outcome accepted|rejected|unknown --assessor <label>]
8
+ [--policy baseline|repeat-review-v1] [-o <new-report.json>]
9
+ trazum task policy <report.json> [-o <new-policy.md>]
10
+ trazum task apply <report.json> --instructions <existing-file>
11
+ trazum task revert --instructions <existing-file>
12
+ trazum task compare <before.json> <after.json> [-o <new-comparison.json>]
13
+
14
+ Analyze explicit, complete task sources from Claude Code and Codex locally.
15
+ Repeat the source flags to include sessions from both harnesses. No home scan,
16
+ network access, provider call, hook installation or command execution occurs.
17
+ Up to 16 sources and ${MAX_INPUT_CHARS} characters combined. Do not split one
18
+ session across sources or import the same session more than once.
19
+ Reports and comparisons are JSON by default (--json is also accepted).
20
+ Outcome and assessor are caller declarations, never inferred from usage.
21
+ Policy application adds a small, optional managed block to the file you choose.
22
+ Review the diff and run a comparable task yourself before comparing reports.
23
+ Revert removes only the exact unchanged block. Close other editors while applying
24
+ or reverting. Existing output reports are never overwritten; new files use 0600.
25
+ Repeated tool results may be intentional. A paired comparison is an observation,
26
+ not proof of causal savings, task quality or remaining subscription allowance.
27
+ `;
28
+
29
+ type Parsed = { flags: Map<string, string>; paths: string[]; sources: { format: 'claude-code' | 'codex'; path: string }[] };
30
+ const ALLOWED: Record<string, readonly string[]> = {
31
+ analyze: ['id', 'type', 'criterion', 'outcome', 'assessor', 'policy', 'claude-code', 'codex', 'out', 'json'],
32
+ policy: ['out'],
33
+ apply: ['instructions'],
34
+ revert: ['instructions'],
35
+ compare: ['out', 'json'],
36
+ };
37
+
38
+ function parse(action: string, args: string[]): Parsed {
39
+ const allowed = ALLOWED[action];
40
+ if (!allowed) throw new Error('Unknown task action. Run trazum task --help.');
41
+ const flags = new Map<string, string>();
42
+ const sources: Parsed['sources'] = [];
43
+ const paths: string[] = [];
44
+ for (let index = 0; index < args.length; index++) {
45
+ const arg = args[index]!;
46
+ if (!arg.startsWith('-')) { paths.push(arg); continue; }
47
+ const name = arg === '-o' ? 'out' : arg.startsWith('--') ? arg.slice(2) : '';
48
+ if (!allowed.includes(name)) throw new Error('Unsupported task option. Run trazum task --help.');
49
+ if (flags.has(name)) throw new Error('Task options cannot be repeated except source flags.');
50
+ if (name === 'json') { flags.set(name, 'true'); continue; }
51
+ const value = args[++index];
52
+ if (value === undefined || value.trim() === '' || value.startsWith('-')) throw new Error('A task option is missing its value.');
53
+ if (name === 'claude-code' || name === 'codex') {
54
+ sources.push({ format: name, path: value });
55
+ if (sources.length > 16) throw new Error('At most 16 task sources are accepted.');
56
+ } else flags.set(name, value);
57
+ }
58
+ return { flags, sources, paths };
59
+ }
60
+
61
+ function required(flags: Map<string, string>, name: string): string {
62
+ const value = flags.get(name);
63
+ if (value === undefined) throw new Error(`Missing --${name}. Run trazum task --help.`);
64
+ return value;
65
+ }
66
+
67
+ async function emit(value: string | object, output?: string): Promise<void> {
68
+ let text = `${typeof value === 'string' ? value : JSON.stringify(value, null, 2)}\n`;
69
+ if (text.length > MAX_INPUT_CHARS && typeof value !== 'string') text = `${JSON.stringify(value)}\n`;
70
+ if (text.length > MAX_INPUT_CHARS) throw new Error('Task output exceeds the report limit; use a smaller complete task source.');
71
+ if (output !== undefined) await writeTaskText(output, text);
72
+ else process.stdout.write(text);
73
+ }
74
+
75
+ export async function runTask(args: string[]): Promise<void> {
76
+ if (args.length === 0 || (args.length === 1 && ['--help', '-h'].includes(args[0]!)) ||
77
+ (args.length === 2 && Object.hasOwn(ALLOWED, args[0]!) && ['--help', '-h'].includes(args[1]!))) {
78
+ process.stdout.write(HELP);
79
+ return;
80
+ }
81
+ const action = args[0]!;
82
+ const { flags, sources, paths } = parse(action, args.slice(1));
83
+ const expectedPaths = action === 'compare' ? 2 : action === 'policy' || action === 'apply' ? 1 : 0;
84
+ if (paths.length !== expectedPaths) throw new Error('Wrong number of task input files. Run trazum task --help.');
85
+ if (action === 'analyze') {
86
+ const taskId = required(flags, 'id');
87
+ const taskType = required(flags, 'type');
88
+ const criterion = required(flags, 'criterion');
89
+ if (sources.length === 0) throw new Error('Provide at least one --claude-code or --codex file.');
90
+ const contents: { format: 'claude-code' | 'codex'; text: string }[] = [];
91
+ let total = 0;
92
+ for (const source of sources) {
93
+ const text = await readTaskText(source.path, MAX_INPUT_CHARS - total);
94
+ total += text.length;
95
+ contents.push({ format: source.format, text });
96
+ }
97
+ const report = analyzeTask({ taskId, taskType, criterion, sources: contents,
98
+ ...(flags.has('outcome') ? { outcome: flags.get('outcome') } : {}),
99
+ ...(flags.has('assessor') ? { assessor: flags.get('assessor') } : {}),
100
+ ...(flags.has('policy') ? { policyId: flags.get('policy') } : {}),
101
+ });
102
+ await emit(report, flags.get('out'));
103
+ } else if (action === 'compare') {
104
+ const before = parseTaskReport(await readTaskText(paths[0]!));
105
+ const after = parseTaskReport(await readTaskText(paths[1]!));
106
+ await emit(compareTasks(before, after), flags.get('out'));
107
+ } else if (action === 'policy' || action === 'apply') {
108
+ const report = parseTaskReport(await readTaskText(paths[0]!));
109
+ const policy = taskPolicy(report);
110
+ if (action === 'policy') await emit(policy.instructions, flags.get('out'));
111
+ else {
112
+ const changed = await changeTaskInstructions(required(flags, 'instructions'), 'apply');
113
+ await emit({ version: 1, kind: 'trazum-task-policy', policyId: policy.id, applied: true, changed });
114
+ }
115
+ } else if (action === 'revert') {
116
+ const changed = await changeTaskInstructions(required(flags, 'instructions'), 'revert');
117
+ await emit({ version: 1, kind: 'trazum-task-policy', policyId: 'repeat-review-v1', applied: false, changed });
118
+ }
119
+ }