@1claw/cli 0.34.6 → 0.35.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.
Files changed (76) hide show
  1. package/README.md +61 -4
  2. package/dist/bin/1claw.js +0 -0
  3. package/dist/src/commands/containers.d.ts +3 -0
  4. package/dist/src/commands/containers.d.ts.map +1 -0
  5. package/dist/src/commands/containers.js +130 -0
  6. package/dist/src/commands/containers.js.map +1 -0
  7. package/dist/src/commands/daemon.js +35 -11
  8. package/dist/src/commands/daemon.js.map +1 -1
  9. package/dist/src/commands/deploy.d.ts +3 -0
  10. package/dist/src/commands/deploy.d.ts.map +1 -0
  11. package/dist/src/commands/deploy.js +158 -0
  12. package/dist/src/commands/deploy.js.map +1 -0
  13. package/dist/src/commands/eject.d.ts +3 -0
  14. package/dist/src/commands/eject.d.ts.map +1 -0
  15. package/dist/src/commands/eject.js +84 -0
  16. package/dist/src/commands/eject.js.map +1 -0
  17. package/dist/src/commands/import.js +1 -1
  18. package/dist/src/commands/import.js.map +1 -1
  19. package/dist/src/commands/init.d.ts +3 -0
  20. package/dist/src/commands/init.d.ts.map +1 -0
  21. package/dist/src/commands/init.js +475 -0
  22. package/dist/src/commands/init.js.map +1 -0
  23. package/dist/src/commands/publish.d.ts +3 -0
  24. package/dist/src/commands/publish.d.ts.map +1 -0
  25. package/dist/src/commands/publish.js +153 -0
  26. package/dist/src/commands/publish.js.map +1 -0
  27. package/dist/src/deploy/google-cloud/main.tf +74 -0
  28. package/dist/src/deploy/google-cloud/outputs.tf +9 -0
  29. package/dist/src/deploy/google-cloud/variables.tf +44 -0
  30. package/dist/src/docker/base/Dockerfile +34 -0
  31. package/dist/src/docker/base/chat-ui/index.html +110 -0
  32. package/dist/src/docker/base/chat-ui/server.js +233 -0
  33. package/dist/src/docker/base/entrypoint.sh +61 -0
  34. package/dist/src/docker/base/healthcheck.sh +2 -0
  35. package/dist/src/docker/compose.yaml +20 -0
  36. package/dist/src/docker/templates/Dockerfile.tmpl +7 -0
  37. package/dist/src/index.d.ts.map +1 -1
  38. package/dist/src/index.js +11 -0
  39. package/dist/src/index.js.map +1 -1
  40. package/dist/src/lib/container-config.d.ts +43 -0
  41. package/dist/src/lib/container-config.d.ts.map +1 -0
  42. package/dist/src/lib/container-config.js +98 -0
  43. package/dist/src/lib/container-config.js.map +1 -0
  44. package/dist/src/lib/daemon-control.d.ts +10 -0
  45. package/dist/src/lib/daemon-control.d.ts.map +1 -0
  46. package/dist/src/lib/daemon-control.js +58 -0
  47. package/dist/src/lib/daemon-control.js.map +1 -0
  48. package/dist/src/lib/docker-client.d.ts +58 -0
  49. package/dist/src/lib/docker-client.d.ts.map +1 -0
  50. package/dist/src/lib/docker-client.js +193 -0
  51. package/dist/src/lib/docker-client.js.map +1 -0
  52. package/dist/src/lib/image-build.d.ts +30 -0
  53. package/dist/src/lib/image-build.d.ts.map +1 -0
  54. package/dist/src/lib/image-build.js +74 -0
  55. package/dist/src/lib/image-build.js.map +1 -0
  56. package/dist/src/lib/paths.d.ts +14 -0
  57. package/dist/src/lib/paths.d.ts.map +1 -0
  58. package/dist/src/lib/paths.js +38 -0
  59. package/dist/src/lib/paths.js.map +1 -0
  60. package/dist/src/modules/ampersend/config.json +8 -0
  61. package/dist/src/modules/ampersend/module.yaml +32 -0
  62. package/dist/src/modules/ampersend/startup.sh +4 -0
  63. package/dist/src/modules/elizaos/config.json +7 -0
  64. package/dist/src/modules/elizaos/module.yaml +30 -0
  65. package/dist/src/modules/elizaos/startup.sh +3 -0
  66. package/dist/src/modules/langchain/module.yaml +30 -0
  67. package/dist/src/modules/langchain/startup.sh +3 -0
  68. package/dist/src/modules/onchain/module.yaml +28 -0
  69. package/dist/src/modules/onchain/startup.sh +3 -0
  70. package/dist/src/modules/registry.d.ts +48 -0
  71. package/dist/src/modules/registry.d.ts.map +1 -0
  72. package/dist/src/modules/registry.js +201 -0
  73. package/dist/src/modules/registry.js.map +1 -0
  74. package/dist/src/modules/scaffold-agent/module.yaml +30 -0
  75. package/dist/src/modules/scaffold-agent/startup.sh +3 -0
  76. package/package.json +4 -3
@@ -0,0 +1,153 @@
1
+ import { Command } from "commander";
2
+ import { existsSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import chalk from "chalk";
5
+ import ora from "ora";
6
+ import { printSuccess, printError, printWarning, printInfo, printKeyValue, } from "../output.js";
7
+ import { dockerBuild, dockerTag, dockerPush, dockerCommit, dockerContainerStatus, } from "../lib/docker-client.js";
8
+ import { buildModuleImage, DEFAULT_BASE_IMAGE } from "../lib/image-build.js";
9
+ import { resolveModules } from "../modules/registry.js";
10
+ import { loadContainerState, saveContainerState, } from "../lib/container-config.js";
11
+ export const publishCommand = new Command("publish")
12
+ .description("Build and push your custom agent container to a registry")
13
+ .option("--name <name>", "Container name (from `1claw init` state)")
14
+ .option("--tag <tag>", "Image tag (default: {name}:latest)")
15
+ .option("--registry <url>", "Registry URL (default: docker.io)")
16
+ .option("--dockerfile <path>", "Custom Dockerfile (build from context)")
17
+ .option("--context <path>", "Build context directory (default: .)")
18
+ .option("--commit", "Snapshot a running container via `docker commit`")
19
+ .action(async (opts) => {
20
+ try {
21
+ await publishAction(opts);
22
+ }
23
+ catch (err) {
24
+ printError(err instanceof Error ? err.message : String(err));
25
+ process.exit(1);
26
+ }
27
+ });
28
+ function resolveTag(opts, fallbackName) {
29
+ let tag = opts.tag ?? `${fallbackName}:latest`;
30
+ if (opts.registry && !tag.startsWith(opts.registry)) {
31
+ const host = opts.registry.replace(/^https?:\/\//, "").replace(/\/$/, "");
32
+ if (host && host !== "docker.io")
33
+ tag = `${host}/${tag}`;
34
+ }
35
+ if (!opts.tag) {
36
+ printWarning(`No --tag given; using "${tag}". For Docker Hub use --tag <username>/<name>:<version>.`);
37
+ }
38
+ return tag;
39
+ }
40
+ async function publishAction(opts) {
41
+ console.log();
42
+ // CASE B — custom Dockerfile / current directory (no --name).
43
+ if (!opts.name) {
44
+ const context = resolve(opts.context ?? ".");
45
+ const dockerfile = opts.dockerfile
46
+ ? resolve(opts.dockerfile)
47
+ : join(context, "Dockerfile");
48
+ if (!existsSync(dockerfile)) {
49
+ throw new Error("No --name and no Dockerfile found. Provide --name <container> or run from a directory with a Dockerfile.");
50
+ }
51
+ const tag = resolveTag(opts, "1claw-agent");
52
+ const buildSpinner = ora(`Building from ${dockerfile}...`).start();
53
+ try {
54
+ await dockerBuild({
55
+ context,
56
+ dockerfile,
57
+ tag,
58
+ onProgress: (l) => (buildSpinner.text = chalk.dim(l.slice(0, 70))),
59
+ });
60
+ buildSpinner.succeed(`Built ${tag}`);
61
+ }
62
+ catch (err) {
63
+ buildSpinner.fail("Build failed.");
64
+ throw err;
65
+ }
66
+ await pushTag(tag);
67
+ printPullHint(tag);
68
+ return;
69
+ }
70
+ // CASE A / C — publish a container created by `1claw init`.
71
+ const state = loadContainerState(opts.name);
72
+ if (!state) {
73
+ throw new Error(`No container state for "${opts.name}". Was it created with \`1claw init\`?`);
74
+ }
75
+ const tag = resolveTag(opts, state.containerName);
76
+ let sourceImage;
77
+ if (opts.commit) {
78
+ // CASE C — snapshot runtime state.
79
+ const status = await dockerContainerStatus(state.containerName);
80
+ if (!status.exists) {
81
+ throw new Error(`Container "${state.containerName}" not found to commit.`);
82
+ }
83
+ printWarning("Publishing from a container commit (not a Dockerfile). " +
84
+ "For reproducible builds, prefer building from a Dockerfile.");
85
+ const commitSpinner = ora(`Committing ${state.containerName}...`).start();
86
+ try {
87
+ sourceImage = `1claw-commit-${state.containerName}:latest`;
88
+ await dockerCommit(state.containerName, sourceImage);
89
+ commitSpinner.succeed("Container committed.");
90
+ }
91
+ catch (err) {
92
+ commitSpinner.fail("Commit failed.");
93
+ throw err;
94
+ }
95
+ }
96
+ else if (state.modules.length > 0) {
97
+ // CASE A — rebuild reproducibly from base + modules.
98
+ const modules = resolveModules(state.modules);
99
+ const baseImage = state.image || DEFAULT_BASE_IMAGE;
100
+ const buildSpinner = ora(`Rebuilding from base + modules (${modules.map((m) => m.name).join(", ")})...`).start();
101
+ try {
102
+ const { tag: builtTag } = await buildModuleImage(baseImage, modules, (l) => (buildSpinner.text = chalk.dim(l.slice(0, 70))));
103
+ sourceImage = builtTag;
104
+ buildSpinner.succeed("Rebuilt module image.");
105
+ }
106
+ catch (err) {
107
+ buildSpinner.fail("Rebuild failed.");
108
+ throw err;
109
+ }
110
+ }
111
+ else {
112
+ // No modules — publish the base/custom image directly.
113
+ sourceImage = state.customImage ?? state.image;
114
+ }
115
+ const tagSpinner = ora(`Tagging ${sourceImage} → ${tag}...`).start();
116
+ try {
117
+ await dockerTag(sourceImage, tag);
118
+ tagSpinner.succeed(`Tagged ${tag}`);
119
+ }
120
+ catch (err) {
121
+ tagSpinner.fail("Tag failed.");
122
+ throw err;
123
+ }
124
+ await pushTag(tag);
125
+ state.customImage = tag;
126
+ state.publishedAt = new Date().toISOString();
127
+ saveContainerState(state);
128
+ printPullHint(tag);
129
+ }
130
+ async function pushTag(tag) {
131
+ const spinner = ora(`Pushing ${tag}...`).start();
132
+ try {
133
+ await dockerPush(tag, (l) => (spinner.text = chalk.dim(l.slice(0, 70))));
134
+ spinner.succeed(`Pushed ${tag}`);
135
+ }
136
+ catch (err) {
137
+ spinner.fail("Push failed.");
138
+ const msg = err instanceof Error ? err.message : String(err);
139
+ if (/denied|unauthorized|authentication required/i.test(msg)) {
140
+ printError("Registry authentication failed. Run `docker login` first, then retry.");
141
+ }
142
+ throw err;
143
+ }
144
+ }
145
+ function printPullHint(tag) {
146
+ console.log();
147
+ printSuccess("Published.");
148
+ printKeyValue([["Image", tag], ["Pull", `docker pull ${tag}`]]);
149
+ console.log();
150
+ printInfo("Deploy it to the cloud with `1claw deploy --google-cloud --name <name>`.");
151
+ console.log();
152
+ }
153
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CA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;QACX,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7B,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,IAAI,8CAA8C,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3D,UAAU,CACN,uEAAuE,CAC1E,CAAC;QACN,CAAC;QACD,MAAM,GAAG,CAAC;IACd,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAC9B,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,YAAY,CAAC,YAAY,CAAC,CAAC;IAC3B,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,SAAS,CAAC,0EAA0E,CAAC,CAAC;IACtF,OAAO,CAAC,GAAG,EAAE,CAAC;AAClB,CAAC"}
@@ -0,0 +1,74 @@
1
+ # Generated by `1claw deploy --google-cloud`.
2
+ # Deploys a 1Claw agent container to Cloud Run with the agent API key stored in
3
+ # Secret Manager and injected as an environment variable at runtime.
4
+ terraform {
5
+ required_providers {
6
+ google = {
7
+ source = "hashicorp/google"
8
+ version = ">= 5.0"
9
+ }
10
+ }
11
+ }
12
+
13
+ provider "google" {
14
+ project = var.project_id
15
+ region = var.region
16
+ }
17
+
18
+ resource "google_secret_manager_secret" "agent_key" {
19
+ secret_id = "${var.service_name}-agent-key"
20
+ replication {
21
+ auto {}
22
+ }
23
+ }
24
+
25
+ resource "google_secret_manager_secret_version" "agent_key" {
26
+ secret = google_secret_manager_secret.agent_key.id
27
+ secret_data = var.agent_api_key
28
+ }
29
+
30
+ resource "google_cloud_run_v2_service" "agent" {
31
+ name = var.service_name
32
+ location = var.region
33
+
34
+ template {
35
+ containers {
36
+ image = var.image_tag
37
+
38
+ ports {
39
+ container_port = 3000
40
+ }
41
+
42
+ # Cloud mode: the container talks to the 1Claw API directly using the
43
+ # agent key injected from Secret Manager (no host daemon in the cloud).
44
+ env {
45
+ name = "ONECLAW_LOCAL_VAULT"
46
+ value = "false"
47
+ }
48
+ env {
49
+ name = "ONECLAW_AGENT_ID"
50
+ value = var.agent_id
51
+ }
52
+ env {
53
+ name = "ONECLAW_CONTAINER_MODULES"
54
+ value = var.modules
55
+ }
56
+ env {
57
+ name = "ONECLAW_AGENT_API_KEY"
58
+ value_source {
59
+ secret_key_ref {
60
+ secret = google_secret_manager_secret.agent_key.secret_id
61
+ version = "latest"
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ resource "google_cloud_run_v2_service_iam_member" "invoker" {
70
+ name = google_cloud_run_v2_service.agent.name
71
+ location = google_cloud_run_v2_service.agent.location
72
+ role = "roles/run.invoker"
73
+ member = var.invoker_member
74
+ }
@@ -0,0 +1,9 @@
1
+ output "service_url" {
2
+ description = "Public URL of the deployed Cloud Run service"
3
+ value = google_cloud_run_v2_service.agent.uri
4
+ }
5
+
6
+ output "service_name" {
7
+ description = "Cloud Run service name"
8
+ value = google_cloud_run_v2_service.agent.name
9
+ }
@@ -0,0 +1,44 @@
1
+ variable "project_id" {
2
+ type = string
3
+ description = "Google Cloud project ID"
4
+ }
5
+
6
+ variable "region" {
7
+ type = string
8
+ description = "Cloud Run region"
9
+ default = "us-central1"
10
+ }
11
+
12
+ variable "service_name" {
13
+ type = string
14
+ description = "Cloud Run service name"
15
+ }
16
+
17
+ variable "image_tag" {
18
+ type = string
19
+ description = "Container image (must be in a registry, e.g. docker.io/<user>/<name>:<tag>)"
20
+ }
21
+
22
+ variable "agent_id" {
23
+ type = string
24
+ description = "1Claw agent ID (metadata only)"
25
+ default = ""
26
+ }
27
+
28
+ variable "modules" {
29
+ type = string
30
+ description = "Comma-separated module names baked into the image"
31
+ default = ""
32
+ }
33
+
34
+ variable "agent_api_key" {
35
+ type = string
36
+ description = "1Claw agent API key (ocv_...) stored in Secret Manager"
37
+ sensitive = true
38
+ }
39
+
40
+ variable "invoker_member" {
41
+ type = string
42
+ description = "IAM member allowed to invoke the service"
43
+ default = "allUsers"
44
+ }
@@ -0,0 +1,34 @@
1
+ FROM node:20-alpine AS base
2
+
3
+ RUN apk add --no-cache curl tini
4
+
5
+ WORKDIR /app
6
+
7
+ # Install the 1Claw MCP server (local daemon mode). Best-effort: the chat UI
8
+ # talks to the daemon over the mounted socket directly, so the container is
9
+ # still healthy if the registry is unreachable at build time.
10
+ RUN npm install -g @1claw/mcp@latest || echo "WARN: @1claw/mcp install deferred to runtime"
11
+
12
+ # Baked-in chat UI (single Node http server + static HTML, zero deps).
13
+ COPY chat-ui /app/chat-ui
14
+
15
+ # Startup + health scripts
16
+ COPY entrypoint.sh /app/entrypoint.sh
17
+ COPY healthcheck.sh /app/healthcheck.sh
18
+ RUN chmod +x /app/entrypoint.sh /app/healthcheck.sh
19
+
20
+ # Module extension point: modules drop assets under /app/modules
21
+ RUN mkdir -p /app/modules /run/1claw
22
+
23
+ ENV NODE_ENV=production
24
+ ENV ONECLAW_LOCAL_VAULT=true
25
+ ENV ONECLAW_DAEMON_SOCKET=/run/1claw/daemon.sock
26
+ ENV CHAT_UI_PORT=3000
27
+
28
+ EXPOSE 3000
29
+
30
+ HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=5 \
31
+ CMD /app/healthcheck.sh
32
+
33
+ ENTRYPOINT ["tini", "--"]
34
+ CMD ["/app/entrypoint.sh"]
@@ -0,0 +1,110 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>1Claw Agent</title>
7
+ <style>
8
+ :root { color-scheme: dark; }
9
+ * { box-sizing: border-box; }
10
+ body {
11
+ margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
12
+ background: #0b0d12; color: #e6e9ef; height: 100vh; display: flex; flex-direction: column;
13
+ }
14
+ header {
15
+ padding: 12px 18px; border-bottom: 1px solid #1c2230;
16
+ display: flex; align-items: center; gap: 12px; background: #0e1219;
17
+ }
18
+ header .dot { width: 9px; height: 9px; border-radius: 50%; background: #38d39f; box-shadow: 0 0 8px #38d39f; }
19
+ header h1 { font-size: 15px; margin: 0; font-weight: 600; }
20
+ header .meta { margin-left: auto; font-size: 12px; color: #7c869b; }
21
+ header .badge { background: #1c2230; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
22
+ #log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
23
+ .msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; line-height: 1.45; font-size: 14px; }
24
+ .user { align-self: flex-end; background: #2563eb; color: #fff; border-bottom-right-radius: 3px; }
25
+ .bot { align-self: flex-start; background: #161b25; border: 1px solid #1c2230; border-bottom-left-radius: 3px; }
26
+ .tool { align-self: flex-start; font-size: 11px; color: #8aa0c2; margin-top: -6px; }
27
+ form { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid #1c2230; background: #0e1219; }
28
+ input { flex: 1; background: #0b0d12; border: 1px solid #28303f; color: #e6e9ef; padding: 11px 14px; border-radius: 10px; font-size: 14px; outline: none; }
29
+ input:focus { border-color: #2563eb; }
30
+ button { background: #2563eb; color: #fff; border: none; padding: 0 18px; border-radius: 10px; font-size: 14px; cursor: pointer; font-weight: 600; }
31
+ button:disabled { opacity: .5; cursor: default; }
32
+ a { color: #6ea8fe; }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <header>
37
+ <span class="dot"></span>
38
+ <h1>1Claw Agent</h1>
39
+ <span class="meta" id="meta">connecting…</span>
40
+ </header>
41
+ <div id="log"></div>
42
+ <form id="form">
43
+ <input id="input" placeholder="Type a message or /help" autocomplete="off" autofocus />
44
+ <button id="send" type="submit">Send</button>
45
+ </form>
46
+ <script>
47
+ const log = document.getElementById("log");
48
+ const form = document.getElementById("form");
49
+ const input = document.getElementById("input");
50
+ const send = document.getElementById("send");
51
+ const meta = document.getElementById("meta");
52
+
53
+ function add(role, text, tool) {
54
+ if (tool) {
55
+ const t = document.createElement("div");
56
+ t.className = "tool";
57
+ t.textContent = "⚙ tool: " + tool;
58
+ log.appendChild(t);
59
+ }
60
+ const el = document.createElement("div");
61
+ el.className = "msg " + (role === "user" ? "user" : "bot");
62
+ el.textContent = text;
63
+ log.appendChild(el);
64
+ log.scrollTop = log.scrollHeight;
65
+ }
66
+
67
+ async function loadInfo() {
68
+ try {
69
+ const r = await fetch("/api/info");
70
+ const info = await r.json();
71
+ const parts = [];
72
+ parts.push("mode=" + info.mode);
73
+ if (info.agentId) parts.push("agent=" + info.agentId.slice(0, 8) + "…");
74
+ if (info.modules && info.modules.length) parts.push("modules=" + info.modules.join(","));
75
+ parts.push(info.daemonReachable ? "daemon ✓" : "daemon —");
76
+ meta.innerHTML = parts.map((p) => '<span class="badge">' + p + "</span>").join("");
77
+ } catch {
78
+ meta.textContent = "offline";
79
+ }
80
+ }
81
+
82
+ form.addEventListener("submit", async (e) => {
83
+ e.preventDefault();
84
+ const message = input.value.trim();
85
+ if (!message) return;
86
+ add("user", message);
87
+ input.value = "";
88
+ send.disabled = true;
89
+ try {
90
+ const r = await fetch("/api/chat", {
91
+ method: "POST",
92
+ headers: { "Content-Type": "application/json" },
93
+ body: JSON.stringify({ message }),
94
+ });
95
+ const data = await r.json();
96
+ add("bot", data.reply || "(no reply)", data.tool);
97
+ } catch (err) {
98
+ add("bot", "Error: " + err.message);
99
+ } finally {
100
+ send.disabled = false;
101
+ input.focus();
102
+ }
103
+ });
104
+
105
+ add("bot", "1Claw agent ready. Your credentials stay in the host daemon — this container never sees secret values. Type /help to begin.");
106
+ loadInfo();
107
+ setInterval(loadInfo, 15000);
108
+ </script>
109
+ </body>
110
+ </html>
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env node
2
+ // 1Claw agent chat UI — a tiny, zero-dependency HTTP server.
3
+ //
4
+ // It serves a single-page chat interface and bridges browser requests to the
5
+ // host daemon over the mounted Unix socket. Secret VALUES never transit this
6
+ // process: the daemon injects them into outbound requests and returns only the
7
+ // upstream response. This server only ever sees secret NAMES and metadata.
8
+ "use strict";
9
+
10
+ const http = require("node:http");
11
+ const { readFileSync } = require("node:fs");
12
+ const { join } = require("node:path");
13
+
14
+ const PORT = parseInt(process.env.CHAT_UI_PORT || "3000", 10);
15
+ const SOCKET = process.env.ONECLAW_DAEMON_SOCKET || "/run/1claw/daemon.sock";
16
+ const AGENT_ID = process.env.ONECLAW_AGENT_ID || "";
17
+ const MODULES = (process.env.ONECLAW_CONTAINER_MODULES || "")
18
+ .split(",")
19
+ .map((m) => m.trim())
20
+ .filter(Boolean);
21
+ const MODE = process.env.ONECLAW_LOCAL_VAULT === "true" ? "local" : "cloud";
22
+
23
+ let INDEX_HTML = "<h1>1Claw Agent Running</h1>";
24
+ try {
25
+ INDEX_HTML = readFileSync(join(__dirname, "index.html"), "utf-8");
26
+ } catch {
27
+ /* fall back to placeholder */
28
+ }
29
+
30
+ /** Call the host daemon over the Unix socket. */
31
+ function daemonRequest(method, path, body) {
32
+ return new Promise((resolve, reject) => {
33
+ const payload = body ? JSON.stringify(body) : undefined;
34
+ const req = http.request(
35
+ {
36
+ socketPath: SOCKET,
37
+ path,
38
+ method,
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ ...(payload
42
+ ? { "Content-Length": Buffer.byteLength(payload) }
43
+ : {}),
44
+ },
45
+ timeout: 10000,
46
+ },
47
+ (res) => {
48
+ const chunks = [];
49
+ res.on("data", (c) => chunks.push(c));
50
+ res.on("end", () => {
51
+ const text = Buffer.concat(chunks).toString("utf-8");
52
+ let parsed = null;
53
+ try {
54
+ parsed = text ? JSON.parse(text) : null;
55
+ } catch {
56
+ parsed = { raw: text };
57
+ }
58
+ resolve({ status: res.statusCode || 0, body: parsed });
59
+ });
60
+ },
61
+ );
62
+ req.on("error", reject);
63
+ req.on("timeout", () => req.destroy(new Error("daemon timeout")));
64
+ if (payload) req.write(payload);
65
+ req.end();
66
+ });
67
+ }
68
+
69
+ function json(res, status, obj) {
70
+ const body = JSON.stringify(obj);
71
+ res.writeHead(status, {
72
+ "Content-Type": "application/json",
73
+ "Content-Length": Buffer.byteLength(body),
74
+ });
75
+ res.end(body);
76
+ }
77
+
78
+ function readBody(req) {
79
+ return new Promise((resolve, reject) => {
80
+ const chunks = [];
81
+ let size = 0;
82
+ req.on("data", (c) => {
83
+ size += c.length;
84
+ if (size > 1024 * 1024) {
85
+ reject(new Error("body too large"));
86
+ req.destroy();
87
+ return;
88
+ }
89
+ chunks.push(c);
90
+ });
91
+ req.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
92
+ req.on("error", reject);
93
+ });
94
+ }
95
+
96
+ async function daemonReachable() {
97
+ if (MODE !== "local") return false;
98
+ try {
99
+ const r = await daemonRequest("GET", "/health");
100
+ return r.status === 200;
101
+ } catch {
102
+ return false;
103
+ }
104
+ }
105
+
106
+ // A minimal, LLM-optional assistant. Demonstrates the daemon trust boundary
107
+ // with slash commands; if an LLM provider is wired in later it replaces this.
108
+ async function handleChat(message) {
109
+ const text = (message || "").trim();
110
+
111
+ if (text === "/help" || text === "") {
112
+ return {
113
+ reply:
114
+ "1Claw agent ready. Commands:\n" +
115
+ " /secrets — list secret names available via the daemon\n" +
116
+ " /info — show this agent's runtime info\n" +
117
+ " /proxy <name> <url> — make a request with the secret injected by the daemon\n" +
118
+ "Secret values never enter this container.",
119
+ tool: null,
120
+ };
121
+ }
122
+
123
+ if (text === "/info") {
124
+ return {
125
+ reply: `Agent ${AGENT_ID || "(local)"} · mode=${MODE} · modules=${MODULES.join(", ") || "none"}`,
126
+ tool: "info",
127
+ };
128
+ }
129
+
130
+ if (text === "/secrets") {
131
+ try {
132
+ const r = await daemonRequest("GET", "/secrets");
133
+ if (r.status !== 200) {
134
+ return { reply: `Daemon returned ${r.status}`, tool: "list_secrets" };
135
+ }
136
+ const names = (r.body.secrets || []).map((s) => s.name);
137
+ return {
138
+ reply: names.length
139
+ ? "Available secrets:\n" + names.map((n) => " • " + n).join("\n")
140
+ : "No secrets available to this agent.",
141
+ tool: "list_secrets",
142
+ };
143
+ } catch (err) {
144
+ return { reply: `Could not reach daemon: ${err.message}`, tool: "list_secrets" };
145
+ }
146
+ }
147
+
148
+ if (text.startsWith("/proxy ")) {
149
+ const parts = text.split(/\s+/);
150
+ const secretName = parts[1];
151
+ const url = parts[2];
152
+ if (!secretName || !url) {
153
+ return { reply: "Usage: /proxy <secret-name> <url>", tool: null };
154
+ }
155
+ try {
156
+ const r = await daemonRequest("POST", "/proxy", {
157
+ secretName,
158
+ url,
159
+ method: "GET",
160
+ });
161
+ return {
162
+ reply:
163
+ r.status === 200
164
+ ? `Proxied request (secret injected by daemon). Upstream status: ${r.body.status}`
165
+ : `Daemon denied request (${r.status}): ${r.body && r.body.error}`,
166
+ tool: "proxy_request",
167
+ };
168
+ } catch (err) {
169
+ return { reply: `Proxy error: ${err.message}`, tool: "proxy_request" };
170
+ }
171
+ }
172
+
173
+ return {
174
+ reply:
175
+ "No LLM provider is configured in this container yet. " +
176
+ "Try /help, /secrets, /info, or /proxy. " +
177
+ "Wire a model via a module to enable conversational replies.",
178
+ tool: null,
179
+ };
180
+ }
181
+
182
+ const server = http.createServer(async (req, res) => {
183
+ const url = req.url || "/";
184
+ const method = req.method || "GET";
185
+
186
+ if (url === "/health") {
187
+ return json(res, 200, { status: "ok", agent: AGENT_ID || null, mode: MODE });
188
+ }
189
+
190
+ if (url === "/api/info" && method === "GET") {
191
+ return json(res, 200, {
192
+ agentId: AGENT_ID || null,
193
+ modules: MODULES,
194
+ mode: MODE,
195
+ daemonReachable: await daemonReachable(),
196
+ });
197
+ }
198
+
199
+ if (url === "/api/secrets" && method === "GET") {
200
+ try {
201
+ const r = await daemonRequest("GET", "/secrets");
202
+ return json(res, r.status, r.body || { secrets: [] });
203
+ } catch (err) {
204
+ return json(res, 502, { error: `daemon unreachable: ${err.message}` });
205
+ }
206
+ }
207
+
208
+ if (url === "/api/chat" && method === "POST") {
209
+ let body;
210
+ try {
211
+ body = JSON.parse((await readBody(req)) || "{}");
212
+ } catch {
213
+ return json(res, 400, { error: "invalid JSON" });
214
+ }
215
+ const result = await handleChat(body.message);
216
+ return json(res, 200, result);
217
+ }
218
+
219
+ if (url === "/" || url === "/index.html") {
220
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
221
+ return res.end(INDEX_HTML);
222
+ }
223
+
224
+ json(res, 404, { error: "not found" });
225
+ });
226
+
227
+ server.listen(PORT, "0.0.0.0", () => {
228
+ console.log(`[chat-ui] listening on :${PORT} (mode=${MODE})`);
229
+ });
230
+
231
+ for (const sig of ["SIGINT", "SIGTERM"]) {
232
+ process.on(sig, () => server.close(() => process.exit(0)));
233
+ }