@corenel/term 0.1.0 → 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.
- package/dist/chunk-2D7G4YW2.js +97 -0
- package/dist/chunk-CB5RFNB4.js +33 -0
- package/dist/chunk-F4ENQXQQ.js +909 -0
- package/dist/chunk-I44FC7PE.js +142 -0
- package/dist/chunk-IK4ZANNW.js +95 -0
- package/dist/chunk-M44CET5L.js +40 -0
- package/dist/chunk-OSJFMQCW.js +44 -0
- package/dist/{chunk-R6AXTD55.js → chunk-VTJEWHM3.js} +19 -1
- package/dist/commands.d.ts +14 -0
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +1 -1
- package/dist/describe.d.ts +23 -0
- package/dist/describe.d.ts.map +1 -1
- package/dist/describe.js +6 -1
- package/dist/diff.d.ts +100 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +18 -0
- package/dist/ink/App.d.ts +12 -0
- package/dist/ink/App.d.ts.map +1 -1
- package/dist/ink/Modal.d.ts.map +1 -1
- package/dist/ink/TodoBlock.d.ts +10 -0
- package/dist/ink/TodoBlock.d.ts.map +1 -0
- package/dist/ink/banner.d.ts +36 -0
- package/dist/ink/banner.d.ts.map +1 -0
- package/dist/ink/index.d.ts.map +1 -1
- package/dist/ink/index.js +300 -140
- package/dist/ink/items.d.ts.map +1 -1
- package/dist/ink/scroll.d.ts +14 -2
- package/dist/ink/scroll.d.ts.map +1 -1
- package/dist/ink/status.d.ts.map +1 -1
- package/dist/ink/theme.d.ts +9 -0
- package/dist/ink/theme.d.ts.map +1 -1
- package/dist/ink/todos.d.ts +20 -0
- package/dist/ink/todos.d.ts.map +1 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/persist.d.ts +27 -4
- package/dist/persist.d.ts.map +1 -1
- package/dist/persist.js +3 -1
- package/dist/policySource.d.ts +26 -0
- package/dist/policySource.d.ts.map +1 -0
- package/dist/policySource.js +8 -0
- package/dist/session.d.ts +199 -13
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +10 -5
- package/dist/state.d.ts +84 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +5 -3
- package/dist/writePreview.d.ts +58 -0
- package/dist/writePreview.d.ts.map +1 -0
- package/dist/writePreview.js +9 -0
- package/package.json +19 -6
- package/dist/chunk-47IH6X5H.js +0 -20
- package/dist/chunk-HAQGHLW6.js +0 -235
- package/dist/chunk-HYWLODZT.js +0 -1230
- package/dist/chunk-TCVDVYMF.js +0 -40
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sourceDescription
|
|
3
|
+
} from "./chunk-CB5RFNB4.js";
|
|
4
|
+
|
|
5
|
+
// src/describe.ts
|
|
6
|
+
import { PermissionService } from "@corenel/harness/guardrail/permission-service";
|
|
7
|
+
import { NAMESPACE_LABELS, resolveNamespace, toolAddress } from "@corenel/harness/tools/namespaces";
|
|
8
|
+
var PREVIEW_LINES = 6;
|
|
9
|
+
var PREVIEW_LINES_ERROR = 12;
|
|
10
|
+
var SUBJECT_WIDTH = 68;
|
|
11
|
+
var ORD_WIDTH = 4;
|
|
12
|
+
function formatOrd(ord) {
|
|
13
|
+
return `#${ord}`.padEnd(ORD_WIDTH);
|
|
14
|
+
}
|
|
15
|
+
function describeToolCall(_name, args) {
|
|
16
|
+
const a = args ?? {};
|
|
17
|
+
const raw = a.path ?? a.file ?? a.command ?? a.cmd ?? a.query ?? a.url;
|
|
18
|
+
const pattern = typeof a.pattern === "string" ? `/${a.pattern}/` : "";
|
|
19
|
+
const text = typeof raw === "string" ? raw : pattern;
|
|
20
|
+
if (!text) return "";
|
|
21
|
+
const one = text.replace(/\s+/g, " ").trim();
|
|
22
|
+
return one.length > SUBJECT_WIDTH ? `${one.slice(0, SUBJECT_WIDTH - 1)}\u2026` : one;
|
|
23
|
+
}
|
|
24
|
+
function capPreview(result, isError) {
|
|
25
|
+
const lines = result.split("\n").map((l) => l.replace(/\s+$/, ""));
|
|
26
|
+
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
27
|
+
while (lines.length && !lines[0].trim()) lines.shift();
|
|
28
|
+
if (!lines.length) return [];
|
|
29
|
+
const cap = isError ? PREVIEW_LINES_ERROR : PREVIEW_LINES;
|
|
30
|
+
if (lines.length <= cap) return lines;
|
|
31
|
+
const dropped = lines.length - cap;
|
|
32
|
+
return [...lines.slice(0, cap), `\u2026 ${dropped} more line${dropped === 1 ? "" : "s"}`];
|
|
33
|
+
}
|
|
34
|
+
function formatTools(tools) {
|
|
35
|
+
if (!tools.length) return "No tools are available.";
|
|
36
|
+
const w = Math.max(...tools.map((t) => t.name.length));
|
|
37
|
+
const line = (t) => ` ${t.name.padEnd(w)} ${t.mutates ? "*" : " "} ${t.means ?? t.description.split(". ")[0]}`;
|
|
38
|
+
return [
|
|
39
|
+
`${tools.length} tools available (* = can change things, and will ask first):`,
|
|
40
|
+
...[...tools].sort((a, b) => a.name.localeCompare(b.name)).map(line)
|
|
41
|
+
].join("\n");
|
|
42
|
+
}
|
|
43
|
+
var NAMESPACE_COL = 14;
|
|
44
|
+
function formatPolicy(policy, source, tools) {
|
|
45
|
+
const permission = new PermissionService({ policy });
|
|
46
|
+
const byNamespace = /* @__PURE__ */ new Map();
|
|
47
|
+
for (const t of tools) {
|
|
48
|
+
const ns = resolveNamespace(t);
|
|
49
|
+
const list = byNamespace.get(ns);
|
|
50
|
+
if (list) list.push(t);
|
|
51
|
+
else byNamespace.set(ns, [t]);
|
|
52
|
+
}
|
|
53
|
+
const lines = [
|
|
54
|
+
`${policy.name}${policy.description ? ` -- ${policy.description}` : ""}`,
|
|
55
|
+
`source: ${sourceDescription(source)}`,
|
|
56
|
+
"",
|
|
57
|
+
"effective level per namespace:"
|
|
58
|
+
];
|
|
59
|
+
for (const { ns, label } of NAMESPACE_LABELS) {
|
|
60
|
+
const nsTools = byNamespace.get(ns);
|
|
61
|
+
if (!nsTools || nsTools.length === 0) continue;
|
|
62
|
+
const levels = new Set(nsTools.map((t) => {
|
|
63
|
+
const subject = {
|
|
64
|
+
name: t.name,
|
|
65
|
+
address: toolAddress(t),
|
|
66
|
+
...t.mutates !== void 0 ? { mutates: t.mutates } : {},
|
|
67
|
+
...t.permission ? { permission: t.permission } : {}
|
|
68
|
+
};
|
|
69
|
+
return permission.resolveLevel(subject);
|
|
70
|
+
}));
|
|
71
|
+
const levelStr = levels.size === 1 ? [...levels][0] : `mixed (${[...levels].sort().join("/")})`;
|
|
72
|
+
lines.push(` ${label.padEnd(NAMESPACE_COL)} ${levelStr}`);
|
|
73
|
+
}
|
|
74
|
+
lines.push(
|
|
75
|
+
"",
|
|
76
|
+
"caps:",
|
|
77
|
+
` max turns ${policy.maxTurns ?? "none"}`,
|
|
78
|
+
` max tool calls ${policy.maxToolCalls ?? "none"}`,
|
|
79
|
+
` on violation ${policy.onViolation ?? "stop"}`,
|
|
80
|
+
` unattended ${policy.unattended ?? "deny"}`,
|
|
81
|
+
"",
|
|
82
|
+
"enforcement -- what actually confines each layer:",
|
|
83
|
+
" files the file service's root confines paths (rejects ../ and symlink escapes) -- this policy does not",
|
|
84
|
+
" shell the working directory is fixed at startup, but the command text itself is not confined by anything here"
|
|
85
|
+
);
|
|
86
|
+
return lines.join("\n");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
PREVIEW_LINES,
|
|
91
|
+
PREVIEW_LINES_ERROR,
|
|
92
|
+
formatOrd,
|
|
93
|
+
describeToolCall,
|
|
94
|
+
capPreview,
|
|
95
|
+
formatTools,
|
|
96
|
+
formatPolicy
|
|
97
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/policySource.ts
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
function sourceLabel(source) {
|
|
4
|
+
switch (source.kind) {
|
|
5
|
+
case "default":
|
|
6
|
+
return null;
|
|
7
|
+
case "builtin":
|
|
8
|
+
return source.name;
|
|
9
|
+
case "file":
|
|
10
|
+
case "project":
|
|
11
|
+
case "user":
|
|
12
|
+
return basename(source.path);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function sourceDescription(source) {
|
|
16
|
+
switch (source.kind) {
|
|
17
|
+
case "default":
|
|
18
|
+
return "built-in default (no --policy given, none discovered)";
|
|
19
|
+
case "builtin":
|
|
20
|
+
return `built-in "${source.name}" (--policy ${source.name})`;
|
|
21
|
+
case "file":
|
|
22
|
+
return `from ${source.path} (--policy)`;
|
|
23
|
+
case "project":
|
|
24
|
+
return `discovered at ${source.path}`;
|
|
25
|
+
case "user":
|
|
26
|
+
return `discovered at ${source.path}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
sourceLabel,
|
|
32
|
+
sourceDescription
|
|
33
|
+
};
|