@justjoshn/pi-pstack-v2 0.2.3 → 0.2.4
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/package.json +1 -1
- package/src/gondolin/policy.ts +65 -0
- package/src/gondolin/vm.ts +3 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justjoshn/pi-pstack-v2",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Use the pstack skills and workflow in Pi, with the upstream subagent tool spawning Pi in tmux, shell jobs running in tmux, and Pi's tools running in a Gondolin micro-VM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { createHttpHooks, createShadowPathPredicate, ReadonlyProvider, RealFSProvider, ShadowProvider, type VMOptions } from '@earendil-works/gondolin';
|
|
4
|
+
import { GUEST_WORKSPACE } from './paths.ts';
|
|
5
|
+
|
|
6
|
+
const GIT_HOOKS_PATH = '/.git/hooks';
|
|
7
|
+
const GIT_CONFIG_PATH = '/.git/config';
|
|
8
|
+
|
|
9
|
+
export const PROTECTED_GIT_PATHS: readonly string[] = [GIT_HOOKS_PATH, GIT_CONFIG_PATH];
|
|
10
|
+
|
|
11
|
+
/** Gondolin host patterns do not match apex domains with `*.x`, so apex domains are listed beside their wildcards. */
|
|
12
|
+
export const DEFAULT_ALLOWED_HOSTS: readonly string[] = [
|
|
13
|
+
'github.com',
|
|
14
|
+
'*.github.com',
|
|
15
|
+
'*.githubusercontent.com',
|
|
16
|
+
'ghcr.io',
|
|
17
|
+
'*.ghcr.io',
|
|
18
|
+
'registry.npmjs.org',
|
|
19
|
+
'*.npmjs.org',
|
|
20
|
+
'nodejs.org',
|
|
21
|
+
'*.nodejs.org',
|
|
22
|
+
'registry.yarnpkg.com',
|
|
23
|
+
'bun.sh',
|
|
24
|
+
'*.bun.sh',
|
|
25
|
+
'pypi.org',
|
|
26
|
+
'*.pypi.org',
|
|
27
|
+
'files.pythonhosted.org',
|
|
28
|
+
'*.pythonhosted.org',
|
|
29
|
+
'crates.io',
|
|
30
|
+
'*.crates.io',
|
|
31
|
+
'static.rust-lang.org',
|
|
32
|
+
'proxy.golang.org',
|
|
33
|
+
'sum.golang.org',
|
|
34
|
+
'storage.googleapis.com',
|
|
35
|
+
'rubygems.org',
|
|
36
|
+
'*.rubygems.org',
|
|
37
|
+
'dl-cdn.alpinelinux.org',
|
|
38
|
+
'*.alpinelinux.org',
|
|
39
|
+
'repo1.maven.org',
|
|
40
|
+
'repo.maven.apache.org',
|
|
41
|
+
'registry-1.docker.io',
|
|
42
|
+
'auth.docker.io',
|
|
43
|
+
'production.cloudflare.docker.com',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
export function createWorkspaceProvider(localCwd: string): ShadowProvider {
|
|
47
|
+
return new ShadowProvider(new RealFSProvider(localCwd), {
|
|
48
|
+
shouldShadow: createShadowPathPredicate([...PROTECTED_GIT_PATHS]),
|
|
49
|
+
writeMode: 'deny',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createDefaultNetworkPolicy() {
|
|
54
|
+
return createHttpHooks({ allowedHosts: [...DEFAULT_ALLOWED_HOSTS] });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createVmOptions(localCwd: string, packageRoot: string): VMOptions {
|
|
58
|
+
const { httpHooks, env } = createDefaultNetworkPolicy();
|
|
59
|
+
return {
|
|
60
|
+
sessionLabel: `pi ${path.basename(localCwd)}`,
|
|
61
|
+
httpHooks,
|
|
62
|
+
env,
|
|
63
|
+
vfs: { mounts: { [GUEST_WORKSPACE]: createWorkspaceProvider(localCwd), [packageRoot]: new ReadonlyProvider(new RealFSProvider(packageRoot)) } },
|
|
64
|
+
};
|
|
65
|
+
}
|
package/src/gondolin/vm.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
1
|
import { fileURLToPath } from 'node:url';
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { VM } from '@earendil-works/gondolin';
|
|
5
4
|
import type { ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
6
5
|
import { GUEST_WORKSPACE } from './paths.ts';
|
|
6
|
+
import { createVmOptions } from './policy.ts';
|
|
7
7
|
|
|
8
8
|
export const STATUS_KEY = 'gondolin';
|
|
9
9
|
const DEFAULT_SHELL = '/bin/sh';
|
|
@@ -27,10 +27,7 @@ export function createGondolinVm(localCwd: string): GondolinVm {
|
|
|
27
27
|
|
|
28
28
|
const start = async (ctx?: ExtensionContext): Promise<VM> => {
|
|
29
29
|
ctx?.ui.setStatus(STATUS_KEY, ctx.ui.theme.fg('accent', `Gondolin: starting ${GUEST_WORKSPACE}`));
|
|
30
|
-
const created = await VM.create(
|
|
31
|
-
sessionLabel: `pi ${path.basename(localCwd)}`,
|
|
32
|
-
vfs: { mounts: { [GUEST_WORKSPACE]: new RealFSProvider(localCwd), [PACKAGE_ROOT]: new ReadonlyProvider(new RealFSProvider(PACKAGE_ROOT)) } },
|
|
33
|
-
});
|
|
30
|
+
const created = await VM.create(createVmOptions(localCwd, PACKAGE_ROOT));
|
|
34
31
|
const bashProbe = await created.exec(BASH_PROBE);
|
|
35
32
|
shellPath = bashProbe.stdout.trim() || DEFAULT_SHELL;
|
|
36
33
|
vm = created;
|