@astrofoundry/astrogate 0.0.0-stage → 0.1.2

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 (101) hide show
  1. package/README.md +13 -2
  2. package/agents/foreman.md +27 -0
  3. package/cli/astro-install.sh +242 -0
  4. package/cli/astro.sh +449 -0
  5. package/cli/astro.test.ts +65 -0
  6. package/cli/astrogate.sh +309 -0
  7. package/cli/astrogate.test.ts +113 -0
  8. package/cli/verify-release.sh +77 -0
  9. package/cli/verify-release.test.ts +140 -0
  10. package/dist/bridge.js +9950 -0
  11. package/dist/claude.js +7899 -0
  12. package/dist/extensions/bridge/index.js +9937 -0
  13. package/dist/extensions/gate/index.js +286 -0
  14. package/dist/extensions/guard/index.js +364 -0
  15. package/dist/extensions/subagents/index.js +8458 -0
  16. package/extensions/bridge/admin.ts +86 -0
  17. package/extensions/bridge/approvals.ts +147 -0
  18. package/extensions/bridge/attachments.ts +65 -0
  19. package/extensions/bridge/chunk.ts +50 -0
  20. package/extensions/bridge/claude-run.test.ts +62 -0
  21. package/extensions/bridge/claude-run.ts +301 -0
  22. package/extensions/bridge/commands.ts +89 -0
  23. package/extensions/bridge/config.ts +263 -0
  24. package/extensions/bridge/conversations.ts +144 -0
  25. package/extensions/bridge/daemon.ts +60 -0
  26. package/extensions/bridge/discord.test.ts +547 -0
  27. package/extensions/bridge/gateway.ts +222 -0
  28. package/extensions/bridge/index.ts +951 -0
  29. package/extensions/bridge/launcher.ts +36 -0
  30. package/extensions/bridge/lifecycle.test.ts +78 -0
  31. package/extensions/bridge/open-work.ts +74 -0
  32. package/extensions/bridge/plugin.ts +172 -0
  33. package/extensions/bridge/quote.ts +39 -0
  34. package/extensions/bridge/reports.ts +65 -0
  35. package/extensions/bridge/rest.ts +217 -0
  36. package/extensions/bridge/setup.ts +218 -0
  37. package/extensions/gate/approvals.test.ts +40 -0
  38. package/extensions/gate/config.ts +110 -0
  39. package/extensions/gate/core.ts +114 -0
  40. package/extensions/gate/index.test.ts +202 -0
  41. package/extensions/gate/index.ts +114 -0
  42. package/extensions/gate/risky.ts +14 -0
  43. package/extensions/gate/types.ts +19 -0
  44. package/extensions/guard/config.test.ts +107 -0
  45. package/extensions/guard/config.ts +120 -0
  46. package/extensions/guard/defaults.ts +40 -0
  47. package/extensions/guard/index.test.ts +313 -0
  48. package/extensions/guard/index.ts +183 -0
  49. package/extensions/guard/rules.test.ts +118 -0
  50. package/extensions/guard/rules.ts +101 -0
  51. package/extensions/guard/types.ts +12 -0
  52. package/extensions/subagents/agents.test.ts +137 -0
  53. package/extensions/subagents/agents.ts +207 -0
  54. package/extensions/subagents/bundled.test.ts +29 -0
  55. package/extensions/subagents/child.test.ts +202 -0
  56. package/extensions/subagents/child.ts +367 -0
  57. package/extensions/subagents/index.test.ts +123 -0
  58. package/extensions/subagents/index.ts +352 -0
  59. package/extensions/subagents/pi-paths.test.ts +39 -0
  60. package/extensions/subagents/pi-paths.ts +58 -0
  61. package/extensions/subagents/render.ts +221 -0
  62. package/extensions/subagents/sessions.test.ts +32 -0
  63. package/extensions/subagents/sessions.ts +34 -0
  64. package/extensions/subagents/ticker.test.ts +40 -0
  65. package/extensions/subagents/ticker.ts +36 -0
  66. package/harness/claude/agents.ts +93 -0
  67. package/harness/claude/claude.test.ts +171 -0
  68. package/harness/claude/hook.ts +77 -0
  69. package/harness/claude/main.ts +122 -0
  70. package/harness/claude/mcp.ts +174 -0
  71. package/harness/claude/settings.ts +63 -0
  72. package/package.json +71 -4
  73. package/release.sha256 +99 -0
  74. package/release.sha256.sig +6 -0
  75. package/specialists/AGENTS.md +67 -0
  76. package/specialists/README.md +81 -0
  77. package/specialists/entry/specialist-cli.sh +22 -0
  78. package/specialists/entry/specialist-install.sh +861 -0
  79. package/specialists/entry/specialist-install.test.ts +305 -0
  80. package/specialists/lib/argv.ts +19 -0
  81. package/specialists/lib/audit.ts +20 -0
  82. package/specialists/lib/config.ts +27 -0
  83. package/specialists/lib/errors.ts +8 -0
  84. package/specialists/lib/flush.test.ts +21 -0
  85. package/specialists/lib/lib.test.ts +87 -0
  86. package/specialists/lib/lock.test.ts +42 -0
  87. package/specialists/lib/lock.ts +67 -0
  88. package/specialists/lib/main.ts +40 -0
  89. package/specialists/lib/output.ts +11 -0
  90. package/specialists/lib/paths.ts +22 -0
  91. package/specialists/lib/pinned.test.ts +55 -0
  92. package/specialists/lib/pinned.ts +67 -0
  93. package/specialists/lib/proc.ts +49 -0
  94. package/specialists/lib/repo.ts +198 -0
  95. package/specialists/lib/runtime.test.ts +81 -0
  96. package/specialists/lib/sanitize.ts +43 -0
  97. package/specialists/lib/secrets.ts +28 -0
  98. package/specialists/lib/ssh.ts +38 -0
  99. package/specialists/lib/tunnel.test.ts +44 -0
  100. package/specialists/lib/tunnel.ts +76 -0
  101. package/specialists/provision/provision.sh +96 -0
@@ -0,0 +1,76 @@
1
+ import { spawn, type ChildProcess } from "node:child_process";
2
+ import { connect } from "node:net";
3
+ import { ServiceError } from "./errors.ts";
4
+
5
+ export interface TunnelOptions {
6
+ env: Record<string, string>;
7
+ /** Local port the tunnel process must start listening on. */
8
+ port: number;
9
+ readyTimeoutMs: number;
10
+ }
11
+
12
+ export interface Tunnel {
13
+ close(): Promise<void>;
14
+ }
15
+
16
+ function portOpen(port: number): Promise<boolean> {
17
+ return new Promise((resolve) => {
18
+ const socket = connect({ port, host: "127.0.0.1" });
19
+ socket.once("connect", () => {
20
+ socket.destroy();
21
+ resolve(true);
22
+ });
23
+ socket.once("error", () => {
24
+ socket.destroy();
25
+ resolve(false);
26
+ });
27
+ });
28
+ }
29
+
30
+ function sleep(ms: number): Promise<void> {
31
+ return new Promise((resolve) => setTimeout(resolve, ms));
32
+ }
33
+
34
+ function stop(child: ChildProcess): Promise<void> {
35
+ if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve();
36
+ return new Promise((resolve) => {
37
+ const hardKill = setTimeout(() => child.kill("SIGKILL"), 3000);
38
+ child.once("exit", () => {
39
+ clearTimeout(hardKill);
40
+ resolve();
41
+ });
42
+ child.kill("SIGTERM");
43
+ });
44
+ }
45
+
46
+ /**
47
+ * Starts a long-running process that opens a local listener (an IAP tunnel)
48
+ * and resolves once 127.0.0.1:port accepts connections. The caller closes it
49
+ * when the connection through it is done.
50
+ */
51
+ export async function openTunnel(file: string, args: string[], options: TunnelOptions): Promise<Tunnel> {
52
+ const child = spawn(file, args, {
53
+ env: { PATH: "/usr/bin:/bin:/usr/sbin:/sbin", HOME: process.env.HOME ?? "", ...options.env },
54
+ stdio: ["ignore", "ignore", "pipe"],
55
+ });
56
+ const state = { stderr: "", ended: false, failure: "" };
57
+ child.stderr?.on("data", (chunk: Buffer) => {
58
+ state.stderr += chunk.toString("utf-8");
59
+ });
60
+ child.on("exit", (code) => {
61
+ state.ended = true;
62
+ state.failure = `exited with code ${code}`;
63
+ });
64
+ child.on("error", (err) => {
65
+ state.ended = true;
66
+ state.failure = err.message;
67
+ });
68
+ const deadline = Date.now() + options.readyTimeoutMs;
69
+ while (Date.now() < deadline) {
70
+ if (state.ended) throw new ServiceError(`${file} ${state.failure}: ${state.stderr.trim()}`);
71
+ if (await portOpen(options.port)) return { close: () => stop(child) };
72
+ await sleep(250);
73
+ }
74
+ await stop(child);
75
+ throw new ServiceError(`${file} did not listen on 127.0.0.1:${options.port} within ${options.readyTimeoutMs} ms: ${state.stderr.trim()}`);
76
+ }
@@ -0,0 +1,96 @@
1
+ #!/bin/sh
2
+ # specialist-provision: copy every Secure Note of the Vaultwarden collection
3
+ # `specialists` into ~/.specialists/secrets/<note>/<FIELD> (mode 0600).
4
+ # Fields ending in _B64 are base64-decoded and written without the suffix.
5
+ # Runs as the `specialist` user. Idempotent; stale fields are removed.
6
+ set -eu
7
+ umask 077
8
+
9
+ home="${HOME:?}"
10
+ config_dir="$home/.config/specialists"
11
+ client_file="$config_dir/client.env"
12
+ password_file="$config_dir/master-password"
13
+ root="$home/.specialists"
14
+ collection_name="${SPECIALISTS_COLLECTION:-specialists}"
15
+ BW=/usr/local/libexec/specialist-bw/current/bw
16
+ JQ=/usr/local/libexec/specialist-jq/current/jq
17
+
18
+ for f in "$client_file" "$password_file"; do
19
+ [ -f "$f" ] || { echo "missing $f" >&2; exit 2; }
20
+ done
21
+
22
+ read_value() {
23
+ awk -v key="$1" 'index($0, key "=") == 1 { sub("^[^=]*=", ""); print; found = 1; exit } END { if (!found) exit 1 }' "$client_file"
24
+ }
25
+
26
+ export BITWARDENCLI_APPDATA_DIR="$config_dir/bw-data"
27
+ export BW_CLIENTID="$(read_value BW_CLIENTID)"
28
+ export BW_CLIENTSECRET="$(read_value BW_CLIENTSECRET)"
29
+ bw_server="$(read_value BW_SERVER)"
30
+
31
+ cleanup() {
32
+ "$BW" lock >/dev/null 2>&1 || true
33
+ unset BW_CLIENTID BW_CLIENTSECRET BW_SESSION
34
+ }
35
+ trap cleanup EXIT HUP INT TERM
36
+
37
+ status_json="$("$BW" status)"
38
+ status="$(printf '%s' "$status_json" | "$JQ" -r '.status')"
39
+ current_server="$(printf '%s' "$status_json" | "$JQ" -r '.serverUrl // ""')"
40
+ if [ "$current_server" != "$bw_server" ]; then
41
+ [ "$status" = "unauthenticated" ] || "$BW" logout >/dev/null
42
+ "$BW" config server "$bw_server" >/dev/null
43
+ status="unauthenticated"
44
+ fi
45
+ case "$status" in
46
+ unauthenticated) "$BW" login --apikey >/dev/null ;;
47
+ unlocked) "$BW" lock >/dev/null ;;
48
+ locked) ;;
49
+ *) echo "unexpected bw status: $status" >&2; exit 1 ;;
50
+ esac
51
+
52
+ BW_SESSION="$("$BW" unlock --passwordfile "$password_file" --raw)"
53
+ export BW_SESSION
54
+ "$BW" sync >/dev/null
55
+
56
+ collection_id="$("$BW" list collections | "$JQ" -er --arg n "$collection_name" '[.[] | select(.name == $n) | .id] | if length == 1 then .[0] else error("collection not found or ambiguous") end')"
57
+
58
+ mkdir -p "$root/bin" "$root/config" "$root/secrets" "$root/work"
59
+ [ -f "$root/audit.log" ] || : > "$root/audit.log"
60
+
61
+ # One line per field: note<TAB>field<TAB>base64(value). Secure Notes only (type 2).
62
+ "$BW" list items --collectionid "$collection_id" |
63
+ "$JQ" -r '.[] | select(.type == 2) | .name as $n | (.fields // [])[] | select(.value != null and .value != "") | [$n, .name, (.value | @base64)] | @tsv' |
64
+ while IFS="$(printf '\t')" read -r note field value_b64; do
65
+ case "$note" in ""|*[!a-z0-9-]*) echo "skip note with unsupported name: $note" >&2; continue ;; esac
66
+ case "$field" in ""|*[!A-Z0-9_]*) echo "skip field with unsupported name: $note/$field" >&2; continue ;; esac
67
+ dir="$root/secrets/$note"
68
+ mkdir -p "$dir"
69
+ target="$field"
70
+ case "$field" in *_B64) target="${field%_B64}" ;; esac
71
+ tmp="$dir/.$target.tmp"
72
+ if [ "$target" != "$field" ]; then
73
+ printf '%s' "$value_b64" | base64 -d | base64 -d > "$tmp"
74
+ else
75
+ printf '%s' "$value_b64" | base64 -d > "$tmp"
76
+ fi
77
+ chmod 600 "$tmp"
78
+ mv -f "$tmp" "$dir/$target"
79
+ printf '%s\t%s\n' "$note" "$target" >> "$root/.provisioned.$$"
80
+ done
81
+
82
+ # Remove files no longer present in Vaultwarden.
83
+ if [ -f "$root/.provisioned.$$" ]; then
84
+ for dir in "$root"/secrets/*/; do
85
+ [ -d "$dir" ] || continue
86
+ note="$(basename "$dir")"
87
+ for file in "$dir"*; do
88
+ [ -f "$file" ] || continue
89
+ name="$(basename "$file")"
90
+ grep -qx "$(printf '%s\t%s' "$note" "$name")" "$root/.provisioned.$$" || { rm -f "$file"; echo "removed stale $note/$name" >&2; }
91
+ done
92
+ done
93
+ awk -F '\t' '{ print $1 "/" $2 }' "$root/.provisioned.$$" | sort
94
+ rm -f "$root/.provisioned.$$"
95
+ fi
96
+ unset BW_CLIENTID BW_CLIENTSECRET BW_SESSION