@lamplitisles/dsh-nanocodex 0.1.0-beta.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 +65 -0
- package/NOTICE +2 -0
- package/README.md +182 -0
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/cordis.patch.yml +52 -0
- package/dist/index.d.ts +435 -0
- package/dist/index.js +3405 -0
- package/dist/standard-preset.d.ts +7 -0
- package/dist/standard-preset.js +25 -0
- package/engine-release.json +14 -0
- package/package.json +119 -0
- package/presets/standard/agent.cordis.yml +6 -0
- package/presets/standard/preset.yml +2 -0
- package/vendor/nanocodex/README.md +1344 -0
- package/vendor/nanocodex/actions/events.d.mts +10 -0
- package/vendor/nanocodex/actions/events.mjs +163 -0
- package/vendor/nanocodex/actions/index.d.mts +13 -0
- package/vendor/nanocodex/actions/index.mjs +35 -0
- package/vendor/nanocodex/actions/session.d.mts +66 -0
- package/vendor/nanocodex/actions/session.mjs +59 -0
- package/vendor/nanocodex/actions/turn.d.mts +59 -0
- package/vendor/nanocodex/actions/turn.mjs +37 -0
- package/vendor/nanocodex/actions/voice.d.mts +22 -0
- package/vendor/nanocodex/actions/voice.mjs +50 -0
- package/vendor/nanocodex/browser/Agent.d.mts +55 -0
- package/vendor/nanocodex/browser/Agent.mjs +11 -0
- package/vendor/nanocodex/browser/ChatGptSubscription.d.mts +7 -0
- package/vendor/nanocodex/browser/ChatGptSubscription.mjs +19 -0
- package/vendor/nanocodex/browser/InlineAgent.mjs +266 -0
- package/vendor/nanocodex/browser/Transport.d.mts +74 -0
- package/vendor/nanocodex/browser/Transport.mjs +61 -0
- package/vendor/nanocodex/browser/Voice.d.mts +71 -0
- package/vendor/nanocodex/browser/Voice.mjs +291 -0
- package/vendor/nanocodex/browser/VoiceSession.mjs +688 -0
- package/vendor/nanocodex/browser/WorkerAgent.d.mts +65 -0
- package/vendor/nanocodex/browser/WorkerAgent.mjs +1472 -0
- package/vendor/nanocodex/browser/agent.worker.mjs +3 -0
- package/vendor/nanocodex/browser/config.d.mts +36 -0
- package/vendor/nanocodex/browser/config.mjs +439 -0
- package/vendor/nanocodex/browser/engine.mjs +13 -0
- package/vendor/nanocodex/browser/harness.mjs +55 -0
- package/vendor/nanocodex/browser/host.d.mts +83 -0
- package/vendor/nanocodex/browser/host.mjs +555 -0
- package/vendor/nanocodex/browser/hostManagedWebSocket.d.mts +14 -0
- package/vendor/nanocodex/browser/hostManagedWebSocket.mjs +110 -0
- package/vendor/nanocodex/browser/index.d.mts +92 -0
- package/vendor/nanocodex/browser/index.mjs +23 -0
- package/vendor/nanocodex/browser/indexeddb-durability-store.mjs +197 -0
- package/vendor/nanocodex/browser/workspace.d.mts +16 -0
- package/vendor/nanocodex/browser/workspace.mjs +107 -0
- package/vendor/nanocodex/cloud/Client.d.mts +83 -0
- package/vendor/nanocodex/cloud/Client.mjs +231 -0
- package/vendor/nanocodex/cloud/Decorator.d.mts +31 -0
- package/vendor/nanocodex/cloud/Decorator.mjs +37 -0
- package/vendor/nanocodex/cloud/Dialog.d.mts +113 -0
- package/vendor/nanocodex/cloud/Dialog.mjs +366 -0
- package/vendor/nanocodex/cloud/Errors.d.mts +22 -0
- package/vendor/nanocodex/cloud/Errors.mjs +39 -0
- package/vendor/nanocodex/cloud/Principal.d.mts +26 -0
- package/vendor/nanocodex/cloud/Principal.mjs +88 -0
- package/vendor/nanocodex/cloud/RemoteProvider.mjs +88 -0
- package/vendor/nanocodex/cloud/Transport.d.mts +47 -0
- package/vendor/nanocodex/cloud/Transport.mjs +454 -0
- package/vendor/nanocodex/cloud/actions/account.d.mts +9 -0
- package/vendor/nanocodex/cloud/actions/account.mjs +19 -0
- package/vendor/nanocodex/cloud/actions/agent.d.mts +18 -0
- package/vendor/nanocodex/cloud/actions/agent.mjs +428 -0
- package/vendor/nanocodex/cloud/actions/connection.d.mts +133 -0
- package/vendor/nanocodex/cloud/actions/connection.mjs +580 -0
- package/vendor/nanocodex/cloud/actions/grant.d.mts +10 -0
- package/vendor/nanocodex/cloud/actions/grant.mjs +12 -0
- package/vendor/nanocodex/cloud/actions/index.d.mts +7 -0
- package/vendor/nanocodex/cloud/actions/index.mjs +7 -0
- package/vendor/nanocodex/cloud/actions/machineUsd.d.mts +23 -0
- package/vendor/nanocodex/cloud/actions/machineUsd.mjs +37 -0
- package/vendor/nanocodex/cloud/actions/model.d.mts +12 -0
- package/vendor/nanocodex/cloud/actions/model.mjs +50 -0
- package/vendor/nanocodex/cloud/actions/mpp.d.mts +28 -0
- package/vendor/nanocodex/cloud/actions/mpp.mjs +39 -0
- package/vendor/nanocodex/cloud/index.d.mts +30 -0
- package/vendor/nanocodex/cloud/index.mjs +9 -0
- package/vendor/nanocodex/cloud/internal.mjs +533 -0
- package/vendor/nanocodex/cloud/mercator.mjs +108 -0
- package/vendor/nanocodex/cloud/server/HostPrincipal.d.mts +34 -0
- package/vendor/nanocodex/cloud/server/HostPrincipal.mjs +202 -0
- package/vendor/nanocodex/cloud/server/index.d.mts +1 -0
- package/vendor/nanocodex/cloud/server/index.mjs +1 -0
- package/vendor/nanocodex/cloud/types.d.mts +211 -0
- package/vendor/nanocodex/cloudflare/Agent.d.mts +133 -0
- package/vendor/nanocodex/cloudflare/Agent.mjs +811 -0
- package/vendor/nanocodex/cloudflare/egress-subject.mjs +19 -0
- package/vendor/nanocodex/cloudflare/egress.d.mts +41 -0
- package/vendor/nanocodex/cloudflare/egress.mjs +119 -0
- package/vendor/nanocodex/cloudflare/event-socket.mjs +316 -0
- package/vendor/nanocodex/cloudflare/index.d.mts +7 -0
- package/vendor/nanocodex/cloudflare/index.mjs +6 -0
- package/vendor/nanocodex/host/Agent.d.mts +55 -0
- package/vendor/nanocodex/host/Agent.mjs +1 -0
- package/vendor/nanocodex/host/index.d.mts +82 -0
- package/vendor/nanocodex/host/index.mjs +10 -0
- package/vendor/nanocodex/index.d.mts +81 -0
- package/vendor/nanocodex/index.mjs +12 -0
- package/vendor/nanocodex/internal.mjs +1275 -0
- package/vendor/nanocodex/managed/Agent.d.mts +380 -0
- package/vendor/nanocodex/managed/Agent.mjs +1694 -0
- package/vendor/nanocodex/managed/ManagedError.d.mts +9 -0
- package/vendor/nanocodex/managed/ManagedError.mjs +8 -0
- package/vendor/nanocodex/managed/README.md +241 -0
- package/vendor/nanocodex/managed/Voice.mjs +202 -0
- package/vendor/nanocodex/managed/index.d.mts +20 -0
- package/vendor/nanocodex/managed/index.mjs +2 -0
- package/vendor/nanocodex/managed/internal.mjs +119 -0
- package/vendor/nanocodex/node/Agent.d.mts +50 -0
- package/vendor/nanocodex/node/Agent.mjs +203 -0
- package/vendor/nanocodex/node/ChatGptSubscription.d.mts +9 -0
- package/vendor/nanocodex/node/ChatGptSubscription.mjs +17 -0
- package/vendor/nanocodex/node/Transport.d.mts +44 -0
- package/vendor/nanocodex/node/Transport.mjs +46 -0
- package/vendor/nanocodex/node/host.mjs +731 -0
- package/vendor/nanocodex/node/index.d.mts +73 -0
- package/vendor/nanocodex/node/index.mjs +17 -0
- package/vendor/nanocodex/node/workspace.d.mts +10 -0
- package/vendor/nanocodex/node/workspace.mjs +198 -0
- package/vendor/nanocodex/package.json +200 -0
- package/vendor/nanocodex/pkg-node/nanocodex.d.ts +675 -0
- package/vendor/nanocodex/pkg-node/nanocodex.js +2628 -0
- package/vendor/nanocodex/pkg-node/nanocodex_bg.wasm.d.ts +105 -0
- package/vendor/nanocodex/pkg-node/package.json +1 -0
- package/vendor/nanocodex/pkg-web/.nanocodex-bindgen-stamp +6 -0
- package/vendor/nanocodex/pkg-web/nanocodex-build.json +1 -0
- package/vendor/nanocodex/pkg-web/nanocodex.d.ts +805 -0
- package/vendor/nanocodex/pkg-web/nanocodex.js +2714 -0
- package/vendor/nanocodex/pkg-web/nanocodex_bg.js +2615 -0
- package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm +0 -0
- package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm.d.ts +105 -0
- package/vendor/nanocodex/pkg-web/nanocodex_worker.js +9 -0
- package/vendor/nanocodex/pkg-web/package.json +1 -0
- package/vendor/nanocodex/runtime/chatgpt-subscription.mjs +212 -0
- package/vendor/nanocodex/runtime/cloudflare-durability-store.d.mts +26 -0
- package/vendor/nanocodex/runtime/cloudflare-durability-store.mjs +168 -0
- package/vendor/nanocodex/runtime/code-evaluator.worker.mjs +137 -0
- package/vendor/nanocodex/runtime/code-runtime.mjs +1 -0
- package/vendor/nanocodex/runtime/durability-store.d.mts +85 -0
- package/vendor/nanocodex/runtime/durability-store.mjs +631 -0
- package/vendor/nanocodex/runtime/durability.mjs +153 -0
- package/vendor/nanocodex/runtime/managed-transport.mjs +460 -0
- package/vendor/nanocodex/runtime/mcp-runtime.mjs +534 -0
- package/vendor/nanocodex/runtime/postgres-durability-store.d.mts +64 -0
- package/vendor/nanocodex/runtime/postgres-durability-store.mjs +532 -0
- package/vendor/nanocodex/runtime/quickjs-evaluator.d.mts +17 -0
- package/vendor/nanocodex/runtime/quickjs-evaluator.mjs +236 -0
- package/vendor/nanocodex/runtime/responses-transport.mjs +22 -0
- package/vendor/nanocodex/runtime/subagents.d.mts +107 -0
- package/vendor/nanocodex/runtime/subagents.mjs +54 -0
- package/vendor/nanocodex/runtime/subscription-store.d.mts +8 -0
- package/vendor/nanocodex/runtime/subscription-store.mjs +42 -0
- package/vendor/nanocodex/runtime/tempo-provider.d.mts +125 -0
- package/vendor/nanocodex/runtime/tempo-provider.mjs +264 -0
- package/vendor/nanocodex/runtime/tool-configuration.mjs +1 -0
- package/vendor/nanocodex/runtime/tool-router.mjs +1 -0
- package/vendor/nanocodex/runtime/utf8.mjs +1 -0
- package/vendor/nanocodex/runtime/worker-evaluator.mjs +162 -0
- package/vendor/nanocodex/runtime/workspace.d.mts +1 -0
- package/vendor/nanocodex/runtime/workspace.mjs +1 -0
- package/vendor/nanocodex/tools/Tools.d.mts +56 -0
- package/vendor/nanocodex/tools/Tools.mjs +136 -0
- package/vendor/nanocodex/tools/artifact.d.mts +1 -0
- package/vendor/nanocodex/tools/artifact.mjs +1 -0
- package/vendor/nanocodex/tools/attachment.mjs +1 -0
- package/vendor/nanocodex/tools/bash.d.mts +1 -0
- package/vendor/nanocodex/tools/bash.mjs +1 -0
- package/vendor/nanocodex/tools/browser/accountInfo.mjs +795 -0
- package/vendor/nanocodex/tools/browser/browserBuffer.mjs +18 -0
- package/vendor/nanocodex/tools/browser/browserCompiler.mjs +155 -0
- package/vendor/nanocodex/tools/browser/browserEgress.mjs +161 -0
- package/vendor/nanocodex/tools/browser/browserPython.mjs +133 -0
- package/vendor/nanocodex/tools/browser/browserShell.mjs +1075 -0
- package/vendor/nanocodex/tools/browser/browserSprintf.mjs +4 -0
- package/vendor/nanocodex/tools/browser/browserSsh.mjs +201 -0
- package/vendor/nanocodex/tools/browser/browserZlib.mjs +136 -0
- package/vendor/nanocodex/tools/browser/compiler.worker.mjs +160 -0
- package/vendor/nanocodex/tools/browser/devTunnelsSshBrowser.mjs +13 -0
- package/vendor/nanocodex/tools/browser/index.d.mts +209 -0
- package/vendor/nanocodex/tools/browser/index.mjs +174 -0
- package/vendor/nanocodex/tools/browser/opfsGit.mjs +248 -0
- package/vendor/nanocodex/tools/browser/python.worker.mjs +114 -0
- package/vendor/nanocodex/tools/browser/threadGit.mjs +197 -0
- package/vendor/nanocodex/tools/browser/unsupportedNodeRsa.mjs +5 -0
- package/vendor/nanocodex/tools/browser/workspace.mjs +83 -0
- package/vendor/nanocodex/tools/dataset.d.mts +1 -0
- package/vendor/nanocodex/tools/dataset.mjs +1 -0
- package/vendor/nanocodex/tools/datasetContract.mjs +1 -0
- package/vendor/nanocodex/tools/datasetEngine.mjs +1 -0
- package/vendor/nanocodex/tools/hostedCatalog.d.mts +1 -0
- package/vendor/nanocodex/tools/hostedCatalog.mjs +1 -0
- package/vendor/nanocodex/tools/index.d.mts +49 -0
- package/vendor/nanocodex/tools/index.mjs +19 -0
- package/vendor/nanocodex/tools/namedTool.mjs +1 -0
- package/vendor/nanocodex/tools/repository-workspace.d.mts +1 -0
- package/vendor/nanocodex/tools/repository-workspace.mjs +1 -0
- package/vendor/nanocodex/tools/ssh.d.mts +1 -0
- package/vendor/nanocodex/tools/ssh.mjs +1 -0
- package/vendor/nanocodex/tools/standard.mjs +1 -0
- package/vendor/nanocodex/tools/standardDescriptions.mjs +1 -0
- package/vendor/nanocodex/types.d.mts +663 -0
- package/vendor/nanocodex/wasm.d.mts +4 -0
- package/vendor/nanocodex/worker/ChatGptSubscription.d.mts +9 -0
- package/vendor/nanocodex/worker/ChatGptSubscription.mjs +29 -0
- package/vendor/nanocodex/worker/index.d.mts +18 -0
- package/vendor/nanocodex/worker/index.mjs +5 -0
- package/vendor/nanocodex-tools/README.md +65 -0
- package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.d.ts +7 -0
- package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.js +14 -0
- package/vendor/nanocodex-tools/dist/hosted/broker-core.d.ts +172 -0
- package/vendor/nanocodex-tools/dist/hosted/broker-core.js +1278 -0
- package/vendor/nanocodex-tools/dist/hosted/index.d.ts +3 -0
- package/vendor/nanocodex-tools/dist/hosted/index.js +3 -0
- package/vendor/nanocodex-tools/dist/hosted/protocol.d.ts +120 -0
- package/vendor/nanocodex-tools/dist/hosted/protocol.js +415 -0
- package/vendor/nanocodex-tools/dist/index.d.ts +19 -0
- package/vendor/nanocodex-tools/dist/index.js +14 -0
- package/vendor/nanocodex-tools/dist/memory.d.ts +204 -0
- package/vendor/nanocodex-tools/dist/memory.js +411 -0
- package/vendor/nanocodex-tools/dist/namespace.d.ts +87 -0
- package/vendor/nanocodex-tools/dist/namespace.js +338 -0
- package/vendor/nanocodex-tools/dist/repository-archive.d.ts +4 -0
- package/vendor/nanocodex-tools/dist/repository-archive.js +104 -0
- package/vendor/nanocodex-tools/dist/runtime.d.ts +30 -0
- package/vendor/nanocodex-tools/dist/runtime.js +37 -0
- package/vendor/nanocodex-tools/dist/session.d.ts +167 -0
- package/vendor/nanocodex-tools/dist/session.js +286 -0
- package/vendor/nanocodex-tools/dist/shell.d.ts +51 -0
- package/vendor/nanocodex-tools/dist/shell.js +553 -0
- package/vendor/nanocodex-tools/dist/ssh.d.ts +29 -0
- package/vendor/nanocodex-tools/dist/ssh.js +66 -0
- package/vendor/nanocodex-tools/dist/workspace.d.ts +45 -0
- package/vendor/nanocodex-tools/dist/workspace.js +237 -0
- package/vendor/nanocodex-tools/package.json +122 -0
- package/vendor/nanocodex-tools/runtime/code-runtime.mjs +817 -0
- package/vendor/nanocodex-tools/runtime/tool-configuration.mjs +50 -0
- package/vendor/nanocodex-tools/runtime/tool-router.mjs +730 -0
- package/vendor/nanocodex-tools/runtime/utf8.d.mts +2 -0
- package/vendor/nanocodex-tools/runtime/utf8.mjs +25 -0
- package/vendor/nanocodex-tools/tools/artifact.d.mts +69 -0
- package/vendor/nanocodex-tools/tools/artifact.mjs +270 -0
- package/vendor/nanocodex-tools/tools/attachment.mjs +603 -0
- package/vendor/nanocodex-tools/tools/bash.d.mts +90 -0
- package/vendor/nanocodex-tools/tools/bash.mjs +742 -0
- package/vendor/nanocodex-tools/tools/dataset.d.mts +9 -0
- package/vendor/nanocodex-tools/tools/dataset.mjs +47 -0
- package/vendor/nanocodex-tools/tools/datasetContract.mjs +54 -0
- package/vendor/nanocodex-tools/tools/datasetEngine.mjs +1167 -0
- package/vendor/nanocodex-tools/tools/execution-contract.d.mts +5 -0
- package/vendor/nanocodex-tools/tools/execution-contract.mjs +63 -0
- package/vendor/nanocodex-tools/tools/hostedCatalog.d.mts +20 -0
- package/vendor/nanocodex-tools/tools/hostedCatalog.mjs +67 -0
- package/vendor/nanocodex-tools/tools/hostedMachine.d.mts +10 -0
- package/vendor/nanocodex-tools/tools/hostedMachine.mjs +56 -0
- package/vendor/nanocodex-tools/tools/just-bash-browser.d.mts +1 -0
- package/vendor/nanocodex-tools/tools/just-bash-browser.mjs +1 -0
- package/vendor/nanocodex-tools/tools/namedTool.d.mts +3 -0
- package/vendor/nanocodex-tools/tools/namedTool.mjs +3 -0
- package/vendor/nanocodex-tools/tools/nodeProcess.d.mts +10 -0
- package/vendor/nanocodex-tools/tools/nodeProcess.mjs +314 -0
- package/vendor/nanocodex-tools/tools/processOutput.mjs +56 -0
- package/vendor/nanocodex-tools/tools/repository-workspace.d.mts +55 -0
- package/vendor/nanocodex-tools/tools/repository-workspace.mjs +397 -0
- package/vendor/nanocodex-tools/tools/ssh.d.mts +56 -0
- package/vendor/nanocodex-tools/tools/ssh.mjs +503 -0
- package/vendor/nanocodex-tools/tools/standard.mjs +458 -0
- package/vendor/nanocodex-tools/tools/standardDescriptions.mjs +3 -0
- package/vendor/nanocodex-tools/tools/types.d.mts +83 -0
- package/vendor/nanocodex-tools/tools/workspace.d.mts +25 -0
- package/vendor/nanocodex-tools/tools/workspace.mjs +282 -0
- package/vendor/nanocodex-tools/tools/x.d.mts +30 -0
- package/vendor/nanocodex-tools/tools/x.mjs +91 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Workspace } from "../tools/types.mjs";
|
|
2
|
+
type ComputerDirent = Readonly<{
|
|
3
|
+
name: string;
|
|
4
|
+
size: number;
|
|
5
|
+
mtime: number;
|
|
6
|
+
isFile: boolean;
|
|
7
|
+
isDirectory: boolean;
|
|
8
|
+
isSymbolicLink: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
type ComputerStat = Readonly<{
|
|
11
|
+
size: number;
|
|
12
|
+
isFile: boolean;
|
|
13
|
+
isDirectory: boolean;
|
|
14
|
+
isSymbolicLink: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
/** Minimal storage interface needed to expose a persistent Nanocodex workspace. */
|
|
17
|
+
export type WorkspaceStorageClient = Readonly<{
|
|
18
|
+
fs: {
|
|
19
|
+
lstat(path: string): Promise<ComputerStat>;
|
|
20
|
+
readdir(path: string, options?: {
|
|
21
|
+
limit?: number | undefined;
|
|
22
|
+
offset?: number | undefined;
|
|
23
|
+
}): Promise<ComputerDirent[]>;
|
|
24
|
+
readFile(path: string, options?: {
|
|
25
|
+
byteOffset?: number | undefined;
|
|
26
|
+
byteLength?: number | undefined;
|
|
27
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
28
|
+
writeFile(path: string, contents: Uint8Array): Promise<void>;
|
|
29
|
+
mkdir(path: string, options?: {
|
|
30
|
+
recursive?: boolean | undefined;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
rm(path: string, options?: {
|
|
33
|
+
recursive?: boolean | undefined;
|
|
34
|
+
force?: boolean | undefined;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Adapts a persistent filesystem client to Nanocodex's host-generic workspace
|
|
40
|
+
* contract. Callers mount the returned handle into a bounded tool runtime.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createWorkspaceFilesystem(workspace: WorkspaceStorageClient, options?: {
|
|
43
|
+
maxFileBytes?: number | undefined;
|
|
44
|
+
}): Promise<Workspace>;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
const ROOT = "/workspace";
|
|
2
|
+
const DEFAULT_MAX_ENTRIES = Infinity;
|
|
3
|
+
const DEFAULT_MAX_FILE_BYTES = Infinity;
|
|
4
|
+
/**
|
|
5
|
+
* Adapts a persistent filesystem client to Nanocodex's host-generic workspace
|
|
6
|
+
* contract. Callers mount the returned handle into a bounded tool runtime.
|
|
7
|
+
*/
|
|
8
|
+
export async function createWorkspaceFilesystem(workspace, options = {}) {
|
|
9
|
+
const maxFileBytes = positiveInteger(options.maxFileBytes, DEFAULT_MAX_FILE_BYTES, "maxFileBytes");
|
|
10
|
+
await ensureRoot(workspace.fs);
|
|
11
|
+
return createFilesystem(workspace.fs, maxFileBytes);
|
|
12
|
+
}
|
|
13
|
+
function createFilesystem(fs, maxFileBytes) {
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
root: ROOT,
|
|
16
|
+
async list(path = ".", options = {}) {
|
|
17
|
+
const directory = resolvePath(path);
|
|
18
|
+
const recursive = options.recursive === true;
|
|
19
|
+
const maxEntries = positiveInteger(options.maxEntries, DEFAULT_MAX_ENTRIES, "maxEntries");
|
|
20
|
+
await requireSafePath(fs, directory, "directory");
|
|
21
|
+
const entries = [];
|
|
22
|
+
const pending = [directory];
|
|
23
|
+
while (pending.length > 0) {
|
|
24
|
+
const current = pending.shift();
|
|
25
|
+
let offset = 0;
|
|
26
|
+
for (;;) {
|
|
27
|
+
const children = await fs.readdir(current, { limit: 1_000, offset });
|
|
28
|
+
if (!children.length)
|
|
29
|
+
break;
|
|
30
|
+
for (const child of children) {
|
|
31
|
+
const childPath = resolveChild(current, child.name);
|
|
32
|
+
requireSupportedEntry(child, childPath);
|
|
33
|
+
entries.push(Object.freeze({
|
|
34
|
+
kind: child.isDirectory ? "directory" : "file",
|
|
35
|
+
modifiedAt: child.mtime,
|
|
36
|
+
path: childPath,
|
|
37
|
+
...(child.isFile ? { size: child.size } : {}),
|
|
38
|
+
}));
|
|
39
|
+
if (entries.length > maxEntries)
|
|
40
|
+
throw new RangeError(`workspace listing exceeds ${maxEntries} entries`);
|
|
41
|
+
if (recursive && child.isDirectory)
|
|
42
|
+
pending.push(childPath);
|
|
43
|
+
}
|
|
44
|
+
offset += children.length;
|
|
45
|
+
}
|
|
46
|
+
if (!recursive)
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return entries.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
50
|
+
},
|
|
51
|
+
async readFile(path) {
|
|
52
|
+
const target = resolvePath(path);
|
|
53
|
+
const stat = await requireSafePath(fs, target, "file");
|
|
54
|
+
if (stat.size > maxFileBytes) {
|
|
55
|
+
throw new RangeError(`workspace file exceeds the ${maxFileBytes}-byte read bound`);
|
|
56
|
+
}
|
|
57
|
+
const stream = await fs.readFile(target, { byteOffset: 0, byteLength: stat.size + 1 });
|
|
58
|
+
return readExactlyBounded(stream, stat.size, maxFileBytes);
|
|
59
|
+
},
|
|
60
|
+
async writeFile(path, contents) {
|
|
61
|
+
const target = resolvePath(path);
|
|
62
|
+
if (target === ROOT)
|
|
63
|
+
throw new Error("cannot write the workspace root as a file");
|
|
64
|
+
const bytes = toBytes(contents);
|
|
65
|
+
if (bytes.byteLength > maxFileBytes) {
|
|
66
|
+
throw new RangeError(`workspace file exceeds the ${maxFileBytes}-byte write bound`);
|
|
67
|
+
}
|
|
68
|
+
const parent = parentPath(target);
|
|
69
|
+
await requireSafeAncestors(fs, parent);
|
|
70
|
+
await fs.mkdir(parent, { recursive: true });
|
|
71
|
+
await requireSafePath(fs, parent, "directory");
|
|
72
|
+
const existing = await optionalLstat(fs, target);
|
|
73
|
+
if (existing)
|
|
74
|
+
requireSafeStat(existing, target, "file");
|
|
75
|
+
await fs.writeFile(target, bytes);
|
|
76
|
+
},
|
|
77
|
+
async mkdir(path) {
|
|
78
|
+
const target = resolvePath(path);
|
|
79
|
+
await requireSafeAncestors(fs, target);
|
|
80
|
+
await fs.mkdir(target, { recursive: true });
|
|
81
|
+
await requireSafePath(fs, target, "directory");
|
|
82
|
+
},
|
|
83
|
+
async remove(path, options = {}) {
|
|
84
|
+
const target = resolvePath(path);
|
|
85
|
+
if (target === ROOT)
|
|
86
|
+
throw new Error("cannot remove the workspace root");
|
|
87
|
+
await requireSafePath(fs, target);
|
|
88
|
+
await fs.rm(target, { recursive: options.recursive === true, force: false });
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async function ensureRoot(fs) {
|
|
93
|
+
const existing = await optionalLstat(fs, ROOT);
|
|
94
|
+
if (!existing)
|
|
95
|
+
await fs.mkdir(ROOT, { recursive: true });
|
|
96
|
+
await requireSafePath(fs, ROOT, "directory");
|
|
97
|
+
}
|
|
98
|
+
async function requireSafeAncestors(fs, target) {
|
|
99
|
+
for (const candidate of pathPrefixes(target)) {
|
|
100
|
+
const stat = await optionalLstat(fs, candidate);
|
|
101
|
+
if (!stat)
|
|
102
|
+
return;
|
|
103
|
+
requireSafeStat(stat, candidate, "directory");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function requireSafePath(fs, target, kind) {
|
|
107
|
+
let result;
|
|
108
|
+
for (const candidate of pathPrefixes(target)) {
|
|
109
|
+
result = await fs.lstat(candidate);
|
|
110
|
+
requireSafeStat(result, candidate, candidate === target ? kind : "directory");
|
|
111
|
+
}
|
|
112
|
+
if (!result)
|
|
113
|
+
throw new Error(`invalid workspace path: ${target}`);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
function requireSafeStat(stat, path, kind) {
|
|
117
|
+
if (stat.isSymbolicLink) {
|
|
118
|
+
throw new Error(`symbolic links are not supported by the Nanocodex workspace: ${path}`);
|
|
119
|
+
}
|
|
120
|
+
if (!stat.isFile && !stat.isDirectory) {
|
|
121
|
+
throw new Error(`unsupported workspace entry: ${path}`);
|
|
122
|
+
}
|
|
123
|
+
if (kind === "directory" && !stat.isDirectory)
|
|
124
|
+
throw new Error(`not a directory: ${path}`);
|
|
125
|
+
if (kind === "file" && !stat.isFile)
|
|
126
|
+
throw new Error(`not a file: ${path}`);
|
|
127
|
+
}
|
|
128
|
+
function requireSupportedEntry(entry, path) {
|
|
129
|
+
requireSafeStat(entry, path);
|
|
130
|
+
}
|
|
131
|
+
async function optionalLstat(fs, path) {
|
|
132
|
+
try {
|
|
133
|
+
return await fs.lstat(path);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (isMissing(error))
|
|
137
|
+
return undefined;
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function pathPrefixes(path) {
|
|
142
|
+
if (path === ROOT)
|
|
143
|
+
return [ROOT];
|
|
144
|
+
const relative = path.slice(ROOT.length + 1);
|
|
145
|
+
const prefixes = [ROOT];
|
|
146
|
+
let current = ROOT;
|
|
147
|
+
for (const segment of relative.split("/")) {
|
|
148
|
+
current += `/${segment}`;
|
|
149
|
+
prefixes.push(current);
|
|
150
|
+
}
|
|
151
|
+
return prefixes;
|
|
152
|
+
}
|
|
153
|
+
function resolvePath(path) {
|
|
154
|
+
if (typeof path !== "string")
|
|
155
|
+
throw new TypeError("workspace path must be a string");
|
|
156
|
+
if (path.includes("\0"))
|
|
157
|
+
throw new TypeError("workspace path cannot contain NUL");
|
|
158
|
+
if (path.includes("\\"))
|
|
159
|
+
throw new TypeError("workspace paths must use forward slashes");
|
|
160
|
+
let relative = path;
|
|
161
|
+
if (path.startsWith("/")) {
|
|
162
|
+
if (path !== ROOT && !path.startsWith(`${ROOT}/`)) {
|
|
163
|
+
throw new Error(`workspace path must stay within ${ROOT}`);
|
|
164
|
+
}
|
|
165
|
+
relative = path.slice(ROOT.length);
|
|
166
|
+
}
|
|
167
|
+
const segments = [];
|
|
168
|
+
for (const segment of relative.split("/")) {
|
|
169
|
+
if (!segment || segment === ".")
|
|
170
|
+
continue;
|
|
171
|
+
if (segment === "..")
|
|
172
|
+
throw new Error(`workspace path must stay within ${ROOT}`);
|
|
173
|
+
segments.push(segment);
|
|
174
|
+
}
|
|
175
|
+
return segments.length === 0 ? ROOT : `${ROOT}/${segments.join("/")}`;
|
|
176
|
+
}
|
|
177
|
+
function resolveChild(parent, name) {
|
|
178
|
+
if (!name || name.includes("/") || name.includes("\\") || name === "." || name === "..") {
|
|
179
|
+
throw new Error(`invalid workspace entry name: ${JSON.stringify(name)}`);
|
|
180
|
+
}
|
|
181
|
+
return resolvePath(`${parent}/${name}`);
|
|
182
|
+
}
|
|
183
|
+
function parentPath(path) {
|
|
184
|
+
return path.slice(0, path.lastIndexOf("/")) || ROOT;
|
|
185
|
+
}
|
|
186
|
+
async function readExactlyBounded(stream, expectedBytes, maxBytes) {
|
|
187
|
+
const reader = stream.getReader();
|
|
188
|
+
const output = new Uint8Array(expectedBytes);
|
|
189
|
+
let offset = 0;
|
|
190
|
+
try {
|
|
191
|
+
while (true) {
|
|
192
|
+
const { value, done } = await reader.read();
|
|
193
|
+
if (done)
|
|
194
|
+
break;
|
|
195
|
+
if (!(value instanceof Uint8Array))
|
|
196
|
+
throw new TypeError("workspace read returned non-byte data");
|
|
197
|
+
if (offset + value.byteLength > expectedBytes || offset + value.byteLength > maxBytes) {
|
|
198
|
+
await reader.cancel("workspace file changed or exceeded its read bound");
|
|
199
|
+
throw new RangeError(`workspace file changed or exceeds the ${maxBytes}-byte read bound`);
|
|
200
|
+
}
|
|
201
|
+
output.set(value, offset);
|
|
202
|
+
offset += value.byteLength;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
reader.releaseLock();
|
|
207
|
+
}
|
|
208
|
+
if (offset !== expectedBytes) {
|
|
209
|
+
throw new Error(`workspace file changed while reading: expected ${expectedBytes} bytes, received ${offset}`);
|
|
210
|
+
}
|
|
211
|
+
return output;
|
|
212
|
+
}
|
|
213
|
+
function toBytes(value) {
|
|
214
|
+
if (typeof value === "string")
|
|
215
|
+
return new TextEncoder().encode(value);
|
|
216
|
+
if (value instanceof ArrayBuffer)
|
|
217
|
+
return new Uint8Array(value);
|
|
218
|
+
if (ArrayBuffer.isView(value)) {
|
|
219
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
220
|
+
}
|
|
221
|
+
throw new TypeError("workspace contents must be a string or byte array");
|
|
222
|
+
}
|
|
223
|
+
function positiveInteger(value, fallback, name) {
|
|
224
|
+
if (value === undefined)
|
|
225
|
+
return fallback;
|
|
226
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
227
|
+
throw new TypeError(`${name} must be positive`);
|
|
228
|
+
}
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
function isMissing(error) {
|
|
232
|
+
if (!error || typeof error !== "object")
|
|
233
|
+
return false;
|
|
234
|
+
const value = error;
|
|
235
|
+
return value.code === "ENOENT"
|
|
236
|
+
|| (typeof value.message === "string" && /ENOENT|not found|no such/i.test(value.message));
|
|
237
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nanocodex-tools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Platform-neutral JavaScript tools for Nanocodex agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
"./node": {
|
|
9
|
+
"types": "./tools/nodeProcess.d.mts",
|
|
10
|
+
"import": "./tools/nodeProcess.mjs"
|
|
11
|
+
},
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./artifact": {
|
|
17
|
+
"types": "./tools/artifact.d.mts",
|
|
18
|
+
"import": "./tools/artifact.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./attachment": "./tools/attachment.mjs",
|
|
21
|
+
"./bash": {
|
|
22
|
+
"types": "./tools/bash.d.mts",
|
|
23
|
+
"import": "./tools/bash.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./dataset": {
|
|
26
|
+
"types": "./tools/dataset.d.mts",
|
|
27
|
+
"import": "./tools/dataset.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./execution-contract": {
|
|
30
|
+
"types": "./tools/execution-contract.d.mts",
|
|
31
|
+
"import": "./tools/execution-contract.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./just-bash/browser": {
|
|
34
|
+
"types": "./tools/just-bash-browser.d.mts",
|
|
35
|
+
"import": "./tools/just-bash-browser.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./memory": {
|
|
38
|
+
"types": "./dist/memory.d.ts",
|
|
39
|
+
"import": "./dist/memory.js"
|
|
40
|
+
},
|
|
41
|
+
"./session": {
|
|
42
|
+
"types": "./dist/session.d.ts",
|
|
43
|
+
"import": "./dist/session.js"
|
|
44
|
+
},
|
|
45
|
+
"./named-tool": {
|
|
46
|
+
"types": "./tools/namedTool.d.mts",
|
|
47
|
+
"import": "./tools/namedTool.mjs"
|
|
48
|
+
},
|
|
49
|
+
"./hosted-catalog": {
|
|
50
|
+
"types": "./tools/hostedCatalog.d.mts",
|
|
51
|
+
"import": "./tools/hostedCatalog.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./internal/hosted-machine": {
|
|
54
|
+
"types": "./tools/hostedMachine.d.mts",
|
|
55
|
+
"import": "./tools/hostedMachine.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./hosted": {
|
|
58
|
+
"types": "./dist/hosted/index.d.ts",
|
|
59
|
+
"import": "./dist/hosted/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./repository-workspace": {
|
|
62
|
+
"types": "./tools/repository-workspace.d.mts",
|
|
63
|
+
"import": "./tools/repository-workspace.mjs"
|
|
64
|
+
},
|
|
65
|
+
"./ssh": {
|
|
66
|
+
"types": "./tools/ssh.d.mts",
|
|
67
|
+
"import": "./tools/ssh.mjs"
|
|
68
|
+
},
|
|
69
|
+
"./standard": "./tools/standard.mjs",
|
|
70
|
+
"./standard-descriptions": "./tools/standardDescriptions.mjs",
|
|
71
|
+
"./runtime/code-runtime": "./runtime/code-runtime.mjs",
|
|
72
|
+
"./runtime/tool-configuration": "./runtime/tool-configuration.mjs",
|
|
73
|
+
"./runtime/tool-router": "./runtime/tool-router.mjs",
|
|
74
|
+
"./runtime/utf8": "./runtime/utf8.mjs",
|
|
75
|
+
"./workspace": {
|
|
76
|
+
"types": "./tools/workspace.d.mts",
|
|
77
|
+
"import": "./tools/workspace.mjs"
|
|
78
|
+
},
|
|
79
|
+
"./x": {
|
|
80
|
+
"types": "./tools/x.d.mts",
|
|
81
|
+
"import": "./tools/x.mjs"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"files": [
|
|
85
|
+
"dist",
|
|
86
|
+
"runtime",
|
|
87
|
+
"tools",
|
|
88
|
+
"README.md"
|
|
89
|
+
],
|
|
90
|
+
"publishConfig": {
|
|
91
|
+
"access": "public",
|
|
92
|
+
"provenance": true
|
|
93
|
+
},
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"@microsoft/dev-tunnels-ssh": "3.12.40",
|
|
96
|
+
"@microsoft/dev-tunnels-ssh-keys": "3.12.40",
|
|
97
|
+
"buffer": "6.0.3",
|
|
98
|
+
"hyparquet": "1.28.2",
|
|
99
|
+
"hyparquet-compressors": "1.1.1",
|
|
100
|
+
"isomorphic-git": "^1.41.5",
|
|
101
|
+
"just-bash": "^3.4.0",
|
|
102
|
+
"modern-tar": "0.7.7"
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"typescript": "5.9.3"
|
|
106
|
+
},
|
|
107
|
+
"engines": {
|
|
108
|
+
"node": ">=22.13.0"
|
|
109
|
+
},
|
|
110
|
+
"license": "MIT OR Apache-2.0",
|
|
111
|
+
"repository": {
|
|
112
|
+
"type": "git",
|
|
113
|
+
"url": "https://github.com/gakonst/nanocodex.git",
|
|
114
|
+
"directory": "js/nanocodex-tools"
|
|
115
|
+
},
|
|
116
|
+
"scripts": {
|
|
117
|
+
"clean": "node --eval \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
118
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
119
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
120
|
+
"typecheck": "tsc --noEmit"
|
|
121
|
+
}
|
|
122
|
+
}
|