@spences10/pi-svelte-guardrails 0.0.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/LICENSE +21 -0
- package/README.md +16 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Scott Spence
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @spences10/pi-svelte-guardrails
|
|
2
|
+
|
|
3
|
+
Pi extension that blocks agents from writing discouraged Svelte
|
|
4
|
+
patterns.
|
|
5
|
+
|
|
6
|
+
Currently blocks `$effect` in `.svelte` `write`/`edit` tool calls and
|
|
7
|
+
tells the agent to prefer `$derived`, event handlers, actions, or
|
|
8
|
+
explicit lifecycle alternatives.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pi install npm:@spences10/pi-svelte-guardrails
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This is opt-in: installing the package globally applies it to your Pi
|
|
15
|
+
sessions, but projects and downstream users do not inherit it unless
|
|
16
|
+
they install the package.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExtensionAPI, ToolCallEvent } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
export declare function is_svelte_path(value: unknown): boolean;
|
|
3
|
+
export declare function contains_disallowed_effect(value: unknown): boolean;
|
|
4
|
+
export declare function find_svelte_path(input: Record<string, unknown>): string | undefined;
|
|
5
|
+
export declare function extract_bash_svelte_path(command: string): string | undefined;
|
|
6
|
+
export declare function should_block_svelte_effect(event: ToolCallEvent): string | undefined;
|
|
7
|
+
export default function svelte_guardrails(pi: ExtensionAPI): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Svelte guardrails for Pi agents.
|
|
2
|
+
const SVELTE_FILE_RE = /\.svelte(?:\.|$|\?)/;
|
|
3
|
+
const EFFECT_RE = /\$effect(?:\s*\(|\s*\.)/;
|
|
4
|
+
export function is_svelte_path(value) {
|
|
5
|
+
return typeof value === 'string' && SVELTE_FILE_RE.test(value);
|
|
6
|
+
}
|
|
7
|
+
export function contains_disallowed_effect(value) {
|
|
8
|
+
return typeof value === 'string' && EFFECT_RE.test(value);
|
|
9
|
+
}
|
|
10
|
+
export function find_svelte_path(input) {
|
|
11
|
+
for (const key of ['path', 'file_path', 'filePath']) {
|
|
12
|
+
const value = input[key];
|
|
13
|
+
if (typeof value === 'string' && is_svelte_path(value))
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
function input_strings(value) {
|
|
19
|
+
if (typeof value === 'string')
|
|
20
|
+
return [value];
|
|
21
|
+
if (Array.isArray(value))
|
|
22
|
+
return value.flatMap(input_strings);
|
|
23
|
+
if (!value || typeof value !== 'object')
|
|
24
|
+
return [];
|
|
25
|
+
return Object.values(value).flatMap(input_strings);
|
|
26
|
+
}
|
|
27
|
+
export function extract_bash_svelte_path(command) {
|
|
28
|
+
const redirect_match = command.match(/>\s*['"]?([^'"\s>]+\.svelte)['"]?\b/);
|
|
29
|
+
if (redirect_match?.[1])
|
|
30
|
+
return redirect_match[1];
|
|
31
|
+
const tee_match = command.match(/\btee\b[^;&|]*\s+['"]?([^'"\s]+\.svelte)['"]?\b/);
|
|
32
|
+
if (tee_match?.[1])
|
|
33
|
+
return tee_match[1];
|
|
34
|
+
const heredoc_match = command.match(/\bcat\b[^;&|]*>\s*['"]?([^'"\s>]+\.svelte)['"]?\b/);
|
|
35
|
+
return heredoc_match?.[1];
|
|
36
|
+
}
|
|
37
|
+
function block_reason(path) {
|
|
38
|
+
return `Blocked by Svelte guardrails: ${path} was not created or modified. Do not investigate this guardrail. Complete the user's request by rewriting the example without $effect; use $derived, event handlers, actions, or lifecycle APIs instead. Do not report success until a replacement file is actually written.`;
|
|
39
|
+
}
|
|
40
|
+
export function should_block_svelte_effect(event) {
|
|
41
|
+
const input = event.input;
|
|
42
|
+
if (['write', 'edit'].includes(event.toolName)) {
|
|
43
|
+
const path = find_svelte_path(input);
|
|
44
|
+
if (!path)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (!input_strings(input).some(contains_disallowed_effect))
|
|
47
|
+
return undefined;
|
|
48
|
+
return block_reason(path);
|
|
49
|
+
}
|
|
50
|
+
if (event.toolName === 'bash') {
|
|
51
|
+
const command = input.command;
|
|
52
|
+
if (!contains_disallowed_effect(command))
|
|
53
|
+
return undefined;
|
|
54
|
+
if (typeof command !== 'string')
|
|
55
|
+
return undefined;
|
|
56
|
+
const path = extract_bash_svelte_path(command);
|
|
57
|
+
if (!path)
|
|
58
|
+
return undefined;
|
|
59
|
+
return block_reason(path);
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
export default function svelte_guardrails(pi) {
|
|
64
|
+
pi.on('tool_call', async (event) => {
|
|
65
|
+
const reason = should_block_svelte_effect(event);
|
|
66
|
+
if (!reason)
|
|
67
|
+
return undefined;
|
|
68
|
+
return { block: true, reason };
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAQnC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,MAAM,SAAS,GAAG,yBAAyB,CAAC;AAE5C,MAAM,UAAU,cAAc,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACxD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC/B,KAA8B;IAE9B,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,KAAK,CAAC;YACrD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QA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AA0B,CAAC;YACzD,OAAO,SAAS,CAAC;QAClB,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC;YAAE,OAAO,SAAS,CAAC;QAC3D,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QAClD,MAAM,IAAI,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EAAgB;IACzD,EAAE,CAAC,EAAE,CACJ,WAAW,EACX,KAAK,EAAE,KAAK,EAA4C,EAAE;QACzD,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAC;QAC9B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAChC,CAAC,CACD,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spences10/pi-svelte-guardrails",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Pi extension that blocks discouraged Svelte patterns before agents write them",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent-guardrails",
|
|
7
|
+
"pi",
|
|
8
|
+
"pi-package",
|
|
9
|
+
"svelte",
|
|
10
|
+
"svelte5"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Scott Spence <me@scottspence.com>",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/spences10/my-pi.git",
|
|
17
|
+
"directory": "packages/pi-svelte-guardrails"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@earendil-works/pi-coding-agent": "^0.74.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.6.1",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"vitest": "^4.1.5"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=24.15.0"
|
|
39
|
+
},
|
|
40
|
+
"pi": {
|
|
41
|
+
"extensions": [
|
|
42
|
+
"./dist/index.js"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run build:self",
|
|
47
|
+
"build:self": "tsc -p tsconfig.build.json",
|
|
48
|
+
"check": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run check:self",
|
|
49
|
+
"check:self": "tsc --noEmit -p tsconfig.json",
|
|
50
|
+
"test": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run test:self",
|
|
51
|
+
"test:self": "vitest run",
|
|
52
|
+
"test:watch": "vitest"
|
|
53
|
+
}
|
|
54
|
+
}
|