@vtstech/pi-shared 1.0.3 → 1.0.4-1
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/README.md +30 -0
- package/format.js +2 -38
- package/ollama.js +6 -46
- package/package.json +2 -1
- package/security.js +9 -53
- package/types.js +2 -28
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @vtstech/pi-shared
|
|
2
|
+
|
|
3
|
+
Shared utilities for [Pi Coding Agent](https://github.com/badlogic/pi-mono) extensions by VTSTech.
|
|
4
|
+
|
|
5
|
+
This is an internal dependency — you don't need to install it directly. It's pulled in automatically when you install any `@vtstech/pi-*` extension package.
|
|
6
|
+
|
|
7
|
+
## Modules
|
|
8
|
+
|
|
9
|
+
| Module | Description |
|
|
10
|
+
|--------|-------------|
|
|
11
|
+
| `format` | Section headers, indicators (ok/fail/warn/info), numeric formatters (bytes, ms, percentages), string utilities |
|
|
12
|
+
| `ollama` | Ollama base URL resolution, models.json I/O, model family detection, Ollama API helpers |
|
|
13
|
+
| `security` | Command blocklist, SSRF patterns, path validation, URL validation, command sanitization, audit logging |
|
|
14
|
+
| `types` | Custom error classes, type definitions (ToolSupportLevel, StepResultType, AuditEntry, etc.) |
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { section, ok, fail, info } from "@vtstech/pi-shared/format";
|
|
20
|
+
import { readModelsJson, getOllamaBaseUrl } from "@vtstech/pi-shared/ollama";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Links
|
|
24
|
+
|
|
25
|
+
- [Main Repository](https://github.com/VTSTech/pi-coding-agent)
|
|
26
|
+
- [Changelog](https://github.com/VTSTech/pi-coding-agent/blob/main/CHANGELOG.md)
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT — [VTSTech](https://www.vts-tech.org)
|
package/format.js
CHANGED
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
1
|
// shared/format.ts
|
|
20
|
-
var format_exports = {};
|
|
21
|
-
__export(format_exports, {
|
|
22
|
-
bytesHuman: () => bytesHuman,
|
|
23
|
-
fail: () => fail,
|
|
24
|
-
fmtBytes: () => fmtBytes,
|
|
25
|
-
fmtDur: () => fmtDur,
|
|
26
|
-
info: () => info,
|
|
27
|
-
msHuman: () => msHuman,
|
|
28
|
-
ok: () => ok,
|
|
29
|
-
padRight: () => padRight,
|
|
30
|
-
pct: () => pct,
|
|
31
|
-
sanitizeForReport: () => sanitizeForReport,
|
|
32
|
-
section: () => section,
|
|
33
|
-
truncate: () => truncate,
|
|
34
|
-
warn: () => warn
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(format_exports);
|
|
37
2
|
function section(title) {
|
|
38
3
|
return `
|
|
39
4
|
\u2500\u2500 ${title} ${"\u2500".repeat(Math.max(1, 60 - title.length - 4))}`;
|
|
@@ -98,8 +63,7 @@ function sanitizeForReport(s, maxLines = 40) {
|
|
|
98
63
|
function padRight(s, n) {
|
|
99
64
|
return s + " ".repeat(Math.max(0, n - s.length));
|
|
100
65
|
}
|
|
101
|
-
|
|
102
|
-
0 && (module.exports = {
|
|
66
|
+
export {
|
|
103
67
|
bytesHuman,
|
|
104
68
|
fail,
|
|
105
69
|
fmtBytes,
|
|
@@ -113,4 +77,4 @@ function padRight(s, n) {
|
|
|
113
77
|
section,
|
|
114
78
|
truncate,
|
|
115
79
|
warn
|
|
116
|
-
}
|
|
80
|
+
};
|
package/ollama.js
CHANGED
|
@@ -1,47 +1,8 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
1
|
// shared/ollama.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
fetchOllamaModels: () => fetchOllamaModels,
|
|
35
|
-
getOllamaBaseUrl: () => getOllamaBaseUrl,
|
|
36
|
-
isReasoningModel: () => isReasoningModel,
|
|
37
|
-
readModelsJson: () => readModelsJson,
|
|
38
|
-
writeModelsJson: () => writeModelsJson
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(ollama_exports);
|
|
41
|
-
var fs = __toESM(require("node:fs"));
|
|
42
|
-
var path = __toESM(require("node:path"));
|
|
43
|
-
var import_node_os = __toESM(require("node:os"));
|
|
44
|
-
var MODELS_JSON_PATH = path.join(import_node_os.default.homedir(), ".pi", "agent", "models.json");
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
var MODELS_JSON_PATH = path.join(os.homedir(), ".pi", "agent", "models.json");
|
|
45
6
|
function getOllamaBaseUrl() {
|
|
46
7
|
try {
|
|
47
8
|
if (fs.existsSync(MODELS_JSON_PATH)) {
|
|
@@ -118,8 +79,7 @@ function detectModelFamily(modelName) {
|
|
|
118
79
|
}
|
|
119
80
|
return "unknown";
|
|
120
81
|
}
|
|
121
|
-
|
|
122
|
-
0 && (module.exports = {
|
|
82
|
+
export {
|
|
123
83
|
MODELS_JSON_PATH,
|
|
124
84
|
detectModelFamily,
|
|
125
85
|
fetchOllamaModels,
|
|
@@ -127,4 +87,4 @@ function detectModelFamily(modelName) {
|
|
|
127
87
|
isReasoningModel,
|
|
128
88
|
readModelsJson,
|
|
129
89
|
writeModelsJson
|
|
130
|
-
}
|
|
90
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtstech/pi-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4-1",
|
|
4
4
|
"description": "Shared utilities for Pi Coding Agent extensions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"keywords": ["pi-package", "pi-extensions"],
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"access": "public",
|
|
10
|
+
"type": "module",
|
|
10
11
|
"author": "VTSTech",
|
|
11
12
|
"homepage": "https://www.vts-tech.org",
|
|
12
13
|
"repository": {
|
package/security.js
CHANGED
|
@@ -1,50 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
1
|
// shared/security.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
BLOCKED_URL_PATTERNS: () => BLOCKED_URL_PATTERNS,
|
|
34
|
-
appendAuditEntry: () => appendAuditEntry,
|
|
35
|
-
checkBashToolInput: () => checkBashToolInput,
|
|
36
|
-
checkFileToolInput: () => checkFileToolInput,
|
|
37
|
-
checkHttpToolInput: () => checkHttpToolInput,
|
|
38
|
-
checkInjectionPatterns: () => checkInjectionPatterns,
|
|
39
|
-
isSafeUrl: () => isSafeUrl,
|
|
40
|
-
readRecentAuditEntries: () => readRecentAuditEntries,
|
|
41
|
-
sanitizeCommand: () => sanitizeCommand,
|
|
42
|
-
validatePath: () => validatePath
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(security_exports);
|
|
45
|
-
var fs = __toESM(require("node:fs"));
|
|
46
|
-
var path = __toESM(require("node:path"));
|
|
47
|
-
var import_node_os = __toESM(require("node:os"));
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
48
5
|
var BLOCKED_COMMANDS = /* @__PURE__ */ new Set([
|
|
49
6
|
// System modification
|
|
50
7
|
"rm",
|
|
@@ -190,9 +147,9 @@ function validatePath(filePath, allowedDirs) {
|
|
|
190
147
|
"/etc/passwd",
|
|
191
148
|
"/.ssh/",
|
|
192
149
|
"/.gnupg/",
|
|
193
|
-
path.join(
|
|
194
|
-
path.join(
|
|
195
|
-
path.join(
|
|
150
|
+
path.join(os.homedir(), ".ssh"),
|
|
151
|
+
path.join(os.homedir(), ".gnupg"),
|
|
152
|
+
path.join(os.homedir(), ".pi", "agent", "models.json")
|
|
196
153
|
];
|
|
197
154
|
for (const sensitive of sensitivePaths) {
|
|
198
155
|
if (resolved.startsWith(sensitive) || resolved === sensitive) {
|
|
@@ -283,7 +240,7 @@ function sanitizeCommand(command) {
|
|
|
283
240
|
}
|
|
284
241
|
return { isSafe: true, error: "", command };
|
|
285
242
|
}
|
|
286
|
-
var AUDIT_DIR = path.join(
|
|
243
|
+
var AUDIT_DIR = path.join(os.homedir(), ".pi", "agent");
|
|
287
244
|
var AUDIT_LOG_PATH = path.join(AUDIT_DIR, "audit.log");
|
|
288
245
|
function appendAuditEntry(entry) {
|
|
289
246
|
try {
|
|
@@ -367,8 +324,7 @@ function checkInjectionPatterns(input) {
|
|
|
367
324
|
}
|
|
368
325
|
return { safe: true, rule: "", detail: "" };
|
|
369
326
|
}
|
|
370
|
-
|
|
371
|
-
0 && (module.exports = {
|
|
327
|
+
export {
|
|
372
328
|
BLOCKED_COMMANDS,
|
|
373
329
|
BLOCKED_URL_PATTERNS,
|
|
374
330
|
appendAuditEntry,
|
|
@@ -380,4 +336,4 @@ function checkInjectionPatterns(input) {
|
|
|
380
336
|
readRecentAuditEntries,
|
|
381
337
|
sanitizeCommand,
|
|
382
338
|
validatePath
|
|
383
|
-
}
|
|
339
|
+
};
|
package/types.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
4
|
|
|
21
5
|
// shared/types.ts
|
|
22
|
-
var types_exports = {};
|
|
23
|
-
__export(types_exports, {
|
|
24
|
-
EmptyResponseError: () => EmptyResponseError,
|
|
25
|
-
ModelTimeoutError: () => ModelTimeoutError,
|
|
26
|
-
OllamaConnectionError: () => OllamaConnectionError,
|
|
27
|
-
SecurityBlockError: () => SecurityBlockError,
|
|
28
|
-
ToolParseError: () => ToolParseError
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(types_exports);
|
|
31
6
|
var OllamaConnectionError = class extends Error {
|
|
32
7
|
constructor(message, cause) {
|
|
33
8
|
super(message);
|
|
@@ -85,11 +60,10 @@ var ToolParseError = class extends Error {
|
|
|
85
60
|
this.rawText = rawText;
|
|
86
61
|
}
|
|
87
62
|
};
|
|
88
|
-
|
|
89
|
-
0 && (module.exports = {
|
|
63
|
+
export {
|
|
90
64
|
EmptyResponseError,
|
|
91
65
|
ModelTimeoutError,
|
|
92
66
|
OllamaConnectionError,
|
|
93
67
|
SecurityBlockError,
|
|
94
68
|
ToolParseError
|
|
95
|
-
}
|
|
69
|
+
};
|