@archildata/just-bash 0.1.0 → 0.1.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/{bin/shell.ts → dist/shell.js} +20 -74
- package/package.json +4 -5
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
/**
|
|
3
|
-
* Interactive just-bash shell with Archil filesystem
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* ARCHIL_REGION=aws-us-east-1 ARCHIL_DISK=myaccount/mydisk ARCHIL_TOKEN=xxx npx tsx bin/shell.ts
|
|
7
|
-
*/
|
|
1
|
+
#!/usr/bin/env node
|
|
8
2
|
|
|
3
|
+
// bin/shell.ts
|
|
9
4
|
import * as readline from "readline";
|
|
10
5
|
import { ArchilClient } from "@archildata/client";
|
|
11
6
|
import { Bash } from "just-bash";
|
|
12
|
-
import { ArchilFs } from "
|
|
13
|
-
|
|
7
|
+
import { ArchilFs } from "@archildata/just-bash";
|
|
14
8
|
async function main() {
|
|
15
9
|
const region = process.env.ARCHIL_REGION;
|
|
16
10
|
const diskName = process.env.ARCHIL_DISK;
|
|
17
11
|
const authToken = process.env.ARCHIL_TOKEN;
|
|
18
|
-
const logLevel = process.env.ARCHIL_LOG_LEVEL;
|
|
19
|
-
|
|
12
|
+
const logLevel = process.env.ARCHIL_LOG_LEVEL;
|
|
20
13
|
if (!region || !diskName) {
|
|
21
14
|
console.error("Missing required environment variables:");
|
|
22
15
|
console.error(" ARCHIL_REGION - e.g., aws-us-east-1");
|
|
@@ -31,7 +24,6 @@ async function main() {
|
|
|
31
24
|
console.error(" ARCHIL_LOG_LEVEL=debug ARCHIL_REGION=... ARCHIL_DISK=... npx tsx bin/shell.ts");
|
|
32
25
|
process.exit(1);
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
console.log("Connecting to Archil...");
|
|
36
28
|
console.log(` Region: ${region}`);
|
|
37
29
|
console.log(` Disk: ${diskName}`);
|
|
@@ -40,57 +32,44 @@ async function main() {
|
|
|
40
32
|
console.log(` Log level: ${logLevel}`);
|
|
41
33
|
}
|
|
42
34
|
console.log("");
|
|
43
|
-
|
|
44
|
-
let client: ArchilClient;
|
|
35
|
+
let client;
|
|
45
36
|
try {
|
|
46
37
|
client = await ArchilClient.connect({
|
|
47
38
|
region,
|
|
48
39
|
diskName,
|
|
49
|
-
authToken: authToken ||
|
|
50
|
-
logLevel
|
|
40
|
+
authToken: authToken || void 0,
|
|
41
|
+
logLevel
|
|
51
42
|
});
|
|
52
43
|
console.log("Connected!");
|
|
53
44
|
} catch (err) {
|
|
54
45
|
console.error("Failed to connect:", err instanceof Error ? err.message : err);
|
|
55
46
|
process.exit(1);
|
|
56
47
|
}
|
|
57
|
-
|
|
58
|
-
// Create filesystem adapter
|
|
59
48
|
const fs = new ArchilFs(client);
|
|
60
|
-
|
|
61
|
-
// Create bash environment
|
|
62
49
|
const bash = new Bash({ fs });
|
|
63
|
-
|
|
64
|
-
// Cleanup function to release delegations and close connection
|
|
65
50
|
let cleaningUp = false;
|
|
66
|
-
const cleanup = async (signal
|
|
51
|
+
const cleanup = async (signal) => {
|
|
67
52
|
if (cleaningUp) return;
|
|
68
53
|
cleaningUp = true;
|
|
69
|
-
|
|
70
54
|
if (signal) {
|
|
71
|
-
console.log(
|
|
55
|
+
console.log(`
|
|
56
|
+
Received ${signal}, cleaning up...`);
|
|
72
57
|
} else {
|
|
73
58
|
console.log("\nGoodbye!");
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
try {
|
|
77
|
-
// close() releases all delegations and cleans up resources
|
|
78
61
|
const released = await client.close();
|
|
79
62
|
if (released > 0) {
|
|
80
|
-
console.log(`Released ${released} delegation${released > 1 ?
|
|
63
|
+
console.log(`Released ${released} delegation${released > 1 ? "s" : ""}`);
|
|
81
64
|
}
|
|
82
65
|
} catch (err) {
|
|
83
66
|
console.error("Error during cleanup:", err instanceof Error ? err.message : err);
|
|
84
67
|
}
|
|
85
|
-
|
|
86
68
|
process.exit(0);
|
|
87
69
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
process.on(
|
|
91
|
-
process.on('SIGTERM', () => cleanup('SIGTERM'));
|
|
92
|
-
process.on('SIGHUP', () => cleanup('SIGHUP'));
|
|
93
|
-
|
|
70
|
+
process.on("SIGINT", () => cleanup("SIGINT"));
|
|
71
|
+
process.on("SIGTERM", () => cleanup("SIGTERM"));
|
|
72
|
+
process.on("SIGHUP", () => cleanup("SIGHUP"));
|
|
94
73
|
console.log("");
|
|
95
74
|
console.log("=== Archil just-bash shell ===");
|
|
96
75
|
console.log("Type bash commands to interact with the filesystem.");
|
|
@@ -101,47 +80,34 @@ async function main() {
|
|
|
101
80
|
console.log(" archil help - Show archil commands");
|
|
102
81
|
console.log("Type 'exit' or Ctrl+D to quit.");
|
|
103
82
|
console.log("");
|
|
104
|
-
|
|
105
|
-
// Create readline interface for interactive input
|
|
106
83
|
const rl = readline.createInterface({
|
|
107
84
|
input: process.stdin,
|
|
108
85
|
output: process.stdout,
|
|
109
|
-
prompt: "archil$ "
|
|
86
|
+
prompt: "archil$ "
|
|
110
87
|
});
|
|
111
|
-
|
|
112
88
|
let cwd = "/";
|
|
113
|
-
|
|
114
89
|
const prompt = () => {
|
|
115
90
|
rl.setPrompt(`archil:${cwd}$ `);
|
|
116
91
|
rl.prompt();
|
|
117
92
|
};
|
|
118
|
-
|
|
119
93
|
prompt();
|
|
120
|
-
|
|
121
|
-
// Helper to resolve a path relative to cwd
|
|
122
|
-
const resolvePath = (path: string): string => {
|
|
94
|
+
const resolvePath = (path) => {
|
|
123
95
|
if (path.startsWith("/")) {
|
|
124
96
|
return path;
|
|
125
97
|
}
|
|
126
98
|
return cwd === "/" ? "/" + path : cwd + "/" + path;
|
|
127
99
|
};
|
|
128
|
-
|
|
129
|
-
// Handle archil checkout/checkin commands
|
|
130
|
-
const handleArchilCommand = async (command: string): Promise<boolean> => {
|
|
100
|
+
const handleArchilCommand = async (command) => {
|
|
131
101
|
const parts = command.split(/\s+/);
|
|
132
102
|
if (parts[0] !== "archil") {
|
|
133
103
|
return false;
|
|
134
104
|
}
|
|
135
|
-
|
|
136
105
|
const subcommand = parts[1];
|
|
137
106
|
const targetPath = parts[2];
|
|
138
|
-
|
|
139
107
|
if (subcommand === "checkout") {
|
|
140
|
-
// Parse flags and path
|
|
141
108
|
const args = parts.slice(2);
|
|
142
109
|
const force = args.includes("--force") || args.includes("-f");
|
|
143
|
-
const pathArg = args.find(a => !a.startsWith("-"));
|
|
144
|
-
|
|
110
|
+
const pathArg = args.find((a) => !a.startsWith("-"));
|
|
145
111
|
if (!pathArg) {
|
|
146
112
|
console.error("Usage: archil checkout [--force|-f] <path>");
|
|
147
113
|
return true;
|
|
@@ -156,7 +122,6 @@ async function main() {
|
|
|
156
122
|
}
|
|
157
123
|
return true;
|
|
158
124
|
}
|
|
159
|
-
|
|
160
125
|
if (subcommand === "checkin") {
|
|
161
126
|
if (!targetPath) {
|
|
162
127
|
console.error("Usage: archil checkin <path>");
|
|
@@ -172,7 +137,6 @@ async function main() {
|
|
|
172
137
|
}
|
|
173
138
|
return true;
|
|
174
139
|
}
|
|
175
|
-
|
|
176
140
|
if (subcommand === "list-delegations" || subcommand === "delegations") {
|
|
177
141
|
try {
|
|
178
142
|
const delegations = client.listDelegations();
|
|
@@ -189,7 +153,6 @@ async function main() {
|
|
|
189
153
|
}
|
|
190
154
|
return true;
|
|
191
155
|
}
|
|
192
|
-
|
|
193
156
|
if (subcommand === "help" || !subcommand) {
|
|
194
157
|
console.log("Archil commands:");
|
|
195
158
|
console.log(" archil checkout [--force|-f] <path> - Acquire write delegation");
|
|
@@ -200,48 +163,36 @@ async function main() {
|
|
|
200
163
|
console.log("The --force flag revokes any existing delegation from other clients.");
|
|
201
164
|
return true;
|
|
202
165
|
}
|
|
203
|
-
|
|
204
166
|
console.error(`Unknown archil command: ${subcommand}`);
|
|
205
167
|
console.error("Run 'archil help' for available commands");
|
|
206
168
|
return true;
|
|
207
169
|
};
|
|
208
|
-
|
|
209
170
|
rl.on("line", async (line) => {
|
|
210
171
|
const trimmed = line.trim();
|
|
211
|
-
|
|
212
172
|
if (trimmed === "exit" || trimmed === "quit") {
|
|
213
173
|
await cleanup();
|
|
214
174
|
return;
|
|
215
175
|
}
|
|
216
|
-
|
|
217
176
|
if (!trimmed) {
|
|
218
177
|
prompt();
|
|
219
178
|
return;
|
|
220
179
|
}
|
|
221
|
-
|
|
222
|
-
// Pause readline while we process the command
|
|
223
180
|
rl.pause();
|
|
224
|
-
|
|
225
181
|
try {
|
|
226
|
-
// Check for archil commands first
|
|
227
182
|
if (trimmed.startsWith("archil")) {
|
|
228
183
|
await handleArchilCommand(trimmed);
|
|
229
184
|
rl.resume();
|
|
230
185
|
prompt();
|
|
231
186
|
return;
|
|
232
187
|
}
|
|
233
|
-
|
|
234
|
-
// Execute command with current working directory
|
|
235
188
|
const result = await bash.exec(trimmed, {
|
|
236
189
|
cwd,
|
|
237
190
|
env: {
|
|
238
191
|
HOME: "/",
|
|
239
192
|
USER: "archil",
|
|
240
|
-
PWD: cwd
|
|
241
|
-
}
|
|
193
|
+
PWD: cwd
|
|
194
|
+
}
|
|
242
195
|
});
|
|
243
|
-
|
|
244
|
-
// Print output
|
|
245
196
|
if (result.stdout) {
|
|
246
197
|
process.stdout.write(result.stdout);
|
|
247
198
|
if (!result.stdout.endsWith("\n")) {
|
|
@@ -254,22 +205,17 @@ async function main() {
|
|
|
254
205
|
console.error("");
|
|
255
206
|
}
|
|
256
207
|
}
|
|
257
|
-
|
|
258
|
-
// Update cwd if command changed it
|
|
259
208
|
if (result.env?.PWD && result.env.PWD !== cwd) {
|
|
260
209
|
cwd = result.env.PWD;
|
|
261
210
|
}
|
|
262
211
|
} catch (err) {
|
|
263
212
|
console.error("Error:", err instanceof Error ? err.message : err);
|
|
264
213
|
}
|
|
265
|
-
|
|
266
214
|
rl.resume();
|
|
267
215
|
prompt();
|
|
268
216
|
});
|
|
269
|
-
|
|
270
217
|
rl.on("close", () => cleanup());
|
|
271
218
|
}
|
|
272
|
-
|
|
273
219
|
main().catch((err) => {
|
|
274
220
|
console.error("Fatal error:", err);
|
|
275
221
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archildata/just-bash",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Archil filesystem adapter for just-bash",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"archil-shell": "./
|
|
16
|
+
"archil-shell": "./dist/shell.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
"bin"
|
|
19
|
+
"dist"
|
|
21
20
|
],
|
|
22
21
|
"scripts": {
|
|
23
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
22
|
+
"build": "tsup src/index.ts --format cjs,esm --dts && tsup bin/shell.ts --format esm --outDir dist --no-splitting --external @archildata/just-bash",
|
|
24
23
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
25
24
|
"lint": "eslint src/",
|
|
26
25
|
"typecheck": "tsc --noEmit",
|