@astudioplus/compressor 0.1.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 (108) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +20 -0
  3. package/README.md +167 -0
  4. package/dist/adapters/agents-md.d.ts +2 -0
  5. package/dist/adapters/agents-md.js +91 -0
  6. package/dist/adapters/apply.d.ts +3 -0
  7. package/dist/adapters/apply.js +83 -0
  8. package/dist/adapters/claude-code.d.ts +2 -0
  9. package/dist/adapters/claude-code.js +403 -0
  10. package/dist/adapters/copilot.d.ts +2 -0
  11. package/dist/adapters/copilot.js +418 -0
  12. package/dist/adapters/cursor.d.ts +2 -0
  13. package/dist/adapters/cursor.js +149 -0
  14. package/dist/adapters/index.d.ts +11 -0
  15. package/dist/adapters/index.js +19 -0
  16. package/dist/adapters/markers.d.ts +7 -0
  17. package/dist/adapters/markers.js +129 -0
  18. package/dist/adapters/types.d.ts +44 -0
  19. package/dist/adapters/types.js +1 -0
  20. package/dist/bench/ablate.d.ts +35 -0
  21. package/dist/bench/ablate.js +163 -0
  22. package/dist/bench/cell.d.ts +33 -0
  23. package/dist/bench/cell.js +437 -0
  24. package/dist/bench/results.d.ts +37 -0
  25. package/dist/bench/results.js +157 -0
  26. package/dist/bench/runner.d.ts +24 -0
  27. package/dist/bench/runner.js +121 -0
  28. package/dist/bench/tasks.d.ts +4 -0
  29. package/dist/bench/tasks.js +147 -0
  30. package/dist/bench/types.d.ts +109 -0
  31. package/dist/bench/types.js +1 -0
  32. package/dist/claude/transcripts.d.ts +30 -0
  33. package/dist/claude/transcripts.js +154 -0
  34. package/dist/cli/commands/benchmark.d.ts +33 -0
  35. package/dist/cli/commands/benchmark.js +203 -0
  36. package/dist/cli/commands/compress.d.ts +8 -0
  37. package/dist/cli/commands/compress.js +45 -0
  38. package/dist/cli/commands/count.d.ts +5 -0
  39. package/dist/cli/commands/count.js +25 -0
  40. package/dist/cli/commands/hook.d.ts +6 -0
  41. package/dist/cli/commands/hook.js +30 -0
  42. package/dist/cli/commands/init.d.ts +16 -0
  43. package/dist/cli/commands/init.js +76 -0
  44. package/dist/cli/commands/report.d.ts +90 -0
  45. package/dist/cli/commands/report.js +464 -0
  46. package/dist/cli/commands/savings.d.ts +38 -0
  47. package/dist/cli/commands/savings.js +196 -0
  48. package/dist/cli/commands/set-mode.d.ts +5 -0
  49. package/dist/cli/commands/set-mode.js +13 -0
  50. package/dist/cli/commands/stats.d.ts +5 -0
  51. package/dist/cli/commands/stats.js +51 -0
  52. package/dist/cli/commands/status.d.ts +1 -0
  53. package/dist/cli/commands/status.js +11 -0
  54. package/dist/cli/commands/uninstall.d.ts +7 -0
  55. package/dist/cli/commands/uninstall.js +22 -0
  56. package/dist/cli/index.d.ts +2 -0
  57. package/dist/cli/index.js +146 -0
  58. package/dist/copilot-hook-entry.d.ts +1 -0
  59. package/dist/copilot-hook-entry.js +36 -0
  60. package/dist/copilot-hook.js +1000 -0
  61. package/dist/engine/detect.d.ts +2 -0
  62. package/dist/engine/detect.js +47 -0
  63. package/dist/engine/index.d.ts +4 -0
  64. package/dist/engine/index.js +90 -0
  65. package/dist/engine/policy.d.ts +2 -0
  66. package/dist/engine/policy.js +48 -0
  67. package/dist/engine/tiers/code.d.ts +7 -0
  68. package/dist/engine/tiers/code.js +206 -0
  69. package/dist/engine/tiers/logs.d.ts +4 -0
  70. package/dist/engine/tiers/logs.js +139 -0
  71. package/dist/engine/tiers/structural.d.ts +28 -0
  72. package/dist/engine/tiers/structural.js +199 -0
  73. package/dist/engine/types.d.ts +71 -0
  74. package/dist/engine/types.js +5 -0
  75. package/dist/hook/copilot.d.ts +5 -0
  76. package/dist/hook/copilot.js +136 -0
  77. package/dist/hook/core.d.ts +36 -0
  78. package/dist/hook/core.js +138 -0
  79. package/dist/hook/exit.d.ts +22 -0
  80. package/dist/hook/exit.js +56 -0
  81. package/dist/hook/post-tool-use.d.ts +5 -0
  82. package/dist/hook/post-tool-use.js +57 -0
  83. package/dist/hook-entry.d.ts +1 -0
  84. package/dist/hook-entry.js +35 -0
  85. package/dist/hook.js +946 -0
  86. package/dist/index.d.ts +15 -0
  87. package/dist/index.js +16 -0
  88. package/dist/ledger/read.d.ts +9 -0
  89. package/dist/ledger/read.js +91 -0
  90. package/dist/ledger/write.d.ts +29 -0
  91. package/dist/ledger/write.js +61 -0
  92. package/dist/packs/atoms.d.ts +3 -0
  93. package/dist/packs/atoms.js +108 -0
  94. package/dist/packs/modes.d.ts +3 -0
  95. package/dist/packs/modes.js +34 -0
  96. package/dist/packs/render.d.ts +24 -0
  97. package/dist/packs/render.js +115 -0
  98. package/dist/packs/types.d.ts +32 -0
  99. package/dist/packs/types.js +1 -0
  100. package/dist/paths.d.ts +29 -0
  101. package/dist/paths.js +87 -0
  102. package/dist/tokens/estimate.d.ts +12 -0
  103. package/dist/tokens/estimate.js +23 -0
  104. package/dist/tokens/exact.d.ts +5 -0
  105. package/dist/tokens/exact.js +16 -0
  106. package/dist/tokens/index.d.ts +2 -0
  107. package/dist/tokens/index.js +2 -0
  108. package/package.json +77 -0
@@ -0,0 +1,5 @@
1
+ import type { MarkerStyle, Mode } from '../engine/types.ts';
2
+ export interface HookResult {
3
+ output: string | null;
4
+ }
5
+ export declare function handlePostToolUse(payloadJson: string, mode: Mode, markerStyle?: MarkerStyle): HookResult;
@@ -0,0 +1,57 @@
1
+ import { compressCall, isRecord, pickLeaf, rebuildWithLeaf, recordCompression } from "./core.js";
2
+ function toolKindFor(toolName) {
3
+ switch (toolName) {
4
+ case 'Read':
5
+ return 'read';
6
+ case 'Bash':
7
+ return 'bash';
8
+ case 'Grep':
9
+ case 'Glob':
10
+ return 'search';
11
+ default:
12
+ return 'other';
13
+ }
14
+ }
15
+ export function handlePostToolUse(payloadJson, mode, markerStyle) {
16
+ try {
17
+ if (mode === 'full') {
18
+ return { output: null };
19
+ }
20
+ const payload = JSON.parse(payloadJson);
21
+ if (!isRecord(payload)) {
22
+ return { output: null };
23
+ }
24
+ const toolName = typeof payload['tool_name'] === 'string' ? payload['tool_name'] : '';
25
+ const toolInput = isRecord(payload['tool_input']) ? payload['tool_input'] : {};
26
+ const tool = toolKindFor(toolName);
27
+ const leaf = pickLeaf(payload['tool_response'], tool);
28
+ if (leaf === null) {
29
+ return { output: null };
30
+ }
31
+ const call = {
32
+ toolKind: tool,
33
+ targeted: tool === 'read' && (toolInput['offset'] != null || toolInput['limit'] != null),
34
+ text: leaf.text,
35
+ };
36
+ if (tool === 'read' && typeof toolInput['file_path'] === 'string') {
37
+ call.filePath = toolInput['file_path'];
38
+ }
39
+ const compressed = compressCall(call, mode, markerStyle);
40
+ if (!compressed.worthwhile) {
41
+ return { output: null };
42
+ }
43
+ recordCompression('claude-code', call, compressed, mode);
44
+ const updatedToolOutput = rebuildWithLeaf(payload['tool_response'], leaf.path, compressed.text);
45
+ return {
46
+ output: JSON.stringify({
47
+ hookSpecificOutput: {
48
+ hookEventName: 'PostToolUse',
49
+ updatedToolOutput,
50
+ },
51
+ }),
52
+ };
53
+ }
54
+ catch {
55
+ return { output: null };
56
+ }
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import process from 'node:process';
2
+ import { settleThenExit } from "./hook/exit.js";
3
+ import { handlePostToolUse } from "./hook/post-tool-use.js";
4
+ // PostToolUse hook entry, bundled to dist/hook.js. Fail-open: any failure
5
+ // means emit nothing and exit 0 so the original tool output passes through.
6
+ function parseMode(argv) {
7
+ const idx = argv.indexOf('--mode');
8
+ const value = idx === -1 ? undefined : argv[idx + 1];
9
+ return value === 'full' || value === 'optimized' || value === 'slim' ? value : 'optimized';
10
+ }
11
+ /** Fail-open: unknown or missing style falls back to the policy default. */
12
+ function parseMarkerStyle(argv) {
13
+ const idx = argv.indexOf('--marker-style');
14
+ const value = idx === -1 ? undefined : argv[idx + 1];
15
+ return value === 'plain' || value === 'deterrent' || value === 'informative'
16
+ ? value
17
+ : undefined;
18
+ }
19
+ async function main() {
20
+ const chunks = [];
21
+ for await (const chunk of process.stdin) {
22
+ chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
23
+ }
24
+ const payload = Buffer.concat(chunks).toString('utf8');
25
+ return handlePostToolUse(payload, parseMode(process.argv), parseMarkerStyle(process.argv))
26
+ .output;
27
+ }
28
+ // Exit path shared with the copilot entry and the CLI subcommands
29
+ // (src/hook/exit.ts): stdout first, ledger settle capped at 250ms, SIGKILL
30
+ // on timeout so a stuck filesystem can never hang the agent.
31
+ main().then((output) => {
32
+ settleThenExit(output).catch(() => process.exit(0));
33
+ }, () => {
34
+ settleThenExit(null).catch(() => process.exit(0));
35
+ });