@the-forge-flow/ultra-compress-pi 0.1.1 → 0.1.2
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.
- package/dist/commands/types.d.ts +2 -4
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/uc-file.d.ts +2 -2
- package/dist/commands/uc-file.d.ts.map +1 -1
- package/dist/commands/uc-file.js +80 -63
- package/dist/commands/uc-file.js.map +1 -1
- package/dist/commands/uc-revert.d.ts +4 -1
- package/dist/commands/uc-revert.d.ts.map +1 -1
- package/dist/commands/uc-revert.js +15 -1
- package/dist/commands/uc-revert.js.map +1 -1
- package/dist/commands/uc.d.ts.map +1 -1
- package/dist/commands/uc.js +4 -0
- package/dist/commands/uc.js.map +1 -1
- package/dist/index.d.ts +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -33
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +0 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/path-complete.d.ts +3 -0
- package/dist/services/path-complete.d.ts.map +1 -0
- package/dist/services/path-complete.js +56 -0
- package/dist/services/path-complete.js.map +1 -0
- package/dist/types.d.ts +0 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -14
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/services/compress-pipeline.d.ts +0 -12
- package/dist/services/compress-pipeline.d.ts.map +0 -1
- package/dist/services/compress-pipeline.js +0 -81
- package/dist/services/compress-pipeline.js.map +0 -1
- package/dist/services/llm-factory.d.ts +0 -15
- package/dist/services/llm-factory.d.ts.map +0 -1
- package/dist/services/llm-factory.js +0 -24
- package/dist/services/llm-factory.js.map +0 -1
package/dist/commands/types.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
label: string;
|
|
4
|
-
}
|
|
1
|
+
import type { AutocompleteItem } from "@mariozechner/pi-tui";
|
|
2
|
+
export type { AutocompleteItem };
|
|
5
3
|
export interface CommandUI {
|
|
6
4
|
notify(message: string, level?: "info" | "warning" | "error"): void;
|
|
7
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC,MAAM,WAAW,SAAS;IACzB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,IAAI,CAAC;CACpE;AAED,MAAM,WAAW,cAAc;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,SAAS,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,sBAAsB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE,GAAG,IAAI,CAAC;CACnE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CommandDefinition } from "./types";
|
|
2
2
|
export interface UcFileDeps {
|
|
3
|
-
|
|
3
|
+
sendUserMessage: (prompt: string) => void;
|
|
4
4
|
cwd?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function createUcFileCommand(deps: UcFileDeps): CommandDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uc-file.d.ts","sourceRoot":"","sources":["../../src/commands/uc-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uc-file.d.ts","sourceRoot":"","sources":["../../src/commands/uc-file.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnE,MAAM,WAAW,UAAU;IAE1B,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAkDD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB,CA2FvE"}
|
package/dist/commands/uc-file.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { basename
|
|
3
|
-
import {
|
|
4
|
-
import { extOf, isSupportedExtension
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { backupPathFor } from "../services/backup-path";
|
|
4
|
+
import { extOf, isSupportedExtension } from "../services/file-ops";
|
|
5
|
+
import { buildLevelPromptFragment } from "../services/level-prompts";
|
|
6
|
+
import { completePath } from "../services/path-complete";
|
|
7
|
+
import { safeResolveInCwd } from "../services/path-guard";
|
|
8
|
+
import { ACTIVE_LEVELS, BackupExistsError, InvalidLevelError, UnsupportedFileTypeError, } from "../types";
|
|
8
9
|
function isActiveLevel(s) {
|
|
9
10
|
return ACTIVE_LEVELS.includes(s);
|
|
10
11
|
}
|
|
11
12
|
function parseArgs(args) {
|
|
12
|
-
const parts = args
|
|
13
|
+
const parts = args
|
|
14
|
+
.trim()
|
|
15
|
+
.split(/\s+/)
|
|
16
|
+
.filter((p) => p.length > 0);
|
|
13
17
|
const yes = parts.includes("--yes");
|
|
14
18
|
const filtered = parts.filter((p) => p !== "--yes");
|
|
15
19
|
return {
|
|
@@ -18,32 +22,62 @@ function parseArgs(args) {
|
|
|
18
22
|
yes,
|
|
19
23
|
};
|
|
20
24
|
}
|
|
25
|
+
function buildPreviewPrompt(absPath, level) {
|
|
26
|
+
const rules = buildLevelPromptFragment(level, "file");
|
|
27
|
+
return `I want a PREVIEW of compressing \`${absPath}\` to level \`${level}\` — do not write anything yet.
|
|
28
|
+
|
|
29
|
+
${rules}
|
|
30
|
+
|
|
31
|
+
Steps:
|
|
32
|
+
1. Read the file at \`${absPath}\`.
|
|
33
|
+
2. Apply the level-${level} rules above to its contents.
|
|
34
|
+
3. Show me the compressed version inside a fenced code block.
|
|
35
|
+
4. Report the character count: before → after, percentage saved.
|
|
36
|
+
5. Do NOT edit or write the file. If I approve, I'll re-run with \`--yes\` to write.`;
|
|
37
|
+
}
|
|
38
|
+
function buildWritePrompt(absPath, level, backupPath) {
|
|
39
|
+
const rules = buildLevelPromptFragment(level, "file");
|
|
40
|
+
return `Compress \`${absPath}\` to level \`${level}\` and write the result.
|
|
41
|
+
|
|
42
|
+
${rules}
|
|
43
|
+
|
|
44
|
+
Steps (do in this order):
|
|
45
|
+
1. Read the file at \`${absPath}\`.
|
|
46
|
+
2. Copy the original to \`${backupPath}\` first via Bash: \`cp "${absPath}" "${backupPath}"\`.
|
|
47
|
+
3. Apply the level-${level} rules above to produce the compressed content.
|
|
48
|
+
4. Write the compressed content to \`${absPath}\` via Edit/Write (replacing the original).
|
|
49
|
+
5. Confirm backup exists and report: character count before → after, percentage saved.
|
|
50
|
+
|
|
51
|
+
Do NOT wrap the compressed output in a markdown code fence in the written file. Write the bare compressed body.`;
|
|
52
|
+
}
|
|
21
53
|
export function createUcFileCommand(deps) {
|
|
22
54
|
return {
|
|
23
55
|
name: "uc-file",
|
|
24
|
-
description: "Compress a markdown file to a given level (preview
|
|
56
|
+
description: "Compress a markdown file to a given level (preview by default, --yes writes with backup). Delegates to the agent.",
|
|
57
|
+
// PI replaces the ENTIRE args prefix with the selected value. So every
|
|
58
|
+
// AutocompleteItem.value must be the full reconstructed args string up to
|
|
59
|
+
// and including the completion.
|
|
25
60
|
getArgumentCompletions(prefix) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
const trimmed = prefix ?? "";
|
|
62
|
+
const parts = trimmed.split(/\s+/);
|
|
63
|
+
const endsWithSpace = /\s$/.test(trimmed);
|
|
64
|
+
// Position 2: completing the level. Path already typed (parts[0]).
|
|
65
|
+
if (parts.length >= 2 || (parts.length === 1 && endsWithSpace && parts[0])) {
|
|
66
|
+
const pathPart = parts[0] ?? "";
|
|
67
|
+
const levelPartial = endsWithSpace && parts.length === 1 ? "" : (parts[parts.length - 1] ?? "");
|
|
68
|
+
const items = ACTIVE_LEVELS.filter((l) => l.startsWith(levelPartial)).map((l) => ({
|
|
69
|
+
value: `${pathPart} ${l}`,
|
|
31
70
|
label: l,
|
|
32
71
|
}));
|
|
33
72
|
return items.length > 0 ? items : null;
|
|
34
73
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.map((e) => join(cwd, e.name))
|
|
41
|
-
.filter((p) => p.startsWith(join(cwd, parts[0] ?? "")));
|
|
42
|
-
return files.length > 0 ? files.map((f) => ({ value: f, label: basename(f) })) : null;
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
74
|
+
// Position 1: path completion with nested-directory support.
|
|
75
|
+
const baseDir = deps.cwd ?? process.cwd();
|
|
76
|
+
const pathPartial = parts[0] ?? "";
|
|
77
|
+
const candidates = completePath(pathPartial, baseDir);
|
|
78
|
+
if (candidates.length === 0)
|
|
45
79
|
return null;
|
|
46
|
-
}
|
|
80
|
+
return candidates.map((c) => ({ value: c, label: c }));
|
|
47
81
|
},
|
|
48
82
|
async handler(args, ctx) {
|
|
49
83
|
const { path, level, yes } = parseArgs(args);
|
|
@@ -52,53 +86,36 @@ export function createUcFileCommand(deps) {
|
|
|
52
86
|
return;
|
|
53
87
|
}
|
|
54
88
|
let abs;
|
|
55
|
-
let backupPath;
|
|
56
|
-
let input;
|
|
57
89
|
try {
|
|
58
|
-
|
|
90
|
+
abs = safeResolveInCwd(path, ctx.cwd);
|
|
59
91
|
}
|
|
60
92
|
catch (e) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
e instanceof UnsupportedFileTypeError ||
|
|
64
|
-
e instanceof BackupExistsError ||
|
|
65
|
-
e instanceof FileTooLargeError) {
|
|
66
|
-
ctx.ui.notify(e.message, "error");
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
throw e;
|
|
93
|
+
ctx.ui.notify(e.message, "error");
|
|
94
|
+
return;
|
|
70
95
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
result = await compressTextPipeline({
|
|
75
|
-
input,
|
|
76
|
-
level,
|
|
77
|
-
mode: "file",
|
|
78
|
-
llm,
|
|
79
|
-
});
|
|
96
|
+
if (!existsSync(abs)) {
|
|
97
|
+
ctx.ui.notify(`ultra-compress: file not found "${abs}"`, "error");
|
|
98
|
+
return;
|
|
80
99
|
}
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
const ext = extOf(abs);
|
|
101
|
+
if (!isSupportedExtension(ext)) {
|
|
102
|
+
ctx.ui.notify(new UnsupportedFileTypeError(abs, `extension "${ext}" not supported`).message, "error");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (abs.endsWith(".original.md")) {
|
|
106
|
+
ctx.ui.notify(new UnsupportedFileTypeError(abs, "path looks like a backup file").message, "error");
|
|
83
107
|
return;
|
|
84
108
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
ctx.ui.notify(
|
|
88
|
-
if (result.warnings.length > 0) {
|
|
89
|
-
ctx.ui.notify(`warnings: ${result.warnings.join(" | ")}`, "warning");
|
|
90
|
-
}
|
|
109
|
+
const backupPath = backupPathFor(abs);
|
|
110
|
+
if (existsSync(backupPath)) {
|
|
111
|
+
ctx.ui.notify(new BackupExistsError(backupPath).message, "error");
|
|
91
112
|
return;
|
|
92
113
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
after: result.compressed.length,
|
|
99
|
-
at: new Date().toISOString(),
|
|
100
|
-
}, ctx.cwd);
|
|
101
|
-
ctx.ui.notify(`ultra-compress: compressed and written. Backup at ${backupPath}.`, "info");
|
|
114
|
+
const prompt = yes
|
|
115
|
+
? buildWritePrompt(abs, level, backupPath)
|
|
116
|
+
: buildPreviewPrompt(abs, level);
|
|
117
|
+
ctx.ui.notify(`ultra-compress: delegating ${yes ? "write" : "preview"} of ${basename(abs)} at ${level} to the agent...`, "info");
|
|
118
|
+
deps.sendUserMessage(prompt);
|
|
102
119
|
},
|
|
103
120
|
};
|
|
104
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uc-file.js","sourceRoot":"","sources":["../../src/commands/uc-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"uc-file.js","sourceRoot":"","sources":["../../src/commands/uc-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACN,aAAa,EAEb,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GACxB,MAAM,UAAU,CAAC;AASlB,SAAS,aAAa,CAAC,CAAS;IAC/B,OAAQ,aAAmC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC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,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBAClC,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,IAAI,wBAAwB,CAAC,GAAG,EAAE,+BAA+B,CAAC,CAAC,OAAO,EAC1E,OAAO,CACP,CAAC;gBACF,OAAO;YACR,CAAC;YAED,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;YACtC,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC5B,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,iBAAiB,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAClE,OAAO;YACR,CAAC;YAED,MAAM,MAAM,GAAG,GAAG;gBACjB,CAAC,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC;gBAC1C,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAElC,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,8BAA8B,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,KAAK,kBAAkB,EACzG,MAAM,CACN,CAAC;YACF,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { CommandDefinition } from "./types";
|
|
2
|
-
export
|
|
2
|
+
export interface UcRevertDeps {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function createUcRevertCommand(deps?: UcRevertDeps): CommandDefinition;
|
|
3
6
|
//# sourceMappingURL=uc-revert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uc-revert.d.ts","sourceRoot":"","sources":["../../src/commands/uc-revert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uc-revert.d.ts","sourceRoot":"","sources":["../../src/commands/uc-revert.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,qBAAqB,CAAC,IAAI,GAAE,YAAiB,GAAG,iBAAiB,CA4ChF"}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { backupPathFor } from "../services/backup-path";
|
|
1
3
|
import { restoreFromBackup } from "../services/file-ops";
|
|
4
|
+
import { completePath } from "../services/path-complete";
|
|
2
5
|
import { PathEscapeError, SymlinkRejectedError, safeResolveInCwd } from "../services/path-guard";
|
|
3
|
-
export function createUcRevertCommand() {
|
|
6
|
+
export function createUcRevertCommand(deps = {}) {
|
|
4
7
|
return {
|
|
5
8
|
name: "uc-revert",
|
|
6
9
|
description: "Restore a file from its ultra-compress .original.md backup.",
|
|
10
|
+
getArgumentCompletions(prefix) {
|
|
11
|
+
const trimmed = prefix ?? "";
|
|
12
|
+
const parts = trimmed.split(/\s+/);
|
|
13
|
+
const baseDir = deps.cwd ?? process.cwd();
|
|
14
|
+
const partial = parts[0] ?? "";
|
|
15
|
+
// Show only files whose backup exists — only revertable paths.
|
|
16
|
+
const candidates = completePath(partial, baseDir, (absPath) => existsSync(backupPathFor(absPath)));
|
|
17
|
+
if (candidates.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
return candidates.map((c) => ({ value: c, label: c }));
|
|
20
|
+
},
|
|
7
21
|
async handler(args, ctx) {
|
|
8
22
|
const path = args.trim();
|
|
9
23
|
if (!path) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uc-revert.js","sourceRoot":"","sources":["../../src/commands/uc-revert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,E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":3,"file":"uc.d.ts","sourceRoot":"","sources":["../../src/commands/uc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAMnE,wBAAgB,eAAe,IAAI,iBAAiB,CA0BnD"}
|
package/dist/commands/uc.js
CHANGED
|
@@ -16,6 +16,10 @@ export function createUcCommand() {
|
|
|
16
16
|
},
|
|
17
17
|
async handler(args, ctx) {
|
|
18
18
|
const level = args.trim();
|
|
19
|
+
if (!level) {
|
|
20
|
+
ctx.ui.notify("ultra-compress: usage: /uc <off|lite|standard|ultra|symbolic>", "error");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
19
23
|
if (!isLevel(level)) {
|
|
20
24
|
ctx.ui.notify(new InvalidLevelError(level).message, "error");
|
|
21
25
|
return;
|
package/dist/commands/uc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uc.js","sourceRoot":"","sources":["../../src/commands/uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAc,MAAM,UAAU,CAAC;AAGrE,SAAS,OAAO,CAAC,CAAS;IACzB,OAAQ,UAAgC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,eAAe;IAC9B,OAAO;QACN,IAAI,EAAE,IAAI;QACV,WAAW,EACV,mFAAmF;QACpF,sBAAsB,CAAC,MAAc;YACpC,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxE,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,CAAC;aACR,CAAC,CAAC,CAAC;YACJ,OAAO,KAAK,CAAC,MAAM,GAAG,C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G,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QACxC,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACZ,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,+DAA+D,EAAE,OAAO,CAAC,CAAC;gBACxF,OAAO;YACR,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrB,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7D,OAAO;YACR,CAAC;YACD,MAAM,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC;QACpD,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { ActiveLevel, CompressOptions, CompressResult, Level } from "./types";
|
|
1
|
+
import type { ActiveLevel, Level } from "./types";
|
|
3
2
|
type PiEventHandler = (event: unknown, ctx: unknown) => unknown | Promise<unknown>;
|
|
4
3
|
interface PiRegisteredCommand {
|
|
5
4
|
description?: string;
|
|
@@ -14,24 +13,20 @@ interface PiCommandContext {
|
|
|
14
13
|
notify?: (message: string, level?: string) => void;
|
|
15
14
|
};
|
|
16
15
|
cwd?: string;
|
|
17
|
-
modelRegistry?: LLMFactoryContext["modelRegistry"];
|
|
18
|
-
signal?: AbortSignal;
|
|
19
16
|
}
|
|
20
17
|
export interface PiExtensionApi {
|
|
21
18
|
on(event: string, handler: PiEventHandler): void;
|
|
22
19
|
registerCommand(name: string, config: PiRegisteredCommand): void;
|
|
20
|
+
sendUserMessage(content: string, options?: {
|
|
21
|
+
deliverAs?: "steer" | "followUp";
|
|
22
|
+
}): void;
|
|
23
23
|
cwd?: string;
|
|
24
24
|
}
|
|
25
25
|
export default function ultraCompressExtension(pi: PiExtensionApi): void;
|
|
26
26
|
export type { ActiveLevel, CompressOptions, CompressResult, Level, Mode, } from "./types";
|
|
27
|
-
export { PIContextRequiredError } from "./types";
|
|
28
27
|
export { buildLevelPromptFragment } from "./services/level-prompts";
|
|
29
28
|
export { validateCompression } from "./services/validator";
|
|
30
29
|
export declare function getActiveLevel(projectRoot?: string): Promise<Level>;
|
|
31
|
-
export type CtxLike = LLMFactoryContext & {
|
|
32
|
-
cwd?: string;
|
|
33
|
-
};
|
|
34
|
-
export declare function compressText(input: string, level: ActiveLevel, ctx: CtxLike, opts?: CompressOptions): Promise<CompressResult>;
|
|
35
30
|
export declare function compressTextLexical(input: string, level: ActiveLevel): {
|
|
36
31
|
compressed: string;
|
|
37
32
|
before: number;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIlD,KAAK,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnF,UAAU,mBAAmB;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,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
@@ -2,9 +2,7 @@ import { dirname, join } from "node:path";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { createUcCommand, createUcFileCommand, createUcRevertCommand, createUcStatusCommand, } from "./commands";
|
|
4
4
|
import { createAgentEndHook, createBeforeAgentStartHook, createSessionStartHook } from "./hooks";
|
|
5
|
-
import { compressTextPipeline } from "./services/compress-pipeline";
|
|
6
5
|
import { applyLevelLexical } from "./services/level-rules";
|
|
7
|
-
import { makeLLM } from "./services/llm-factory";
|
|
8
6
|
import { loadState } from "./services/state-store";
|
|
9
7
|
function wrapCommand(def) {
|
|
10
8
|
return {
|
|
@@ -29,15 +27,7 @@ export default function ultraCompressExtension(pi) {
|
|
|
29
27
|
};
|
|
30
28
|
pi.registerCommand("uc", wrapCommand(createUcCommand()));
|
|
31
29
|
pi.registerCommand("uc-file", wrapCommand(createUcFileCommand({
|
|
32
|
-
|
|
33
|
-
const piCtx = ctx;
|
|
34
|
-
const factoryCtx = {};
|
|
35
|
-
if (piCtx.modelRegistry !== undefined)
|
|
36
|
-
factoryCtx.modelRegistry = piCtx.modelRegistry;
|
|
37
|
-
if (piCtx.signal !== undefined)
|
|
38
|
-
factoryCtx.signal = piCtx.signal;
|
|
39
|
-
return makeLLM(factoryCtx);
|
|
40
|
-
},
|
|
30
|
+
sendUserMessage: (prompt) => pi.sendUserMessage(prompt),
|
|
41
31
|
})));
|
|
42
32
|
pi.registerCommand("uc-status", wrapCommand(createUcStatusCommand()));
|
|
43
33
|
pi.registerCommand("uc-revert", wrapCommand(createUcRevertCommand()));
|
|
@@ -54,11 +44,11 @@ export default function ultraCompressExtension(pi) {
|
|
|
54
44
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
55
45
|
const e = event;
|
|
56
46
|
const c = ctx;
|
|
57
|
-
if (typeof e?.
|
|
58
|
-
return;
|
|
47
|
+
if (typeof e?.systemPrompt !== "string")
|
|
48
|
+
return undefined;
|
|
59
49
|
if (typeof c?.cwd !== "string")
|
|
60
|
-
return;
|
|
61
|
-
return await beforeAgentStart({ prompt: e.prompt, systemPrompt: e.systemPrompt }, { cwd: c.cwd });
|
|
50
|
+
return undefined;
|
|
51
|
+
return await beforeAgentStart({ prompt: typeof e.prompt === "string" ? e.prompt : "", systemPrompt: e.systemPrompt }, { cwd: c.cwd });
|
|
62
52
|
});
|
|
63
53
|
pi.on("agent_end", async (event, ctx) => {
|
|
64
54
|
const c = ctx;
|
|
@@ -69,31 +59,14 @@ export default function ultraCompressExtension(pi) {
|
|
|
69
59
|
});
|
|
70
60
|
const extensionDir = dirname(fileURLToPath(import.meta.url));
|
|
71
61
|
const skillsDir = join(extensionDir, "skills");
|
|
72
|
-
pi.on("resources_discover", () => ({
|
|
62
|
+
pi.on("resources_discover", () => ({ skillPaths: [skillsDir] }));
|
|
73
63
|
}
|
|
74
|
-
export { PIContextRequiredError } from "./types";
|
|
75
64
|
export { buildLevelPromptFragment } from "./services/level-prompts";
|
|
76
65
|
export { validateCompression } from "./services/validator";
|
|
77
66
|
export async function getActiveLevel(projectRoot) {
|
|
78
67
|
const state = await loadState(projectRoot);
|
|
79
68
|
return state.level;
|
|
80
69
|
}
|
|
81
|
-
export async function compressText(input, level, ctx, opts) {
|
|
82
|
-
const factoryCtx = {};
|
|
83
|
-
if (ctx.modelRegistry !== undefined)
|
|
84
|
-
factoryCtx.modelRegistry = ctx.modelRegistry;
|
|
85
|
-
if (ctx.signal !== undefined)
|
|
86
|
-
factoryCtx.signal = ctx.signal;
|
|
87
|
-
const llm = makeLLM(factoryCtx);
|
|
88
|
-
return compressTextPipeline({
|
|
89
|
-
input,
|
|
90
|
-
level,
|
|
91
|
-
mode: "file",
|
|
92
|
-
llm,
|
|
93
|
-
...(opts?.maxRepairRetries !== undefined ? { maxRepairRetries: opts.maxRepairRetries } : {}),
|
|
94
|
-
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
70
|
export function compressTextLexical(input, level) {
|
|
98
71
|
const compressed = applyLevelLexical(input, level);
|
|
99
72
|
return { compressed, before: input.length, after: compressed.length };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAGN,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAGN,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAyBnD,SAAS,WAAW,CAAC,GAAsB;IAC1C,OAAO;QACN,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,GAAG,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAE,sBAAsB,EAAE,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK;YACxB,MAAM,GAAG,GAAmB;gBAC3B,GAAG,EAA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AC,CAAC;IAEH,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC/C,EAAE,CAAC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAClE,CAAC;AAWD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,WAAoB;IACxD,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC,KAAK,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAClC,KAAa,EACb,KAAkB;IAElB,MAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;AACvE,CAAC"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { compressTextPipeline } from "./compress-pipeline";
|
|
2
|
-
export type { LLMCall, CompressPipelineInput } from "./compress-pipeline";
|
|
3
1
|
export { buildLevelPromptFragment } from "./level-prompts";
|
|
4
2
|
export { applyLevelLexical, maskProtectedZones, unmaskProtectedZones } from "./level-rules";
|
|
5
3
|
export { validateCompression } from "./validator";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,GACb,MAAM,eAAe,CAAC"}
|
package/dist/services/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,GACb,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-complete.d.ts","sourceRoot":"","sources":["../../src/services/path-complete.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAS1E,wBAAgB,YAAY,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,gBAAgB,GAC3B,MAAM,EAAE,CAwCV"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { extOf, isSupportedExtension } from "./file-ops";
|
|
4
|
+
// Nested-path completion for .md/.txt/.rst/.markdown files.
|
|
5
|
+
// - Splits `partial` into (dirPart, tail); reads the directory.
|
|
6
|
+
// - Returns subdirectories with a trailing "/" (so tab-completion can drill in)
|
|
7
|
+
// and matching files.
|
|
8
|
+
// - Dotfiles/dotdirs and *.original.md backups are always skipped.
|
|
9
|
+
// - Optional `fileFilter`: called for each candidate file (by absolute path and
|
|
10
|
+
// name); only files returning true are included. Directories are unaffected.
|
|
11
|
+
export function completePath(partial, baseDir, fileFilter) {
|
|
12
|
+
let dirPart;
|
|
13
|
+
let tail;
|
|
14
|
+
const lastSep = partial.lastIndexOf("/");
|
|
15
|
+
if (lastSep === -1) {
|
|
16
|
+
dirPart = "";
|
|
17
|
+
tail = partial;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
dirPart = partial.slice(0, lastSep + 1);
|
|
21
|
+
tail = partial.slice(lastSep + 1);
|
|
22
|
+
}
|
|
23
|
+
const searchDir = dirPart === "" ? resolve(baseDir) : resolve(baseDir, dirPart);
|
|
24
|
+
let entries;
|
|
25
|
+
try {
|
|
26
|
+
entries = readdirSync(searchDir, { withFileTypes: true, encoding: "utf8" });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const results = [];
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
if (entry.name.startsWith("."))
|
|
34
|
+
continue;
|
|
35
|
+
if (!entry.name.startsWith(tail))
|
|
36
|
+
continue;
|
|
37
|
+
if (entry.isDirectory()) {
|
|
38
|
+
results.push(`${dirPart}${entry.name}/`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (entry.isFile()) {
|
|
42
|
+
if (!isSupportedExtension(extOf(entry.name)))
|
|
43
|
+
continue;
|
|
44
|
+
if (entry.name.endsWith(".original.md"))
|
|
45
|
+
continue;
|
|
46
|
+
if (fileFilter) {
|
|
47
|
+
const absPath = resolve(searchDir, entry.name);
|
|
48
|
+
if (!fileFilter(absPath, entry.name))
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
results.push(`${dirPart}${entry.name}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return results.sort();
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=path-complete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-complete.js","sourceRoot":"","sources":["../../src/services/path-complete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIzD,4DAA4D;AAC5D,gEAAgE;AAChE,gFAAgF;AAChF,wBAAwB;AACxB,mEAAmE;AACnE,gFAAgF;AAChF,+EAA+E;AAC/E,MAAM,UAAU,YAAY,CAC3B,OAAe,EACf,OAAe,EACf,UAA6B;IAE7B,IAAI,OAAe,CAAC;IACpB,IAAI,IAAY,CAAC;IACjB,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;QACpB,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,OAAO,CAAC;IAChB,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;QACxC,IAAI,GAAG,OAAO,CAAC,KAAK,CAA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AI,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -40,9 +40,6 @@ export interface ValidatorReport {
|
|
|
40
40
|
warnings: string[];
|
|
41
41
|
errors: string[];
|
|
42
42
|
}
|
|
43
|
-
export declare class PIContextRequiredError extends Error {
|
|
44
|
-
constructor();
|
|
45
|
-
}
|
|
46
43
|
export declare class InvalidLevelError extends Error {
|
|
47
44
|
constructor(given: string);
|
|
48
45
|
}
|
|
@@ -55,8 +52,4 @@ export declare class BackupExistsError extends Error {
|
|
|
55
52
|
export declare class UnsupportedFileTypeError extends Error {
|
|
56
53
|
constructor(path: string, reason: string);
|
|
57
54
|
}
|
|
58
|
-
export declare class ValidatorFailedError extends Error {
|
|
59
|
-
readonly errors: string[];
|
|
60
|
-
constructor(errors: string[]);
|
|
61
|
-
}
|
|
62
55
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEvE,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAEhD,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAEtC,eAAO,MAAM,UAAU,2DAA4D,CAAC;AACpF,eAAO,MAAM,aAAa,oDAAqD,CAAC;AAEhF,MAAM,WAAW,YAAY;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,yBAAyB,EAAE,MAAM,CAAC;IAClC,eAAe,EAAE,mBAAmB,EAAE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AAM;CAIxC"}
|
package/dist/types.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
export const ALL_LEVELS = ["off", "lite", "standard", "ultra", "symbolic"];
|
|
2
2
|
export const ACTIVE_LEVELS = ["lite", "standard", "ultra", "symbolic"];
|
|
3
|
-
export class PIContextRequiredError extends Error {
|
|
4
|
-
constructor() {
|
|
5
|
-
super("ultra-compress: PI ExtensionContext is required for LLM-backed operations");
|
|
6
|
-
this.name = "PIContextRequiredError";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
3
|
export class InvalidLevelError extends Error {
|
|
10
4
|
constructor(given) {
|
|
11
5
|
super(`ultra-compress: invalid level "${given}" (expected one of: off|lite|standard|ultra|symbolic)`);
|
|
@@ -30,12 +24,4 @@ export class UnsupportedFileTypeError extends Error {
|
|
|
30
24
|
this.name = "UnsupportedFileTypeError";
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
export class ValidatorFailedError extends Error {
|
|
34
|
-
errors;
|
|
35
|
-
constructor(errors) {
|
|
36
|
-
super(`ultra-compress: validator failed after repair retries — ${errors.join("; ")}`);
|
|
37
|
-
this.name = "ValidatorFailedError";
|
|
38
|
-
this.errors = errors;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
27
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AA0ChF,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AA0ChF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,KAAa;QACxB,KAAK,CACJ,kCAAkC,KAAK,uDAAuD,CAC9F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,IAAY,EAAE,KAAa;QACtC,KAAK,CAAC,yBAAyB,IAAI,QAAQ,KAAK,qBAAqB,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,UAAkB;QAC7B,KAAK,CAAC,2BAA2B,UAAU,yCAAyC,CAAC,CAAC;QACtF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAClD,YAAY,IAAY,EAAE,MAAc;QACvC,KAAK,CAAC,yCAAyC,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-forge-flow/ultra-compress-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "PI extension for token-efficient prose — level-based runtime output compression and markdown file compression",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type ActiveLevel, type CompressResult, type Mode } from "../types";
|
|
2
|
-
export type LLMCall = (prompt: string, signal?: AbortSignal) => Promise<string>;
|
|
3
|
-
export interface CompressPipelineInput {
|
|
4
|
-
input: string;
|
|
5
|
-
level: ActiveLevel;
|
|
6
|
-
mode: Mode;
|
|
7
|
-
llm: LLMCall;
|
|
8
|
-
maxRepairRetries?: number;
|
|
9
|
-
signal?: AbortSignal;
|
|
10
|
-
}
|
|
11
|
-
export declare function compressTextPipeline(opts: CompressPipelineInput): Promise<CompressResult>;
|
|
12
|
-
//# sourceMappingURL=compress-pipeline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress-pipeline.d.ts","sourceRoot":"","sources":["../../src/services/compress-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,IAAI,EAAwB,MAAM,UAAU,CAAC;AAKlG,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,OAAO,CAAC;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAuCD,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAyD/F"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { ValidatorFailedError } from "../types";
|
|
2
|
-
import { buildLevelPromptFragment } from "./level-prompts";
|
|
3
|
-
import { applyLevelLexical, maskProtectedZones, unmaskProtectedZones } from "./level-rules";
|
|
4
|
-
import { validateCompression } from "./validator";
|
|
5
|
-
const OUTER_FENCE_RE = /^\s*```(?:\w+)?\n([\s\S]*?)\n```\s*$/;
|
|
6
|
-
function stripOuterFence(s) {
|
|
7
|
-
const m = s.match(OUTER_FENCE_RE);
|
|
8
|
-
if (!m)
|
|
9
|
-
return s;
|
|
10
|
-
// m[1] is guaranteed to exist since OUTER_FENCE_RE has one capture group
|
|
11
|
-
// biome-ignore lint/style/noNonNullAssertion: capture group always exists
|
|
12
|
-
return m[1];
|
|
13
|
-
}
|
|
14
|
-
function buildInitialPrompt(maskedPrePass, level, mode) {
|
|
15
|
-
const rules = buildLevelPromptFragment(level, mode);
|
|
16
|
-
return `${rules}\n\nInput to compress:\n\n${maskedPrePass}`;
|
|
17
|
-
}
|
|
18
|
-
function buildRepairPrompt(masked, previousOutput, errors, level, mode) {
|
|
19
|
-
return `${buildLevelPromptFragment(level, mode)}
|
|
20
|
-
|
|
21
|
-
Previous output had these specific errors. DO NOT recompress or rephrase — PATCH ONLY these drifts:
|
|
22
|
-
|
|
23
|
-
${errors.map((e) => `- ${e}`).join("\n")}
|
|
24
|
-
|
|
25
|
-
Original masked input:
|
|
26
|
-
${masked}
|
|
27
|
-
|
|
28
|
-
Previous attempt:
|
|
29
|
-
${previousOutput}
|
|
30
|
-
|
|
31
|
-
Return a corrected version that keeps the level-${level} compression but fixes the listed drifts.`;
|
|
32
|
-
}
|
|
33
|
-
export async function compressTextPipeline(opts) {
|
|
34
|
-
const { input, level, mode, llm, maxRepairRetries = 2, signal } = opts;
|
|
35
|
-
const { masked, tokens } = maskProtectedZones(input);
|
|
36
|
-
const lexical = applyLevelLexical(masked, level);
|
|
37
|
-
const prompt = buildInitialPrompt(lexical, level, mode);
|
|
38
|
-
let attempt = 0;
|
|
39
|
-
let lastOutput = "";
|
|
40
|
-
let lastErrors = [];
|
|
41
|
-
const warnings = [];
|
|
42
|
-
while (attempt <= maxRepairRetries) {
|
|
43
|
-
const raw = attempt === 0
|
|
44
|
-
? await llm(prompt, signal)
|
|
45
|
-
: await llm(buildRepairPrompt(lexical, lastOutput, lastErrors, level, mode), signal);
|
|
46
|
-
let stripped = stripOuterFence(raw.trim());
|
|
47
|
-
// Remove punctuation immediately after protected token references to avoid duplication
|
|
48
|
-
stripped = stripped.replace(/⟨PROT:\d+⟩[.,;:!?]/g, (match) => match.slice(0, -1));
|
|
49
|
-
lastOutput = stripped;
|
|
50
|
-
// Check protected tokens survived the LLM pass BEFORE unmasking, so
|
|
51
|
-
// dropped tokens surface as a specific repair signal rather than as
|
|
52
|
-
// vague "missing URL" errors downstream.
|
|
53
|
-
const missing = [];
|
|
54
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
55
|
-
if (!stripped.includes(`⟨PROT:${i}⟩`))
|
|
56
|
-
missing.push(`⟨PROT:${i}⟩`);
|
|
57
|
-
}
|
|
58
|
-
if (missing.length > 0) {
|
|
59
|
-
lastErrors = [
|
|
60
|
-
`dropped protected tokens: ${missing.join(", ")} — these MUST appear verbatim in the output`,
|
|
61
|
-
];
|
|
62
|
-
attempt += 1;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const unmasked = unmaskProtectedZones(stripped, tokens);
|
|
66
|
-
const report = validateCompression(input, unmasked);
|
|
67
|
-
if (report.ok) {
|
|
68
|
-
return {
|
|
69
|
-
compressed: unmasked,
|
|
70
|
-
before: input.length,
|
|
71
|
-
after: unmasked.length,
|
|
72
|
-
ratio: (input.length - unmasked.length) / input.length,
|
|
73
|
-
warnings: [...warnings, ...report.warnings],
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
lastErrors = report.errors;
|
|
77
|
-
attempt += 1;
|
|
78
|
-
}
|
|
79
|
-
throw new ValidatorFailedError(lastErrors);
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=compress-pipeline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress-pipeline.js","sourceRoot":"","sources":["../../src/services/compress-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,oBAAoB,EAAE,MAAM,UAAU,CAA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;YACxB,UAAU,GAAG;gBACZ,6BAA6B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,6CAA6C;aAC5F,CAAC;YACF,OAAO,IAAI,CAAC,CAAC;YACb,SAAS;QACV,CAAC;QAED,MAAM,QAAQ,GAAG,oBAAoB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEpD,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,OAAO;gBACN,UAAU,EAAE,QAAQ;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,KAAK,EAAE,QAAQ,CAAC,MAAM;gBACtB,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM;gBACtD,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;aAC3C,CAAC;QACH,CAAC;QAED,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC3B,OAAO,IAAI,CAAC,CAAC;IACd,CAAC;IAED,MAAM,IAAI,oBAAoB,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { LLMCall } from "./compress-pipeline";
|
|
2
|
-
interface PiModelRegistry {
|
|
3
|
-
find(provider: string, model: string): unknown;
|
|
4
|
-
getApiKeyAndHeaders(model: unknown): Promise<{
|
|
5
|
-
apiKey: string;
|
|
6
|
-
headers: Record<string, string>;
|
|
7
|
-
}>;
|
|
8
|
-
}
|
|
9
|
-
export interface LLMFactoryContext {
|
|
10
|
-
modelRegistry?: PiModelRegistry;
|
|
11
|
-
signal?: AbortSignal;
|
|
12
|
-
}
|
|
13
|
-
export declare function makeLLM(piCtx: LLMFactoryContext): LLMCall;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=llm-factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llm-factory.d.ts","sourceRoot":"","sources":["../../src/services/llm-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,UAAU,eAAe;IACxB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/C,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;CAClG;AAED,MAAM,WAAW,iBAAiB;IACjC,aAAa,CAAC,EAAE,eAAe,CAAC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAID,wBAAgB,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CA0BzD"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { PIContextRequiredError } from "../types";
|
|
2
|
-
// Build a live LLMCall bound to the PI session's default model. Throws
|
|
3
|
-
// PIContextRequiredError when invoked outside a live PI runtime (no registry).
|
|
4
|
-
export function makeLLM(piCtx) {
|
|
5
|
-
return async (prompt, signal) => {
|
|
6
|
-
if (!piCtx.modelRegistry)
|
|
7
|
-
throw new PIContextRequiredError();
|
|
8
|
-
const mod = await import("@mariozechner/pi-ai");
|
|
9
|
-
const complete = mod.complete;
|
|
10
|
-
const model = piCtx.modelRegistry.find("", "");
|
|
11
|
-
const auth = await piCtx.modelRegistry.getApiKeyAndHeaders(model);
|
|
12
|
-
const resp = await complete(model, { messages: [{ role: "user", content: prompt }] }, {
|
|
13
|
-
apiKey: auth.apiKey,
|
|
14
|
-
headers: auth.headers,
|
|
15
|
-
maxTokens: 8192,
|
|
16
|
-
signal: signal ?? piCtx.signal,
|
|
17
|
-
});
|
|
18
|
-
return resp.content
|
|
19
|
-
.filter((c) => c.type === "text")
|
|
20
|
-
.map((c) => c.text ?? "")
|
|
21
|
-
.join("");
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=llm-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llm-factory.js","sourceRoot":"","sources":["../../src/services/llm-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAalD,uEAAuE;AACvE,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,KAAwB;IAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QAC/B,IAAI,CAAC,KAAK,CAAC,aAAa;YAAE,MAAM,IAAI,sBAAsB,EAAE,CAAC;QAC7D,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAChD,MAAM,QAAQ,GACb,GAGA,CAAC,QAAQ,CAAC;QACX,MAAM,KAAK,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAClE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAC1B,KAAK,EACL,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,EACjD;YACC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC,MAAM;SAC9B,CACD,CAAC;QACF,OAAO,IAAI,CAAC,OAAO;aACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;aAChC,GAAG,CAAC,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