acture-sandbox 0.1.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/LICENSE +190 -0
- package/README.md +113 -0
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Thor Whalen
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# acture-sandbox
|
|
2
|
+
|
|
3
|
+
> **acture is a development tool first.** This package is an *optional
|
|
4
|
+
> accelerator* — and a deliberately small one. The extension **host/loader** is
|
|
5
|
+
> a ~15-line core-only pattern you hand-write (see
|
|
6
|
+
> [`docs/hand-written-sandbox.md`](https://github.com/thorwhalen/acture/blob/main/docs/hand-written-sandbox.md)),
|
|
7
|
+
> with no `acture-*` dependency. `acture-sandbox` ships only the *one* rung that
|
|
8
|
+
> is genuinely hard to hand-write: **isolating code you did not author.** See
|
|
9
|
+
> [`docs/positioning.md`](https://github.com/thorwhalen/acture/blob/main/docs/positioning.md).
|
|
10
|
+
|
|
11
|
+
An extension system is two layers (research-9 §1). The **host/loader** —
|
|
12
|
+
load/unload/observe bundles of command contributions — is pattern territory: a
|
|
13
|
+
`CommandRecord` already *is* the manifest, so a host that trusts its authors
|
|
14
|
+
needs nothing beyond `acture` core. The **isolation layer** — running code you
|
|
15
|
+
cannot audit *safely* — is the first acture surface that genuinely earns a
|
|
16
|
+
package. `acture-sandbox` is that layer, and nothing else: **one
|
|
17
|
+
`ExtensionRunner` port plus an in-process transport.**
|
|
18
|
+
|
|
19
|
+
The port is async and errors-as-data on purpose. A cross-boundary transport
|
|
20
|
+
(Web Worker, cross-origin iframe, QuickJS-in-WASM, Node `isolated-vm`) is
|
|
21
|
+
asynchronous and cannot transport thrown exceptions, so the in-process adapter
|
|
22
|
+
holds the identical contract. Design for the worst runtime; the local case is
|
|
23
|
+
then trivial — and moving in-process → isolated is an adapter swap, not a
|
|
24
|
+
rewrite.
|
|
25
|
+
|
|
26
|
+
> **The in-process transport is not a security boundary.** It is the v1 adapter
|
|
27
|
+
> for *trusted* authors. The moment an untrusted author is about to run code,
|
|
28
|
+
> swap in a real isolating transport behind the same port. Admitting untrusted
|
|
29
|
+
> code through the in-process adapter is the one irreversible mistake.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
pnpm add acture-sandbox # `acture` is a peer dependency you already have
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Run a trusted extension in-process
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createInProcessRunner } from 'acture-sandbox';
|
|
41
|
+
import type { Registry } from 'acture';
|
|
42
|
+
|
|
43
|
+
// The runner treats the bridge as opaque (`HostBridge = unknown`), so the host
|
|
44
|
+
// owns its shape and the extension narrows to it. Typically a facade over the
|
|
45
|
+
// registry / `dispatch` — what an extension may touch is the host's policy.
|
|
46
|
+
interface AppBridge {
|
|
47
|
+
registry: Registry;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const csvProfiler = {
|
|
51
|
+
activate(bridge: AppBridge) {
|
|
52
|
+
const unload = bridge.registry.registerAll(/* the extension's commands */);
|
|
53
|
+
return { deactivate: () => unload() };
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const runner = createInProcessRunner();
|
|
58
|
+
const hostBridge: AppBridge = { registry: appRegistry }; // appRegistry = your acture registry
|
|
59
|
+
|
|
60
|
+
// `bridge` is optional — omit it for a pure extension that acquires nothing,
|
|
61
|
+
// and `activate` receives `undefined`.
|
|
62
|
+
const loaded = await runner.load({ id: 'acme.csv-profiler', module: csvProfiler }, hostBridge);
|
|
63
|
+
if (!loaded.ok) console.error(loaded.error.code, loaded.error.message);
|
|
64
|
+
|
|
65
|
+
runner.loaded(); // → ['acme.csv-profiler']
|
|
66
|
+
await runner.dispose('acme.csv-profiler'); // runs deactivate(), forgets it
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Loading is errors-as-data — `load` and `dispose` never throw. Error codes:
|
|
70
|
+
`already_loaded`, `load_failed`, `activate_threw` (load) and `not_loaded`,
|
|
71
|
+
`deactivate_threw` (dispose). A disposed id can be loaded again.
|
|
72
|
+
|
|
73
|
+
### Lazy sources
|
|
74
|
+
|
|
75
|
+
A source can defer its module behind an `import` thunk (unwrapping a `default`
|
|
76
|
+
export), so the host can populate the palette / AI tool list from a manifest
|
|
77
|
+
*before* the extension's code is fetched:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
await runner.load({
|
|
81
|
+
id: 'acme.lazy',
|
|
82
|
+
import: () => import('./extensions/lazy.js'),
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## What this package is NOT
|
|
87
|
+
|
|
88
|
+
Isolation only. It deliberately does **not** ship the manifest schema, the
|
|
89
|
+
host/loader, an effect channel, capability grants, an entitlement / install
|
|
90
|
+
gate, or a marketplace. Those are a core-only pattern
|
|
91
|
+
([`docs/hand-written-sandbox.md`](https://github.com/thorwhalen/acture/blob/main/docs/hand-written-sandbox.md))
|
|
92
|
+
and host product architecture — documented, never bundled (no god-package; the
|
|
93
|
+
package translates, it does not decide). Real isolating transports
|
|
94
|
+
(Worker / iframe / QuickJS / `isolated-vm`) arrive one at a time, only when a
|
|
95
|
+
real untrusted-author need names them.
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
| Export | What |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `createInProcessRunner()` | Create an in-process (no-isolation) `ExtensionRunner` for trusted authors. |
|
|
102
|
+
| `ExtensionRunner` | The isolation port: `load(source, bridge?)`, `dispose(id)`, `loaded()`. Async, errors-as-data. |
|
|
103
|
+
| `ExtensionSource` | `{ id, module }` or `{ id, import }` — how the runner obtains an extension's module (open for future transports). |
|
|
104
|
+
| `ExtensionModule` | `{ activate(bridge) }` — the extension's entrypoint, returning an optional `ActivationHandle`. |
|
|
105
|
+
| `ActivationHandle` | `{ deactivate?() }` — teardown, invoked on `dispose`. |
|
|
106
|
+
| `HostBridge` | The host capabilities handed to `activate`. Opaque to the runner; defined by the host. |
|
|
107
|
+
| `LoadedExtension` | `{ id }` — a live handle returned from a successful `load`. |
|
|
108
|
+
|
|
109
|
+
## See also
|
|
110
|
+
|
|
111
|
+
- [`docs/hand-written-sandbox.md`](https://github.com/thorwhalen/acture/blob/main/docs/hand-written-sandbox.md) — the ~15-line host/loader you hand-write to drive this runner.
|
|
112
|
+
- The `acture-extensions` skill — the agent's guide to adding an extension system to a target project.
|
|
113
|
+
- [`docs/research/acture_research_9 -- Extensions and Plugin Systems.md`](https://github.com/thorwhalen/acture/blob/main/docs/research/acture_research_9%20--%20Extensions%20and%20Plugin%20Systems.md) — the design: trust model, isolation table, the effect-as-data seam.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var acture = require('acture');
|
|
4
|
+
|
|
5
|
+
// src/in-process-runner.ts
|
|
6
|
+
async function resolveModule(source) {
|
|
7
|
+
if ("module" in source) return source.module;
|
|
8
|
+
const imported = await source.import();
|
|
9
|
+
return "default" in imported ? imported.default : imported;
|
|
10
|
+
}
|
|
11
|
+
function describe(error) {
|
|
12
|
+
return error instanceof Error ? error.message : String(error);
|
|
13
|
+
}
|
|
14
|
+
function createInProcessRunner() {
|
|
15
|
+
const active = /* @__PURE__ */ new Map();
|
|
16
|
+
return {
|
|
17
|
+
async load(source, bridge) {
|
|
18
|
+
if (active.has(source.id)) {
|
|
19
|
+
return acture.err(
|
|
20
|
+
"already_loaded",
|
|
21
|
+
`Extension "${source.id}" is already loaded.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
let module;
|
|
25
|
+
try {
|
|
26
|
+
module = await resolveModule(source);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return acture.err("load_failed", describe(error), error);
|
|
29
|
+
}
|
|
30
|
+
let handle;
|
|
31
|
+
try {
|
|
32
|
+
handle = await module.activate(bridge);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return acture.err("activate_threw", describe(error), error);
|
|
35
|
+
}
|
|
36
|
+
active.set(source.id, handle ?? {});
|
|
37
|
+
return acture.ok({ id: source.id });
|
|
38
|
+
},
|
|
39
|
+
async dispose(id) {
|
|
40
|
+
const handle = active.get(id);
|
|
41
|
+
if (!handle) {
|
|
42
|
+
return acture.err("not_loaded", `Extension "${id}" is not loaded.`);
|
|
43
|
+
}
|
|
44
|
+
active.delete(id);
|
|
45
|
+
try {
|
|
46
|
+
await handle.deactivate?.();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return acture.err("deactivate_threw", describe(error), error);
|
|
49
|
+
}
|
|
50
|
+
return acture.ok(void 0);
|
|
51
|
+
},
|
|
52
|
+
loaded() {
|
|
53
|
+
return [...active.keys()];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.createInProcessRunner = createInProcessRunner;
|
|
59
|
+
//# sourceMappingURL=index.cjs.map
|
|
60
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/in-process-runner.ts"],"names":["err","ok"],"mappings":";;;;;AA2BA,eAAe,cAAc,MAAA,EAAmD;AAC9E,EAAA,IAAI,QAAA,IAAY,MAAA,EAAQ,OAAO,MAAA,CAAO,MAAA;AACtC,EAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,MAAA,EAAO;AACrC,EAAA,OAAO,SAAA,IAAa,QAAA,GAAW,QAAA,CAAS,OAAA,GAAU,QAAA;AACpD;AAKA,SAAS,SAAS,KAAA,EAAwB;AACxC,EAAA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAC9D;AAMO,SAAS,qBAAA,GAAyC;AACvD,EAAA,MAAM,MAAA,uBAAa,GAAA,EAA8B;AAEjD,EAAA,OAAO;AAAA,IACL,MAAM,IAAA,CAAK,MAAA,EAAyB,MAAA,EAAqB;AACvD,MAAA,IAAI,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACzB,QAAA,OAAOA,UAAA;AAAA,UACL,gBAAA;AAAA,UACA,CAAA,WAAA,EAAc,OAAO,EAAE,CAAA,oBAAA;AAAA,SACzB;AAAA,MACF;AAEA,MAAA,IAAI,MAAA;AACJ,MAAA,IAAI;AACF,QAAA,MAAA,GAAS,MAAM,cAAc,MAAM,CAAA;AAAA,MACrC,SAAS,KAAA,EAAO;AACd,QAAA,OAAOA,UAAA,CAAI,aAAA,EAAe,QAAA,CAAS,KAAK,GAAG,KAAK,CAAA;AAAA,MAClD;AAEA,MAAA,IAAI,MAAA;AACJ,MAAA,IAAI;AACF,QAAA,MAAA,GAAS,MAAM,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA;AAAA,MACvC,SAAS,KAAA,EAAO;AACd,QAAA,OAAOA,UAAA,CAAI,gBAAA,EAAkB,QAAA,CAAS,KAAK,GAAG,KAAK,CAAA;AAAA,MACrD;AAEA,MAAA,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,EAAA,EAAI,MAAA,IAAU,EAAE,CAAA;AAClC,MAAA,OAAOC,SAAA,CAAG,EAAE,EAAA,EAAI,MAAA,CAAO,IAAI,CAAA;AAAA,IAC7B,CAAA;AAAA,IAEA,MAAM,QAAQ,EAAA,EAAY;AACxB,MAAA,MAAM,MAAA,GAAS,MAAA,CAAO,GAAA,CAAI,EAAE,CAAA;AAC5B,MAAA,IAAI,CAAC,MAAA,EAAQ;AACX,QAAA,OAAOD,UAAA,CAAI,YAAA,EAAc,CAAA,WAAA,EAAc,EAAE,CAAA,gBAAA,CAAkB,CAAA;AAAA,MAC7D;AAIA,MAAA,MAAA,CAAO,OAAO,EAAE,CAAA;AAChB,MAAA,IAAI;AACF,QAAA,MAAM,OAAO,UAAA,IAAa;AAAA,MAC5B,SAAS,KAAA,EAAO;AACd,QAAA,OAAOA,UAAA,CAAI,kBAAA,EAAoB,QAAA,CAAS,KAAK,GAAG,KAAK,CAAA;AAAA,MACvD;AACA,MAAA,OAAOC,UAAG,MAAiB,CAAA;AAAA,IAC7B,CAAA;AAAA,IAEA,MAAA,GAAS;AACP,MAAA,OAAO,CAAC,GAAG,MAAA,CAAO,IAAA,EAAM,CAAA;AAAA,IAC1B;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * The in-process (no-isolation) `ExtensionRunner` transport — the v1 adapter\n * for TRUSTED authors (research-9 §3.5).\n *\n * It runs an extension's `activate` in the SAME realm, passing the host bridge\n * by reference. It contains nothing — an extension can do anything its bridge\n * allows. Its job is to establish the async, errors-as-data lifecycle so that a\n * real isolating transport (Web Worker, cross-origin iframe, QuickJS-in-WASM,\n * Node `isolated-vm`) is an adapter swap behind the same port, not a redesign.\n *\n * It is NOT a security boundary. The moment an author is untrusted, swap in an\n * isolating runner — that is the single trigger for the isolation transports\n * (research-9 §0). Admitting untrusted code through this adapter is the one\n * irreversible mistake.\n */\n\nimport { ok, err } from 'acture';\nimport type {\n ActivationHandle,\n ExtensionModule,\n ExtensionRunner,\n ExtensionSource,\n HostBridge,\n} from './runner.js';\n\n/** Resolve a source to its module, normalising an `import` thunk's optional\n * `default` export (ESM dynamic-import shape). */\nasync function resolveModule(source: ExtensionSource): Promise<ExtensionModule> {\n if ('module' in source) return source.module;\n const imported = await source.import();\n return 'default' in imported ? imported.default : imported;\n}\n\n/** Best-effort human message from an unknown thrown value (errors don't\n * survive a serialization boundary; the in-process adapter keeps the same\n * errors-as-data discipline a cross-boundary one is forced into). */\nfunction describe(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Create an in-process extension runner. Each `load` activates an extension in\n * this realm and tracks it by id; `dispose` deactivates and forgets it.\n */\nexport function createInProcessRunner(): ExtensionRunner {\n const active = new Map<string, ActivationHandle>();\n\n return {\n async load(source: ExtensionSource, bridge?: HostBridge) {\n if (active.has(source.id)) {\n return err(\n 'already_loaded',\n `Extension \"${source.id}\" is already loaded.`,\n );\n }\n\n let module: ExtensionModule;\n try {\n module = await resolveModule(source);\n } catch (error) {\n return err('load_failed', describe(error), error);\n }\n\n let handle: ActivationHandle | void;\n try {\n handle = await module.activate(bridge);\n } catch (error) {\n return err('activate_threw', describe(error), error);\n }\n\n active.set(source.id, handle ?? {});\n return ok({ id: source.id });\n },\n\n async dispose(id: string) {\n const handle = active.get(id);\n if (!handle) {\n return err('not_loaded', `Extension \"${id}\" is not loaded.`);\n }\n\n // Forget it first, so a throwing `deactivate` cannot leave a\n // half-disposed entry that can never be loaded or disposed again.\n active.delete(id);\n try {\n await handle.deactivate?.();\n } catch (error) {\n return err('deactivate_threw', describe(error), error);\n }\n return ok(undefined as void);\n },\n\n loaded() {\n return [...active.keys()];\n },\n };\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Result } from 'acture';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `ExtensionRunner` isolation port and its data contract.
|
|
5
|
+
*
|
|
6
|
+
* This is the single accelerator `acture-sandbox` exists for (research-9 §1,
|
|
7
|
+
* §6.1): isolating the execution of code you did not author. Everything here
|
|
8
|
+
* is transport-agnostic — `load` / `dispose` are async and return
|
|
9
|
+
* errors-as-data because a cross-boundary transport (Web Worker, cross-origin
|
|
10
|
+
* iframe, QuickJS-in-WASM, Node `isolated-vm`) is asynchronous and cannot
|
|
11
|
+
* transport thrown exceptions. The in-process adapter holds the identical
|
|
12
|
+
* contract, so moving in-process → isolated is an adapter swap, not a redesign
|
|
13
|
+
* (research-9 §3.3, §4.6: "design for the worst runtime; the local case is
|
|
14
|
+
* then trivial").
|
|
15
|
+
*
|
|
16
|
+
* What this file deliberately does NOT define: the manifest schema, the
|
|
17
|
+
* host/loader, the effect channel, capability grants, an entitlement store, a
|
|
18
|
+
* marketplace. Those are a ~15-line core-only pattern (`docs/hand-written-sandbox.md`)
|
|
19
|
+
* and host product architecture (research-9 §6.3, §7) — not package territory
|
|
20
|
+
* (hard-don't #2: no god-package; hard-don't #3: translate, don't decide).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The host capabilities handed to an extension at activation. OPAQUE to the
|
|
25
|
+
* runner by design: the in-process adapter passes it by reference; a future
|
|
26
|
+
* isolating adapter proxies it across the membrane as a capability-gated
|
|
27
|
+
* channel. The runner never inspects it — *what* an extension may touch is
|
|
28
|
+
* host policy (e.g. a facade over `registry.dispatch`), never the runner's call.
|
|
29
|
+
*/
|
|
30
|
+
type HostBridge = unknown;
|
|
31
|
+
/**
|
|
32
|
+
* What an extension exposes to the runner: an `activate` entrypoint the runner
|
|
33
|
+
* invokes once at load, mirroring VS Code's activate/deactivate lifecycle. Its
|
|
34
|
+
* returned handle (if any) is invoked on dispose.
|
|
35
|
+
*/
|
|
36
|
+
interface ExtensionModule {
|
|
37
|
+
activate(bridge: HostBridge): ActivationHandle | void | Promise<ActivationHandle | void>;
|
|
38
|
+
}
|
|
39
|
+
/** Returned by `activate` to register teardown. Optional — a pure extension
|
|
40
|
+
* that acquires nothing needs no `deactivate`. */
|
|
41
|
+
interface ActivationHandle {
|
|
42
|
+
deactivate?(): void | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* How a runner obtains an extension's module. Discriminated and open by
|
|
46
|
+
* design: the in-process adapter accepts a direct `module` reference or an
|
|
47
|
+
* `import` thunk; cross-boundary transports add their own variants (a URL, a
|
|
48
|
+
* source blob, a bundle hash) WITHOUT changing the port.
|
|
49
|
+
*/
|
|
50
|
+
type ExtensionSource = {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly module: ExtensionModule;
|
|
53
|
+
} | {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly import: () => Promise<ExtensionModule | {
|
|
56
|
+
default: ExtensionModule;
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
59
|
+
/** A live handle to a loaded extension. */
|
|
60
|
+
interface LoadedExtension {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The isolation seam — one port, swappable transports.
|
|
65
|
+
*
|
|
66
|
+
* Errors-as-data (`acture`'s `Result`) and async on purpose: the contract is
|
|
67
|
+
* byte-identical whether the extension runs in this realm or behind a
|
|
68
|
+
* membrane. An implementation NEVER throws across `load` / `dispose`.
|
|
69
|
+
*/
|
|
70
|
+
interface ExtensionRunner {
|
|
71
|
+
/** Load and activate an extension. Returns the live handle, or an error
|
|
72
|
+
* datum (`already_loaded`, `load_failed`, `activate_threw`). */
|
|
73
|
+
load(source: ExtensionSource, bridge?: HostBridge): Promise<Result<LoadedExtension>>;
|
|
74
|
+
/** Deactivate and unload. Returns an error datum (`not_loaded`,
|
|
75
|
+
* `deactivate_threw`); the extension is removed from `loaded()` regardless
|
|
76
|
+
* of whether `deactivate` threw. */
|
|
77
|
+
dispose(id: string): Promise<Result<void>>;
|
|
78
|
+
/** The ids currently loaded, in load order. */
|
|
79
|
+
loaded(): readonly string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The in-process (no-isolation) `ExtensionRunner` transport — the v1 adapter
|
|
84
|
+
* for TRUSTED authors (research-9 §3.5).
|
|
85
|
+
*
|
|
86
|
+
* It runs an extension's `activate` in the SAME realm, passing the host bridge
|
|
87
|
+
* by reference. It contains nothing — an extension can do anything its bridge
|
|
88
|
+
* allows. Its job is to establish the async, errors-as-data lifecycle so that a
|
|
89
|
+
* real isolating transport (Web Worker, cross-origin iframe, QuickJS-in-WASM,
|
|
90
|
+
* Node `isolated-vm`) is an adapter swap behind the same port, not a redesign.
|
|
91
|
+
*
|
|
92
|
+
* It is NOT a security boundary. The moment an author is untrusted, swap in an
|
|
93
|
+
* isolating runner — that is the single trigger for the isolation transports
|
|
94
|
+
* (research-9 §0). Admitting untrusted code through this adapter is the one
|
|
95
|
+
* irreversible mistake.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create an in-process extension runner. Each `load` activates an extension in
|
|
100
|
+
* this realm and tracks it by id; `dispose` deactivates and forgets it.
|
|
101
|
+
*/
|
|
102
|
+
declare function createInProcessRunner(): ExtensionRunner;
|
|
103
|
+
|
|
104
|
+
export { type ActivationHandle, type ExtensionModule, type ExtensionRunner, type ExtensionSource, type HostBridge, type LoadedExtension, createInProcessRunner };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Result } from 'acture';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `ExtensionRunner` isolation port and its data contract.
|
|
5
|
+
*
|
|
6
|
+
* This is the single accelerator `acture-sandbox` exists for (research-9 §1,
|
|
7
|
+
* §6.1): isolating the execution of code you did not author. Everything here
|
|
8
|
+
* is transport-agnostic — `load` / `dispose` are async and return
|
|
9
|
+
* errors-as-data because a cross-boundary transport (Web Worker, cross-origin
|
|
10
|
+
* iframe, QuickJS-in-WASM, Node `isolated-vm`) is asynchronous and cannot
|
|
11
|
+
* transport thrown exceptions. The in-process adapter holds the identical
|
|
12
|
+
* contract, so moving in-process → isolated is an adapter swap, not a redesign
|
|
13
|
+
* (research-9 §3.3, §4.6: "design for the worst runtime; the local case is
|
|
14
|
+
* then trivial").
|
|
15
|
+
*
|
|
16
|
+
* What this file deliberately does NOT define: the manifest schema, the
|
|
17
|
+
* host/loader, the effect channel, capability grants, an entitlement store, a
|
|
18
|
+
* marketplace. Those are a ~15-line core-only pattern (`docs/hand-written-sandbox.md`)
|
|
19
|
+
* and host product architecture (research-9 §6.3, §7) — not package territory
|
|
20
|
+
* (hard-don't #2: no god-package; hard-don't #3: translate, don't decide).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The host capabilities handed to an extension at activation. OPAQUE to the
|
|
25
|
+
* runner by design: the in-process adapter passes it by reference; a future
|
|
26
|
+
* isolating adapter proxies it across the membrane as a capability-gated
|
|
27
|
+
* channel. The runner never inspects it — *what* an extension may touch is
|
|
28
|
+
* host policy (e.g. a facade over `registry.dispatch`), never the runner's call.
|
|
29
|
+
*/
|
|
30
|
+
type HostBridge = unknown;
|
|
31
|
+
/**
|
|
32
|
+
* What an extension exposes to the runner: an `activate` entrypoint the runner
|
|
33
|
+
* invokes once at load, mirroring VS Code's activate/deactivate lifecycle. Its
|
|
34
|
+
* returned handle (if any) is invoked on dispose.
|
|
35
|
+
*/
|
|
36
|
+
interface ExtensionModule {
|
|
37
|
+
activate(bridge: HostBridge): ActivationHandle | void | Promise<ActivationHandle | void>;
|
|
38
|
+
}
|
|
39
|
+
/** Returned by `activate` to register teardown. Optional — a pure extension
|
|
40
|
+
* that acquires nothing needs no `deactivate`. */
|
|
41
|
+
interface ActivationHandle {
|
|
42
|
+
deactivate?(): void | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* How a runner obtains an extension's module. Discriminated and open by
|
|
46
|
+
* design: the in-process adapter accepts a direct `module` reference or an
|
|
47
|
+
* `import` thunk; cross-boundary transports add their own variants (a URL, a
|
|
48
|
+
* source blob, a bundle hash) WITHOUT changing the port.
|
|
49
|
+
*/
|
|
50
|
+
type ExtensionSource = {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly module: ExtensionModule;
|
|
53
|
+
} | {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly import: () => Promise<ExtensionModule | {
|
|
56
|
+
default: ExtensionModule;
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
59
|
+
/** A live handle to a loaded extension. */
|
|
60
|
+
interface LoadedExtension {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The isolation seam — one port, swappable transports.
|
|
65
|
+
*
|
|
66
|
+
* Errors-as-data (`acture`'s `Result`) and async on purpose: the contract is
|
|
67
|
+
* byte-identical whether the extension runs in this realm or behind a
|
|
68
|
+
* membrane. An implementation NEVER throws across `load` / `dispose`.
|
|
69
|
+
*/
|
|
70
|
+
interface ExtensionRunner {
|
|
71
|
+
/** Load and activate an extension. Returns the live handle, or an error
|
|
72
|
+
* datum (`already_loaded`, `load_failed`, `activate_threw`). */
|
|
73
|
+
load(source: ExtensionSource, bridge?: HostBridge): Promise<Result<LoadedExtension>>;
|
|
74
|
+
/** Deactivate and unload. Returns an error datum (`not_loaded`,
|
|
75
|
+
* `deactivate_threw`); the extension is removed from `loaded()` regardless
|
|
76
|
+
* of whether `deactivate` threw. */
|
|
77
|
+
dispose(id: string): Promise<Result<void>>;
|
|
78
|
+
/** The ids currently loaded, in load order. */
|
|
79
|
+
loaded(): readonly string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The in-process (no-isolation) `ExtensionRunner` transport — the v1 adapter
|
|
84
|
+
* for TRUSTED authors (research-9 §3.5).
|
|
85
|
+
*
|
|
86
|
+
* It runs an extension's `activate` in the SAME realm, passing the host bridge
|
|
87
|
+
* by reference. It contains nothing — an extension can do anything its bridge
|
|
88
|
+
* allows. Its job is to establish the async, errors-as-data lifecycle so that a
|
|
89
|
+
* real isolating transport (Web Worker, cross-origin iframe, QuickJS-in-WASM,
|
|
90
|
+
* Node `isolated-vm`) is an adapter swap behind the same port, not a redesign.
|
|
91
|
+
*
|
|
92
|
+
* It is NOT a security boundary. The moment an author is untrusted, swap in an
|
|
93
|
+
* isolating runner — that is the single trigger for the isolation transports
|
|
94
|
+
* (research-9 §0). Admitting untrusted code through this adapter is the one
|
|
95
|
+
* irreversible mistake.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create an in-process extension runner. Each `load` activates an extension in
|
|
100
|
+
* this realm and tracks it by id; `dispose` deactivates and forgets it.
|
|
101
|
+
*/
|
|
102
|
+
declare function createInProcessRunner(): ExtensionRunner;
|
|
103
|
+
|
|
104
|
+
export { type ActivationHandle, type ExtensionModule, type ExtensionRunner, type ExtensionSource, type HostBridge, type LoadedExtension, createInProcessRunner };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { err, ok } from 'acture';
|
|
2
|
+
|
|
3
|
+
// src/in-process-runner.ts
|
|
4
|
+
async function resolveModule(source) {
|
|
5
|
+
if ("module" in source) return source.module;
|
|
6
|
+
const imported = await source.import();
|
|
7
|
+
return "default" in imported ? imported.default : imported;
|
|
8
|
+
}
|
|
9
|
+
function describe(error) {
|
|
10
|
+
return error instanceof Error ? error.message : String(error);
|
|
11
|
+
}
|
|
12
|
+
function createInProcessRunner() {
|
|
13
|
+
const active = /* @__PURE__ */ new Map();
|
|
14
|
+
return {
|
|
15
|
+
async load(source, bridge) {
|
|
16
|
+
if (active.has(source.id)) {
|
|
17
|
+
return err(
|
|
18
|
+
"already_loaded",
|
|
19
|
+
`Extension "${source.id}" is already loaded.`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
let module;
|
|
23
|
+
try {
|
|
24
|
+
module = await resolveModule(source);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return err("load_failed", describe(error), error);
|
|
27
|
+
}
|
|
28
|
+
let handle;
|
|
29
|
+
try {
|
|
30
|
+
handle = await module.activate(bridge);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return err("activate_threw", describe(error), error);
|
|
33
|
+
}
|
|
34
|
+
active.set(source.id, handle ?? {});
|
|
35
|
+
return ok({ id: source.id });
|
|
36
|
+
},
|
|
37
|
+
async dispose(id) {
|
|
38
|
+
const handle = active.get(id);
|
|
39
|
+
if (!handle) {
|
|
40
|
+
return err("not_loaded", `Extension "${id}" is not loaded.`);
|
|
41
|
+
}
|
|
42
|
+
active.delete(id);
|
|
43
|
+
try {
|
|
44
|
+
await handle.deactivate?.();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return err("deactivate_threw", describe(error), error);
|
|
47
|
+
}
|
|
48
|
+
return ok(void 0);
|
|
49
|
+
},
|
|
50
|
+
loaded() {
|
|
51
|
+
return [...active.keys()];
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { createInProcessRunner };
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/in-process-runner.ts"],"names":[],"mappings":";;;AA2BA,eAAe,cAAc,MAAA,EAAmD;AAC9E,EAAA,IAAI,QAAA,IAAY,MAAA,EAAQ,OAAO,MAAA,CAAO,MAAA;AACtC,EAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,MAAA,EAAO;AACrC,EAAA,OAAO,SAAA,IAAa,QAAA,GAAW,QAAA,CAAS,OAAA,GAAU,QAAA;AACpD;AAKA,SAAS,SAAS,KAAA,EAAwB;AACxC,EAAA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAC9D;AAMO,SAAS,qBAAA,GAAyC;AACvD,EAAA,MAAM,MAAA,uBAAa,GAAA,EAA8B;AAEjD,EAAA,OAAO;AAAA,IACL,MAAM,IAAA,CAAK,MAAA,EAAyB,MAAA,EAAqB;AACvD,MAAA,IAAI,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACzB,QAAA,OAAO,GAAA;AAAA,UACL,gBAAA;AAAA,UACA,CAAA,WAAA,EAAc,OAAO,EAAE,CAAA,oBAAA;AAAA,SACzB;AAAA,MACF;AAEA,MAAA,IAAI,MAAA;AACJ,MAAA,IAAI;AACF,QAAA,MAAA,GAAS,MAAM,cAAc,MAAM,CAAA;AAAA,MACrC,SAAS,KAAA,EAAO;AACd,QAAA,OAAO,GAAA,CAAI,aAAA,EAAe,QAAA,CAAS,KAAK,GAAG,KAAK,CAAA;AAAA,MAClD;AAEA,MAAA,IAAI,MAAA;AACJ,MAAA,IAAI;AACF,QAAA,MAAA,GAAS,MAAM,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA;AAAA,MACvC,SAAS,KAAA,EAAO;AACd,QAAA,OAAO,GAAA,CAAI,gBAAA,EAAkB,QAAA,CAAS,KAAK,GAAG,KAAK,CAAA;AAAA,MACrD;AAEA,MAAA,MAAA,CAAO,GAAA,CAAI,MAAA,CAAO,EAAA,EAAI,MAAA,IAAU,EAAE,CAAA;AAClC,MAAA,OAAO,EAAA,CAAG,EAAE,EAAA,EAAI,MAAA,CAAO,IAAI,CAAA;AAAA,IAC7B,CAAA;AAAA,IAEA,MAAM,QAAQ,EAAA,EAAY;AACxB,MAAA,MAAM,MAAA,GAAS,MAAA,CAAO,GAAA,CAAI,EAAE,CAAA;AAC5B,MAAA,IAAI,CAAC,MAAA,EAAQ;AACX,QAAA,OAAO,GAAA,CAAI,YAAA,EAAc,CAAA,WAAA,EAAc,EAAE,CAAA,gBAAA,CAAkB,CAAA;AAAA,MAC7D;AAIA,MAAA,MAAA,CAAO,OAAO,EAAE,CAAA;AAChB,MAAA,IAAI;AACF,QAAA,MAAM,OAAO,UAAA,IAAa;AAAA,MAC5B,SAAS,KAAA,EAAO;AACd,QAAA,OAAO,GAAA,CAAI,kBAAA,EAAoB,QAAA,CAAS,KAAK,GAAG,KAAK,CAAA;AAAA,MACvD;AACA,MAAA,OAAO,GAAG,MAAiB,CAAA;AAAA,IAC7B,CAAA;AAAA,IAEA,MAAA,GAAS;AACP,MAAA,OAAO,CAAC,GAAG,MAAA,CAAO,IAAA,EAAM,CAAA;AAAA,IAC1B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * The in-process (no-isolation) `ExtensionRunner` transport — the v1 adapter\n * for TRUSTED authors (research-9 §3.5).\n *\n * It runs an extension's `activate` in the SAME realm, passing the host bridge\n * by reference. It contains nothing — an extension can do anything its bridge\n * allows. Its job is to establish the async, errors-as-data lifecycle so that a\n * real isolating transport (Web Worker, cross-origin iframe, QuickJS-in-WASM,\n * Node `isolated-vm`) is an adapter swap behind the same port, not a redesign.\n *\n * It is NOT a security boundary. The moment an author is untrusted, swap in an\n * isolating runner — that is the single trigger for the isolation transports\n * (research-9 §0). Admitting untrusted code through this adapter is the one\n * irreversible mistake.\n */\n\nimport { ok, err } from 'acture';\nimport type {\n ActivationHandle,\n ExtensionModule,\n ExtensionRunner,\n ExtensionSource,\n HostBridge,\n} from './runner.js';\n\n/** Resolve a source to its module, normalising an `import` thunk's optional\n * `default` export (ESM dynamic-import shape). */\nasync function resolveModule(source: ExtensionSource): Promise<ExtensionModule> {\n if ('module' in source) return source.module;\n const imported = await source.import();\n return 'default' in imported ? imported.default : imported;\n}\n\n/** Best-effort human message from an unknown thrown value (errors don't\n * survive a serialization boundary; the in-process adapter keeps the same\n * errors-as-data discipline a cross-boundary one is forced into). */\nfunction describe(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Create an in-process extension runner. Each `load` activates an extension in\n * this realm and tracks it by id; `dispose` deactivates and forgets it.\n */\nexport function createInProcessRunner(): ExtensionRunner {\n const active = new Map<string, ActivationHandle>();\n\n return {\n async load(source: ExtensionSource, bridge?: HostBridge) {\n if (active.has(source.id)) {\n return err(\n 'already_loaded',\n `Extension \"${source.id}\" is already loaded.`,\n );\n }\n\n let module: ExtensionModule;\n try {\n module = await resolveModule(source);\n } catch (error) {\n return err('load_failed', describe(error), error);\n }\n\n let handle: ActivationHandle | void;\n try {\n handle = await module.activate(bridge);\n } catch (error) {\n return err('activate_threw', describe(error), error);\n }\n\n active.set(source.id, handle ?? {});\n return ok({ id: source.id });\n },\n\n async dispose(id: string) {\n const handle = active.get(id);\n if (!handle) {\n return err('not_loaded', `Extension \"${id}\" is not loaded.`);\n }\n\n // Forget it first, so a throwing `deactivate` cannot leave a\n // half-disposed entry that can never be loaded or disposed again.\n active.delete(id);\n try {\n await handle.deactivate?.();\n } catch (error) {\n return err('deactivate_threw', describe(error), error);\n }\n return ok(undefined as void);\n },\n\n loaded() {\n return [...active.keys()];\n },\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "acture-sandbox",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "acture sandbox — the isolation seam for an extension system: one ExtensionRunner port plus an in-process transport. Swap in Worker / iframe / QuickJS / isolated-vm transports when authors are untrusted.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Thor Whalen",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/thorwhalen/acture.git",
|
|
10
|
+
"directory": "packages/sandbox"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/thorwhalen/acture#readme",
|
|
13
|
+
"bugs": "https://github.com/thorwhalen/acture/issues",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"acture": "^1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsup": "^8.3.0",
|
|
37
|
+
"typescript": "^5.7.0",
|
|
38
|
+
"vitest": "^2.1.0",
|
|
39
|
+
"zod": "^4.0.0",
|
|
40
|
+
"acture": "1.3.0"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"acture",
|
|
44
|
+
"sandbox",
|
|
45
|
+
"extensions",
|
|
46
|
+
"plugins",
|
|
47
|
+
"isolation",
|
|
48
|
+
"command-dispatch"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
58
|
+
}
|
|
59
|
+
}
|