opencode-landstrip 0.16.29 → 0.17.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/LICENSE +201 -21
- package/README.md +1 -1
- package/index.ts +49 -31
- package/package.json +4 -5
- package/shared.ts +59 -69
- package/tui.ts +146 -33
- package/landstrip.d.ts +0 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 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 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 those 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ but they are not process-sandboxed by this plugin.
|
|
|
76
76
|
|
|
77
77
|
## License
|
|
78
78
|
|
|
79
|
-
`opencode-landstrip` is licensed under `
|
|
79
|
+
`opencode-landstrip` is licensed under `Apache-2.0`. See [LICENSE](LICENSE) for more
|
|
80
80
|
information.
|
|
81
81
|
|
|
82
82
|
The bundled `@landstrip/landstrip` package is licensed separately as
|
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (C) Jarkko Sakkinen 2026
|
|
3
3
|
|
|
4
4
|
import type { Hooks, Plugin, PluginInput, PluginOptions } from '@opencode-ai/plugin';
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type LandstripTrap,
|
|
15
15
|
type SandboxConfig,
|
|
16
16
|
type SandboxFilesystemConfig,
|
|
17
|
+
controlResponseLine,
|
|
17
18
|
extractDomainsFromCommand,
|
|
18
19
|
formatLandstripTraps,
|
|
19
20
|
getConfigPaths,
|
|
@@ -61,7 +62,7 @@ interface SandboxPermissionDecision {
|
|
|
61
62
|
|
|
62
63
|
type ToastVariant = 'info' | 'success' | 'warning' | 'error';
|
|
63
64
|
|
|
64
|
-
const LANDSTRIP_VERSION = [0,
|
|
65
|
+
const LANDSTRIP_VERSION = [0, 17, 0] as const;
|
|
65
66
|
const REQUIRED_LANDSTRIP_VERSION = LANDSTRIP_VERSION.join('.');
|
|
66
67
|
const SUPPORTED_PLATFORMS = new Set<NodeJS.Platform>(['linux', 'darwin', 'win32']);
|
|
67
68
|
|
|
@@ -257,9 +258,6 @@ function extractBlockedPath(
|
|
|
257
258
|
const landstripTraps = parseLandstripTraps(output);
|
|
258
259
|
for (const trap of landstripTraps) {
|
|
259
260
|
if (trap.kind === 'filesystem') return normalizeBlockedPath(trap.path, baseDirectory);
|
|
260
|
-
if (trap.kind === 'internal' && trap.detail.file) {
|
|
261
|
-
return normalizeBlockedPath(trap.detail.file, baseDirectory);
|
|
262
|
-
}
|
|
263
261
|
}
|
|
264
262
|
|
|
265
263
|
if (
|
|
@@ -639,6 +637,7 @@ function startTrapServer(
|
|
|
639
637
|
baseDirectory: string,
|
|
640
638
|
sessionAllowedReadPaths: Set<string>,
|
|
641
639
|
sessionAllowedWritePaths: Set<string>,
|
|
640
|
+
sessionAllowedTargets: Set<string>,
|
|
642
641
|
): Promise<{ server: ReturnType<typeof createServer>; port: number; trapLines: string[] }> {
|
|
643
642
|
const trapLines: string[] = [];
|
|
644
643
|
const server = createServer((trapSocket) => {
|
|
@@ -660,33 +659,50 @@ function startTrapServer(
|
|
|
660
659
|
} catch {
|
|
661
660
|
obj = null;
|
|
662
661
|
}
|
|
663
|
-
if (
|
|
664
|
-
obj
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
662
|
+
if (obj && obj.state === 'query' && typeof obj.query_id === 'string') {
|
|
663
|
+
const queryId = obj.query_id;
|
|
664
|
+
if (
|
|
665
|
+
(obj.operation === 'read' || obj.operation === 'write') &&
|
|
666
|
+
typeof obj.path === 'string'
|
|
667
|
+
) {
|
|
668
|
+
const path = canonicalizePath(obj.path, baseDirectory);
|
|
669
|
+
const operation = obj.operation as 'read' | 'write';
|
|
670
|
+
// Per landstrip policy: a deny rule overrides allow only when more
|
|
671
|
+
// specific; a tie or more-specific allow carves the path back in.
|
|
672
|
+
const denyReadDepth = matchDepth(path, denyRead, baseDirectory);
|
|
673
|
+
const allowReadDepth = matchDepth(path, effectiveAllowRead, baseDirectory);
|
|
674
|
+
const denyWriteDepth = matchDepth(path, denyWrite, baseDirectory);
|
|
675
|
+
const allowWriteDepth = matchDepth(path, effectiveAllowWrite, baseDirectory);
|
|
676
|
+
const allowed =
|
|
677
|
+
operation === 'read'
|
|
678
|
+
? !(denyReadDepth > allowReadDepth) && allowReadDepth >= 0
|
|
679
|
+
: !(denyWriteDepth > allowWriteDepth) && allowWriteDepth >= 0;
|
|
680
|
+
if (allowed) {
|
|
681
|
+
trapSocket.write(controlResponseLine(queryId, 'allow'));
|
|
682
|
+
} else {
|
|
683
|
+
// Auto-grant via session scope and allow so the command proceeds.
|
|
684
|
+
const scope = sessionScopeFor(path, baseDirectory);
|
|
685
|
+
if (operation === 'read') sessionAllowedReadPaths.add(scope);
|
|
686
|
+
else sessionAllowedWritePaths.add(scope);
|
|
687
|
+
trapSocket.write(controlResponseLine(queryId, 'allow'));
|
|
688
|
+
trapLines.push(line);
|
|
689
|
+
}
|
|
690
|
+
} else if (
|
|
691
|
+
(obj.operation === 'connect' || obj.operation === 'bind') &&
|
|
692
|
+
typeof obj.target === 'string'
|
|
693
|
+
) {
|
|
694
|
+
// No policy field expresses "allow this address:port" (allowedDomains
|
|
695
|
+
// is hostname-based and enforced by the HTTP(S) proxy, not the broker),
|
|
696
|
+
// so — matching the filesystem branch above — auto-grant, remember it
|
|
697
|
+
// for the rest of the session, and surface it afterward rather than
|
|
698
|
+
// hanging or hard-denying an already-approved command.
|
|
699
|
+
const target = obj.target;
|
|
700
|
+
if (!sessionAllowedTargets.has(target)) {
|
|
701
|
+
sessionAllowedTargets.add(target);
|
|
702
|
+
trapLines.push(line);
|
|
703
|
+
}
|
|
704
|
+
trapSocket.write(controlResponseLine(queryId, 'allow'));
|
|
684
705
|
} else {
|
|
685
|
-
// Auto-grant via session scope and allow so the command proceeds.
|
|
686
|
-
const scope = sessionScopeFor(path, baseDirectory);
|
|
687
|
-
if (operation === 'read') sessionAllowedReadPaths.add(scope);
|
|
688
|
-
else sessionAllowedWritePaths.add(scope);
|
|
689
|
-
trapSocket.write(JSON.stringify({ query_id: obj.query_id, action: 'allow' }) + '\n');
|
|
690
706
|
trapLines.push(line);
|
|
691
707
|
}
|
|
692
708
|
} else {
|
|
@@ -829,6 +845,7 @@ const plugin: Plugin = async ({ client, directory }: PluginInput, options?: Plug
|
|
|
829
845
|
const callAllowances = new Set<string>();
|
|
830
846
|
const sessionAllowedReadPaths = new Set<string>();
|
|
831
847
|
const sessionAllowedWritePaths = new Set<string>();
|
|
848
|
+
const sessionAllowedTargets = new Set<string>();
|
|
832
849
|
|
|
833
850
|
function getEffectiveAllowRead(config: SandboxConfig): string[] {
|
|
834
851
|
return [...config.filesystem.allowRead, ...sessionAllowedReadPaths];
|
|
@@ -1153,6 +1170,7 @@ const plugin: Plugin = async ({ client, directory }: PluginInput, options?: Plug
|
|
|
1153
1170
|
directory,
|
|
1154
1171
|
sessionAllowedReadPaths,
|
|
1155
1172
|
sessionAllowedWritePaths,
|
|
1173
|
+
sessionAllowedTargets,
|
|
1156
1174
|
);
|
|
1157
1175
|
|
|
1158
1176
|
const wrappedCommand = buildWrappedCommand(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-landstrip",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Landlock-based sandboxing for opencode with landstrip",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"landlock",
|
|
@@ -8,16 +8,15 @@
|
|
|
8
8
|
"opencode-plugin",
|
|
9
9
|
"sandbox"
|
|
10
10
|
],
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/landstrip/
|
|
14
|
+
"url": "git+https://github.com/landstrip/landstrip.git"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"index.ts",
|
|
18
18
|
"tui.ts",
|
|
19
19
|
"shared.ts",
|
|
20
|
-
"landstrip.d.ts",
|
|
21
20
|
"README.md",
|
|
22
21
|
"sandbox.json"
|
|
23
22
|
],
|
|
@@ -49,7 +48,7 @@
|
|
|
49
48
|
"ci:test": "npm test"
|
|
50
49
|
},
|
|
51
50
|
"dependencies": {
|
|
52
|
-
"@landstrip/landstrip": "^0.
|
|
51
|
+
"@landstrip/landstrip": "^0.17.1"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
54
|
"@opencode-ai/plugin": "^1.17.7",
|
package/shared.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (C) Jarkko Sakkinen 2026
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
binaryPath,
|
|
6
|
+
type LandstripControlResponse,
|
|
7
|
+
type LandstripTrap,
|
|
8
|
+
} from '@landstrip/landstrip';
|
|
9
|
+
|
|
10
|
+
// Re-exported so index.ts/tui.ts can import the trap/response types from this
|
|
11
|
+
// module alongside the parsing functions that produce/consume them.
|
|
12
|
+
export type { LandstripControlResponse, LandstripTrap };
|
|
5
13
|
|
|
6
14
|
import { createHash } from 'node:crypto';
|
|
7
15
|
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
@@ -396,81 +404,54 @@ export function updateForPermission(
|
|
|
396
404
|
}
|
|
397
405
|
|
|
398
406
|
// Landstrip emits one JSON trap per line on its trap fd/file. The `state` field
|
|
399
|
-
//
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
// optional. Parsing lives here so the server hook and the TUI socket handler
|
|
403
|
-
// decode identically.
|
|
404
|
-
export type LandstripTrapState = 'query' | 'info';
|
|
405
|
-
|
|
406
|
-
export type LandstripTrap =
|
|
407
|
-
| {
|
|
408
|
-
kind: 'filesystem';
|
|
409
|
-
operation: 'read' | 'write';
|
|
410
|
-
path: string;
|
|
411
|
-
mechanism: string;
|
|
412
|
-
state?: LandstripTrapState;
|
|
413
|
-
queryId?: number;
|
|
414
|
-
}
|
|
415
|
-
| { kind: 'network'; operation: string; target: string; mechanism: string }
|
|
416
|
-
| { kind: 'launch'; program: string; message: string }
|
|
417
|
-
| { kind: 'usage'; message: string }
|
|
418
|
-
| { kind: 'internal'; detail: Record<string, string> };
|
|
419
|
-
|
|
407
|
+
// distinguishes a terminal `info` trap from a `query` trap that holds a syscall
|
|
408
|
+
// pending until the host answers with the trap's `query_id`. Parsing lives here
|
|
409
|
+
// so the server hook and the TUI socket handler decode identically.
|
|
420
410
|
const LANDSTRIP_OPERATIONS = new Set<'read' | 'write'>(['read', 'write']);
|
|
421
411
|
|
|
422
412
|
function isLandstripOperation(value: unknown): value is 'read' | 'write' {
|
|
423
413
|
return typeof value === 'string' && LANDSTRIP_OPERATIONS.has(value as 'read' | 'write');
|
|
424
414
|
}
|
|
425
415
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
416
|
+
// The declarations landstrip ships are compile-time only, so a runtime guard is
|
|
417
|
+
// still required — but it only has to validate the fields actually read below.
|
|
418
|
+
// Deliberately does not validate `state`: a missing or unknown state degrades to
|
|
419
|
+
// "informational", the safe direction. `query_id` must be a string on both
|
|
420
|
+
// filesystem and network traps — landstrip < 0.17 sent a number here, and a
|
|
421
|
+
// numeric id fails landstrip's own deserializer when echoed back, so treating
|
|
422
|
+
// it as undecodable (rather than coercing it) keeps a stale/mismatched trap
|
|
423
|
+
// from ever being answered with a shape the broker would reject.
|
|
424
|
+
function isLandstripTrap(value: unknown): value is LandstripTrap {
|
|
425
|
+
if (!isRecord(value)) return false;
|
|
433
426
|
|
|
434
427
|
switch (value.kind) {
|
|
435
|
-
case 'filesystem':
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
case '
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return
|
|
453
|
-
}
|
|
454
|
-
case 'usage': {
|
|
455
|
-
const { message } = value;
|
|
456
|
-
if (typeof message !== 'string') return null;
|
|
457
|
-
return { kind: 'usage', message };
|
|
458
|
-
}
|
|
459
|
-
case 'internal': {
|
|
460
|
-
const detail: Record<string, string> = {};
|
|
461
|
-
const payload = value.detail;
|
|
462
|
-
if (isRecord(payload)) {
|
|
463
|
-
for (const [key, val] of Object.entries(payload)) {
|
|
464
|
-
detail[key] = typeof val === 'string' ? val : JSON.stringify(val);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return { kind: 'internal', detail };
|
|
468
|
-
}
|
|
428
|
+
case 'filesystem':
|
|
429
|
+
return (
|
|
430
|
+
isLandstripOperation(value.operation) &&
|
|
431
|
+
typeof value.path === 'string' &&
|
|
432
|
+
typeof value.query_id === 'string'
|
|
433
|
+
);
|
|
434
|
+
case 'network':
|
|
435
|
+
return (
|
|
436
|
+
typeof value.operation === 'string' &&
|
|
437
|
+
typeof value.target === 'string' &&
|
|
438
|
+
typeof value.query_id === 'string'
|
|
439
|
+
);
|
|
440
|
+
case 'launch':
|
|
441
|
+
return typeof value.program === 'string' && typeof value.message === 'string';
|
|
442
|
+
case 'usage':
|
|
443
|
+
return typeof value.message === 'string';
|
|
444
|
+
case 'internal':
|
|
445
|
+
return typeof value.code === 'string' && typeof value.message === 'string';
|
|
469
446
|
default:
|
|
470
|
-
return
|
|
447
|
+
return false;
|
|
471
448
|
}
|
|
472
449
|
}
|
|
473
450
|
|
|
451
|
+
export function decodeLandstripTrap(value: unknown): LandstripTrap | null {
|
|
452
|
+
return isLandstripTrap(value) ? value : null;
|
|
453
|
+
}
|
|
454
|
+
|
|
474
455
|
export function parseLandstripTraps(output: string): LandstripTrap[] {
|
|
475
456
|
const traps: LandstripTrap[] = [];
|
|
476
457
|
|
|
@@ -507,10 +488,8 @@ export function formatLandstripTrap(trap: LandstripTrap): string {
|
|
|
507
488
|
case 'usage':
|
|
508
489
|
return `landstrip: usage error: ${trap.message}`;
|
|
509
490
|
case 'internal': {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
.join(', ');
|
|
513
|
-
return `landstrip: internal error${detail ? ` (${detail})` : ''}`;
|
|
491
|
+
const mechanism = trap.mechanism ? ` [${trap.mechanism}]` : '';
|
|
492
|
+
return `landstrip: ${trap.code}${mechanism}: ${trap.message}`;
|
|
514
493
|
}
|
|
515
494
|
}
|
|
516
495
|
}
|
|
@@ -519,6 +498,17 @@ export function formatLandstripTraps(traps: LandstripTrap[]): string {
|
|
|
519
498
|
return traps.map(formatLandstripTrap).join('\n');
|
|
520
499
|
}
|
|
521
500
|
|
|
501
|
+
// The broker matches an answer to its query by the exact decimal `query_id`
|
|
502
|
+
// string the trap carried. A numeric id fails its deserializer, the line is
|
|
503
|
+
// dropped, and the child's syscall stays suspended.
|
|
504
|
+
export function controlResponseLine(
|
|
505
|
+
queryId: string,
|
|
506
|
+
action: LandstripControlResponse['action'],
|
|
507
|
+
): string {
|
|
508
|
+
const response: LandstripControlResponse = { query_id: queryId, action };
|
|
509
|
+
return JSON.stringify(response) + '\n';
|
|
510
|
+
}
|
|
511
|
+
|
|
522
512
|
// The TUI plugin runs the query-response socket server and publishes its port
|
|
523
513
|
// to a per-directory discovery file; the server plugin reads it to inject the
|
|
524
514
|
// fd-3 redirect. Namespacing by a hash of the realpath keeps concurrent
|
package/tui.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (C) Jarkko Sakkinen 2026
|
|
3
3
|
|
|
4
4
|
import type { TuiPlugin, TuiSlotContext, TuiSlotPlugin } from '@opencode-ai/plugin/tui';
|
|
5
5
|
import { type AddressInfo, createServer, type Socket as NetSocket } from 'node:net';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
controlResponseLine,
|
|
8
9
|
getConfigPaths,
|
|
9
10
|
loadConfig,
|
|
10
11
|
normalizeOptions,
|
|
@@ -37,6 +38,10 @@ type PermissionChoice = 'once' | 'session' | 'project' | 'global' | 'reject';
|
|
|
37
38
|
|
|
38
39
|
type QueryChoice = 'once' | 'session' | 'project' | 'global' | 'deny';
|
|
39
40
|
|
|
41
|
+
// No project/global option: no landstrip policy field expresses "allow this
|
|
42
|
+
// address:port" the way allowRead/allowWrite express a path.
|
|
43
|
+
type NetworkQueryChoice = 'once' | 'session' | 'deny';
|
|
44
|
+
|
|
40
45
|
// A landstrip filesystem query (read or write) held pending over the fd-3
|
|
41
46
|
// socket. It shares the dialog stack with permission prompts so the two never
|
|
42
47
|
// overlap, hence the common `id`/`kind` shape.
|
|
@@ -44,18 +49,31 @@ interface FsQueryEntry {
|
|
|
44
49
|
kind: 'fs-query';
|
|
45
50
|
id: string;
|
|
46
51
|
socket: NetSocket;
|
|
47
|
-
queryId:
|
|
52
|
+
queryId: string;
|
|
48
53
|
operation: 'read' | 'write';
|
|
49
54
|
path: string;
|
|
50
55
|
}
|
|
51
56
|
|
|
57
|
+
// A landstrip network query (connect or bind) held pending over the same
|
|
58
|
+
// fd-3 socket. The broker only knows `address:port`, so — unlike FsQueryEntry
|
|
59
|
+
// — there is no project/global persistence option: no policy field can
|
|
60
|
+
// express "allow this address:port".
|
|
61
|
+
interface NetworkQueryEntry {
|
|
62
|
+
kind: 'net-query';
|
|
63
|
+
id: string;
|
|
64
|
+
socket: NetSocket;
|
|
65
|
+
queryId: string;
|
|
66
|
+
operation: string;
|
|
67
|
+
target: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
52
70
|
interface PermissionEntry {
|
|
53
71
|
kind: 'permission';
|
|
54
72
|
id: string;
|
|
55
73
|
permission: PendingPermission;
|
|
56
74
|
}
|
|
57
75
|
|
|
58
|
-
type QueueEntry = PermissionEntry | FsQueryEntry;
|
|
76
|
+
type QueueEntry = PermissionEntry | FsQueryEntry | NetworkQueryEntry;
|
|
59
77
|
|
|
60
78
|
function asRecord(permission: PendingPermission): Record<string, unknown> {
|
|
61
79
|
return permission as unknown as Record<string, unknown>;
|
|
@@ -86,9 +104,13 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
86
104
|
const sessionAllowedWritePaths = new Set<string>();
|
|
87
105
|
const sessionAllowedReadPaths = new Set<string>();
|
|
88
106
|
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
const
|
|
107
|
+
// Targets the user approved "for session": address:port, since the broker
|
|
108
|
+
// knows nothing more specific than that at connect/bind time.
|
|
109
|
+
const sessionAllowedTargets = new Set<string>();
|
|
110
|
+
|
|
111
|
+
// Filesystem and network queries still awaiting a response, so cleanup can
|
|
112
|
+
// release held syscalls instead of letting the child hang.
|
|
113
|
+
const liveQueries = new Set<FsQueryEntry | NetworkQueryEntry>();
|
|
92
114
|
|
|
93
115
|
function pump(): void {
|
|
94
116
|
if (activeId !== undefined) return;
|
|
@@ -96,7 +118,8 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
96
118
|
while (next && resolved.has(next.id)) next = queue.shift();
|
|
97
119
|
if (!next) return;
|
|
98
120
|
if (next.kind === 'permission') showPermission(next.permission);
|
|
99
|
-
else showFsQuery(next);
|
|
121
|
+
else if (next.kind === 'fs-query') showFsQuery(next);
|
|
122
|
+
else showNetworkQuery(next);
|
|
100
123
|
}
|
|
101
124
|
|
|
102
125
|
function enqueueEntry(entry: QueueEntry): void {
|
|
@@ -232,8 +255,8 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
232
255
|
);
|
|
233
256
|
}
|
|
234
257
|
|
|
235
|
-
function
|
|
236
|
-
if (!socket.destroyed) socket.write(
|
|
258
|
+
function respondQuery(socket: NetSocket, queryId: string, action: 'allow' | 'deny'): void {
|
|
259
|
+
if (!socket.destroyed) socket.write(controlResponseLine(queryId, action));
|
|
237
260
|
}
|
|
238
261
|
|
|
239
262
|
function resolveFsQuery(entry: FsQueryEntry, choice: QueryChoice): void {
|
|
@@ -262,7 +285,7 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
262
285
|
}
|
|
263
286
|
}
|
|
264
287
|
|
|
265
|
-
|
|
288
|
+
respondQuery(entry.socket, entry.queryId, action);
|
|
266
289
|
api.ui.toast({
|
|
267
290
|
title: 'Sandbox',
|
|
268
291
|
message:
|
|
@@ -273,7 +296,7 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
273
296
|
});
|
|
274
297
|
} catch {
|
|
275
298
|
// Persisting failed — still release the held syscall by denying it.
|
|
276
|
-
|
|
299
|
+
respondQuery(entry.socket, entry.queryId, 'deny');
|
|
277
300
|
} finally {
|
|
278
301
|
liveQueries.delete(entry);
|
|
279
302
|
finishActive(entry.id);
|
|
@@ -348,6 +371,77 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
348
371
|
);
|
|
349
372
|
}
|
|
350
373
|
|
|
374
|
+
function resolveNetworkQuery(entry: NetworkQueryEntry, choice: NetworkQueryChoice): void {
|
|
375
|
+
if (resolved.has(entry.id)) return;
|
|
376
|
+
const action = choice === 'deny' ? 'deny' : 'allow';
|
|
377
|
+
|
|
378
|
+
try {
|
|
379
|
+
if (action === 'allow' && choice === 'session') sessionAllowedTargets.add(entry.target);
|
|
380
|
+
|
|
381
|
+
respondQuery(entry.socket, entry.queryId, action);
|
|
382
|
+
api.ui.toast({
|
|
383
|
+
title: 'Sandbox',
|
|
384
|
+
message:
|
|
385
|
+
action === 'deny'
|
|
386
|
+
? `${entry.operation} denied: ${entry.target}`
|
|
387
|
+
: `${entry.operation} allowed (${choice}): ${entry.target}`,
|
|
388
|
+
variant: action === 'deny' ? 'warning' : 'success',
|
|
389
|
+
});
|
|
390
|
+
} finally {
|
|
391
|
+
liveQueries.delete(entry);
|
|
392
|
+
finishActive(entry.id);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function showNetworkQuery(entry: NetworkQueryEntry): void {
|
|
397
|
+
activeId = entry.id;
|
|
398
|
+
|
|
399
|
+
void api.attention.notify({
|
|
400
|
+
title: `Sandbox ${entry.operation} blocked`,
|
|
401
|
+
message: entry.target,
|
|
402
|
+
sound: { name: 'permission' },
|
|
403
|
+
notification: true,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Same esc-denies-a-held-syscall reasoning as showFsQuery.
|
|
407
|
+
let selectionMade = false;
|
|
408
|
+
|
|
409
|
+
api.ui.dialog.replace(
|
|
410
|
+
() =>
|
|
411
|
+
api.ui.DialogSelect<NetworkQueryChoice>({
|
|
412
|
+
title: 'Sandbox Network Blocked',
|
|
413
|
+
placeholder: `${entry.operation} blocked: ${entry.target}`,
|
|
414
|
+
options: [
|
|
415
|
+
{
|
|
416
|
+
title: 'Allow once',
|
|
417
|
+
value: 'once',
|
|
418
|
+
category: `This ${entry.operation}`,
|
|
419
|
+
description: `Permit only this ${entry.operation}`,
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
title: 'Allow for session',
|
|
423
|
+
value: 'session',
|
|
424
|
+
category: `This ${entry.operation}`,
|
|
425
|
+
description: `Permit ${entry.target} for this session`,
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
title: 'Deny',
|
|
429
|
+
value: 'deny',
|
|
430
|
+
category: 'Deny',
|
|
431
|
+
description: `Block this ${entry.operation}`,
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
onSelect: (option) => {
|
|
435
|
+
selectionMade = true;
|
|
436
|
+
resolveNetworkQuery(entry, option.value);
|
|
437
|
+
},
|
|
438
|
+
}),
|
|
439
|
+
() => {
|
|
440
|
+
if (!selectionMade) resolveNetworkQuery(entry, 'deny');
|
|
441
|
+
},
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
351
445
|
const unsubscribeAsked = api.event.on('permission.asked', (event) => {
|
|
352
446
|
const pending = event.properties as PendingPermission;
|
|
353
447
|
enqueue(pending);
|
|
@@ -372,7 +466,7 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
372
466
|
sockets.add(socket);
|
|
373
467
|
socket.setEncoding('utf-8');
|
|
374
468
|
const socketId = ++socketSeq;
|
|
375
|
-
const seen = new Set<
|
|
469
|
+
const seen = new Set<string>();
|
|
376
470
|
let buffer = '';
|
|
377
471
|
|
|
378
472
|
socket.on('data', (chunk: string | Buffer) => {
|
|
@@ -388,27 +482,46 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
388
482
|
buffer = buffer.slice(newline + 1);
|
|
389
483
|
|
|
390
484
|
for (const trap of parseLandstripTraps(line)) {
|
|
391
|
-
if (trap.kind !== 'filesystem'
|
|
392
|
-
if (
|
|
393
|
-
seen.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
485
|
+
if (trap.kind !== 'filesystem' && trap.kind !== 'network') continue;
|
|
486
|
+
if (trap.state !== 'query') continue;
|
|
487
|
+
if (seen.has(trap.query_id)) continue;
|
|
488
|
+
seen.add(trap.query_id);
|
|
489
|
+
|
|
490
|
+
if (trap.kind === 'filesystem') {
|
|
491
|
+
const sessionPaths =
|
|
492
|
+
trap.operation === 'read' ? sessionAllowedReadPaths : sessionAllowedWritePaths;
|
|
493
|
+
if (sessionAllows(sessionPaths, trap.path)) {
|
|
494
|
+
respondQuery(socket, trap.query_id, 'allow');
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const entry: FsQueryEntry = {
|
|
499
|
+
kind: 'fs-query',
|
|
500
|
+
id: `landstrip-${trap.operation}:${socketId}:${trap.query_id}`,
|
|
501
|
+
socket,
|
|
502
|
+
queryId: trap.query_id,
|
|
503
|
+
operation: trap.operation,
|
|
504
|
+
path: trap.path,
|
|
505
|
+
};
|
|
506
|
+
liveQueries.add(entry);
|
|
507
|
+
enqueueEntry(entry);
|
|
508
|
+
} else {
|
|
509
|
+
if (sessionAllowedTargets.has(trap.target)) {
|
|
510
|
+
respondQuery(socket, trap.query_id, 'allow');
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const entry: NetworkQueryEntry = {
|
|
515
|
+
kind: 'net-query',
|
|
516
|
+
id: `landstrip-net:${socketId}:${trap.query_id}`,
|
|
517
|
+
socket,
|
|
518
|
+
queryId: trap.query_id,
|
|
519
|
+
operation: trap.operation,
|
|
520
|
+
target: trap.target,
|
|
521
|
+
};
|
|
522
|
+
liveQueries.add(entry);
|
|
523
|
+
enqueueEntry(entry);
|
|
400
524
|
}
|
|
401
|
-
|
|
402
|
-
const entry: FsQueryEntry = {
|
|
403
|
-
kind: 'fs-query',
|
|
404
|
-
id: `landstrip-${trap.operation}:${socketId}:${trap.queryId}`,
|
|
405
|
-
socket,
|
|
406
|
-
queryId: trap.queryId,
|
|
407
|
-
operation: trap.operation,
|
|
408
|
-
path: trap.path,
|
|
409
|
-
};
|
|
410
|
-
liveQueries.add(entry);
|
|
411
|
-
enqueueEntry(entry);
|
|
412
525
|
}
|
|
413
526
|
}
|
|
414
527
|
});
|
|
@@ -555,7 +668,7 @@ const tui: TuiPlugin = async (api, options, meta) => {
|
|
|
555
668
|
// Deny any still-held queries so the sandboxed children don't hang, then
|
|
556
669
|
// tear down the socket server and drop the discovery file.
|
|
557
670
|
for (const entry of liveQueries) {
|
|
558
|
-
|
|
671
|
+
respondQuery(entry.socket, entry.queryId, 'deny');
|
|
559
672
|
liveQueries.delete(entry);
|
|
560
673
|
}
|
|
561
674
|
for (const socket of sockets) socket.destroy();
|
package/landstrip.d.ts
DELETED