code60-transmission-server 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.
Files changed (95) hide show
  1. package/INTENT.md +47 -0
  2. package/README.md +87 -240
  3. package/dist/src/acp.js +130 -0
  4. package/dist/src/contract.js +133 -0
  5. package/dist/src/engine.js +650 -0
  6. package/dist/src/linux.js +84 -0
  7. package/dist/src/main.js +81 -22
  8. package/dist/src/repository.js +94 -0
  9. package/dist/src/service.js +196 -0
  10. package/package.json +19 -33
  11. package/reference/openapi.json +1073 -0
  12. package/README.engine.md +0 -401
  13. package/dist/src/broker/filesystem.js +0 -385
  14. package/dist/src/broker/index.js +0 -734
  15. package/dist/src/broker/native/README.md +0 -192
  16. package/dist/src/broker/native/build.js +0 -43
  17. package/dist/src/broker/native/fs-helper.c +0 -529
  18. package/dist/src/broker/native/git-helper.c +0 -176
  19. package/dist/src/broker/policy.js +0 -149
  20. package/dist/src/broker/startup-lock.js +0 -14
  21. package/dist/src/broker/types.js +0 -11
  22. package/dist/src/cli/daemon.js +0 -365
  23. package/dist/src/cli/helpers.js +0 -104
  24. package/dist/src/cli/main.js +0 -180
  25. package/dist/src/config/deployment.js +0 -163
  26. package/dist/src/config/documents.js +0 -29
  27. package/dist/src/config/profile-validation.js +0 -123
  28. package/dist/src/config/schema-graph.js +0 -237
  29. package/dist/src/config/schema-loader.js +0 -185
  30. package/dist/src/config/validation-pool.js +0 -105
  31. package/dist/src/config/validation-protocol.js +0 -1
  32. package/dist/src/config/validation-worker.js +0 -106
  33. package/dist/src/config/workflow-language.js +0 -9
  34. package/dist/src/config/workflow-schema.json +0 -534
  35. package/dist/src/config/workflow-types.js +0 -1
  36. package/dist/src/config/workflow-validation.js +0 -95
  37. package/dist/src/engine/budgets.js +0 -50
  38. package/dist/src/engine/clocks.js +0 -27
  39. package/dist/src/engine/commands.js +0 -441
  40. package/dist/src/engine/contracts.js +0 -11
  41. package/dist/src/engine/drain-state.js +0 -31
  42. package/dist/src/engine/effective-permissions.js +0 -120
  43. package/dist/src/engine/instruction-pins.js +0 -205
  44. package/dist/src/engine/retries.js +0 -50
  45. package/dist/src/engine/state.js +0 -1
  46. package/dist/src/engine/timing.js +0 -23
  47. package/dist/src/engine/tool-observations.js +0 -87
  48. package/dist/src/engine/workflow-engine.js +0 -1807
  49. package/dist/src/mcp/catalog.js +0 -71
  50. package/dist/src/mcp/main.js +0 -24
  51. package/dist/src/mcp/server.js +0 -103
  52. package/dist/src/runtime/codex-app-server.js +0 -91
  53. package/dist/src/runtime/containment.js +0 -82
  54. package/dist/src/runtime/engine-driver.js +0 -212
  55. package/dist/src/runtime/json-line-writer.js +0 -192
  56. package/dist/src/runtime/pinned-instruction-sources.js +0 -24
  57. package/dist/src/runtime/protocol-client.js +0 -264
  58. package/dist/src/runtime/protocol-pool.js +0 -183
  59. package/dist/src/runtime/protocol-projection.js +0 -393
  60. package/dist/src/runtime/protocol-types.js +0 -1
  61. package/dist/src/runtime/protocol-worker.js +0 -18
  62. package/dist/src/runtime/provider-bridge.js +0 -288
  63. package/dist/src/runtime/provider-credentials.js +0 -41
  64. package/dist/src/runtime/provider-transport.js +0 -404
  65. package/dist/src/runtime/runtime-broker.js +0 -213
  66. package/dist/src/runtime/workspace-instructions.js +0 -120
  67. package/dist/src/runtime/workspace-view.js +0 -74
  68. package/dist/src/server/api-contract.json +0 -11078
  69. package/dist/src/server/api-types.js +0 -1
  70. package/dist/src/server/application.js +0 -38
  71. package/dist/src/server/auth.js +0 -67
  72. package/dist/src/server/broker-handlers.js +0 -242
  73. package/dist/src/server/control-plane.js +0 -50
  74. package/dist/src/server/deployment.js +0 -237
  75. package/dist/src/server/errors.js +0 -22
  76. package/dist/src/server/history-handlers.js +0 -113
  77. package/dist/src/server/http.js +0 -124
  78. package/dist/src/server/paging.js +0 -56
  79. package/dist/src/server/publication.js +0 -119
  80. package/dist/src/server/tool-event-handler.js +0 -77
  81. package/dist/src/server/workspace-handlers.js +0 -34
  82. package/dist/src/storage/coordinator.js +0 -224
  83. package/dist/src/storage/startup-lock.js +0 -71
  84. package/dist/src/storage/store.js +0 -167
  85. package/dist/src/tools/check-worker.js +0 -81
  86. package/dist/src/tools/checks.js +0 -106
  87. package/dist/src/tools/dns.js +0 -248
  88. package/dist/src/tools/http-contract.js +0 -38
  89. package/dist/src/tools/http.js +0 -358
  90. package/dist/src/tools/index.js +0 -177
  91. package/dist/src/tools/worker-check.js +0 -73
  92. package/dist/src/workspaces/git.js +0 -163
  93. package/dist/src/workspaces/index.js +0 -715
  94. package/examples/deployment.local.json +0 -22
  95. package/scripts/postinstall.mjs +0 -25
@@ -1,176 +0,0 @@
1
- #define _DARWIN_C_SOURCE
2
- #define _POSIX_C_SOURCE 200809L
3
- #include <sys/types.h>
4
- #include <sys/stat.h>
5
- #include <sys/file.h>
6
- #include <dirent.h>
7
- #include <errno.h>
8
- #include <fcntl.h>
9
- #include <inttypes.h>
10
- #include <stdio.h>
11
- #include <stdlib.h>
12
- #include <string.h>
13
- #include <unistd.h>
14
-
15
- /* Trusted engine plumbing only, never an agent tool. fd3 is a pinned workspace.
16
- * No arbitrary executable, Git subcommand, option, path, environment or shell.
17
- * Effects additionally run under the Git driver's deny-default Seatbelt policy. */
18
- static void die(void) { fputs("git_helper_denied\n", stderr); exit(74); }
19
- static int directory(int fd) {
20
- struct stat s;
21
- return fstat(fd, &s) == 0 && S_ISDIR(s.st_mode) && s.st_uid == geteuid() && !(s.st_mode & 022);
22
- }
23
- static int regular(const struct stat *s) {
24
- return S_ISREG(s->st_mode) && s->st_uid == geteuid() && s->st_nlink == 1 && !(s->st_mode & 022);
25
- }
26
- static int hex(const char *s) {
27
- if (strlen(s) != 40) return 0;
28
- for (; *s; s++) if (!((*s >= '0' && *s <= '9') || (*s >= 'a' && *s <= 'f'))) return 0;
29
- return 1;
30
- }
31
- static int token(const char *s) {
32
- if (strlen(s) != 36) return 0;
33
- for (; *s; s++) if (!((*s >= '0' && *s <= '9') || (*s >= 'a' && *s <= 'f') || *s == '-')) return 0;
34
- return 1;
35
- }
36
- static int ref(const char *s) {
37
- if (strncmp(s, "refs/heads/", 11) && strncmp(s, "refs/code60/", 12)) return 0;
38
- if (strlen(s) > 512 || strstr(s, "..") || strstr(s, "//") || strstr(s, "@{") || s[strlen(s)-1] == '/') return 0;
39
- for (; *s; s++) if (!((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
40
- (*s >= '0' && *s <= '9') || strchr("/-_.", *s))) return 0;
41
- return 1;
42
- }
43
- static unsigned entries;
44
- static void inspect(int fd, unsigned depth) {
45
- if (depth > 64 || !directory(fd)) die();
46
- int copy = openat(fd, ".", O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
47
- if (copy < 0) die();
48
- DIR *dir = fdopendir(copy); if (!dir) die();
49
- struct dirent *entry;
50
- while ((entry = readdir(dir))) {
51
- if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue;
52
- if (++entries > 100000) die();
53
- struct stat s;
54
- if (fstatat(fd, entry->d_name, &s, AT_SYMLINK_NOFOLLOW) < 0) die();
55
- if (S_ISDIR(s.st_mode)) {
56
- int child = openat(fd, entry->d_name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
57
- if (child < 0) die();
58
- inspect(child, depth + 1); close(child);
59
- } else if (!regular(&s)) die();
60
- }
61
- closedir(dir);
62
- }
63
- static void identity(char *out, size_t capacity, const struct stat *s) {
64
- int n = snprintf(out, capacity, "%ju:%ju:%ju:%jd:%jd:%ld:%jd:%ld",
65
- (uintmax_t)s->st_dev, (uintmax_t)s->st_ino, (uintmax_t)s->st_mode, (intmax_t)s->st_size,
66
- (intmax_t)s->st_mtimespec.tv_sec, s->st_mtimespec.tv_nsec, (intmax_t)s->st_ctimespec.tv_sec, s->st_ctimespec.tv_nsec);
67
- if (n < 0 || (size_t)n >= capacity) die();
68
- }
69
- static void read_file(int git, const char *name, int index) {
70
- int fd = openat(git, name, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
71
- if (fd < 0) { if (index && errno == ENOENT) { puts("absent"); return; } die(); }
72
- struct stat s;
73
- if (fstat(fd, &s) < 0 || !regular(&s) || s.st_size < 0 || s.st_size > (index ? 16777216 : 65536)) die();
74
- if (index) { char id[256]; identity(id, sizeof(id), &s); puts(id); fflush(stdout); }
75
- char buffer[8192]; ssize_t n;
76
- while ((n = read(fd, buffer, sizeof(buffer))) > 0) if (write(STDOUT_FILENO, buffer, (size_t)n) != n) die();
77
- if (n < 0) die();
78
- struct stat after; char before_id[256], after_id[256];
79
- if (fstat(fd, &after) < 0) die();
80
- identity(before_id, sizeof(before_id), &s); identity(after_id, sizeof(after_id), &after);
81
- if (strcmp(before_id, after_id)) die();
82
- close(fd);
83
- }
84
- static void install_index(int git, const char *id, const char *expected) {
85
- if (!token(id)) die();
86
- char candidate[80], backup[80], actual[256];
87
- snprintf(candidate, sizeof(candidate), ".code60-index-%s", id);
88
- snprintf(backup, sizeof(backup), ".code60-index-backup-%s", id);
89
- struct stat next, before, captured;
90
- if (fstatat(git, candidate, &next, AT_SYMLINK_NOFOLLOW) < 0 || !regular(&next)) die();
91
- int exists = fstatat(git, "index", &before, AT_SYMLINK_NOFOLLOW) == 0;
92
- if (exists) { if (!regular(&before)) die(); identity(actual, sizeof(actual), &before); }
93
- else strcpy(actual, "absent");
94
- if (strcmp(actual, expected)) die();
95
- if (exists) {
96
- if (renameatx_np(git, "index", git, backup, RENAME_EXCL) < 0) die();
97
- if (fstatat(git, backup, &captured, AT_SYMLINK_NOFOLLOW) < 0 || !regular(&captured) ||
98
- captured.st_dev != before.st_dev || captured.st_ino != before.st_ino ||
99
- captured.st_size != before.st_size || captured.st_mode != before.st_mode ||
100
- captured.st_mtimespec.tv_sec != before.st_mtimespec.tv_sec || captured.st_mtimespec.tv_nsec != before.st_mtimespec.tv_nsec) {
101
- (void)renameatx_np(git, backup, git, "index", RENAME_EXCL); die();
102
- }
103
- }
104
- if (renameatx_np(git, candidate, git, "index", RENAME_EXCL) < 0) {
105
- if (exists) (void)renameatx_np(git, backup, git, "index", RENAME_EXCL);
106
- die();
107
- }
108
- if (fsync(git) < 0) die();
109
- /* Backups are deliberately retained; never erase an unexpected index. */
110
- }
111
- int main(int argc, char **argv) {
112
- if (argc == 2 && !strcmp(argv[1], "startup-lock")) {
113
- /* fd3 is an engine-private O_NOFOLLOW opened, empty mode-0600 lock file.
114
- * flock belongs to the shared OPEN DESCRIPTION, not this helper's PID.
115
- * NEVER LOCK_UN: the engine and every effect child retain this description. */
116
- struct stat lock;
117
- if (fstat(3, &lock) < 0 || !regular(&lock) || (lock.st_mode & 077) || lock.st_size) die();
118
- if (flock(3, LOCK_EX | LOCK_NB) < 0) {
119
- if (errno == EWOULDBLOCK || errno == EAGAIN) return 75;
120
- die();
121
- }
122
- puts("locked"); return 0;
123
- }
124
- if (argc < 2 || argc > 7 || !directory(3)) die();
125
- int git = openat(3, ".git", O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
126
- if (git < 0 || !directory(git)) die();
127
- struct stat s; if (fstat(git, &s) < 0) die();
128
- char git_id[128]; snprintf(git_id, sizeof(git_id), "%ju:%ju", (uintmax_t)s.st_dev, (uintmax_t)s.st_ino);
129
- if (!strcmp(argv[1], "probe") && argc == 2) { puts(git_id); return 0; }
130
- if (argc < 3 || strcmp(argv[2], git_id)) die();
131
- inspect(git, 0);
132
- const char *unsupported[] = {"commondir", "shallow", "info/grafts", "objects/info/alternates", "objects/info/http-alternates",
133
- "info/sparse-checkout", "refs/replace", "worktrees", "MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD",
134
- "rebase-apply", "rebase-merge", "BISECT_LOG", "index.lock", "HEAD.lock", "packed-refs.lock", NULL};
135
- for (size_t i = 0; unsupported[i]; i++) {
136
- struct stat feature;
137
- if (fstatat(git, unsupported[i], &feature, AT_SYMLINK_NOFOLLOW) == 0 || errno != ENOENT) die();
138
- }
139
- if (!strcmp(argv[1], "config") && argc == 3) { read_file(git, "config", 0); return 0; }
140
- if (!strcmp(argv[1], "index") && argc == 3) { read_file(git, "index", 1); return 0; }
141
- if (!strcmp(argv[1], "install-index") && argc == 5) { install_index(git, argv[3], argv[4]); return 0; }
142
- char *args[64] = {"/Library/Developer/CommandLineTools/usr/bin/git", "--git-dir=.",
143
- "-c", "core.bare=true", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false",
144
- "-c", "core.attributesFile=/dev/null", "-c", "core.excludesFile=/dev/null",
145
- "-c", "core.sparseCheckout=false", "-c", "index.sparse=false",
146
- "-c", "credential.helper=", "-c", "protocol.allow=never", "-c", "submodule.recurse=false",
147
- "-c", "commit.gpgSign=false", "-c", "gc.auto=0", "-c", "maintenance.auto=false",
148
- "-c", "user.useConfigOnly=true", NULL};
149
- int n = 30; /* first unused slot above */
150
- while (args[n]) n++;
151
- const char *verb = argv[1];
152
- if (!strcmp(verb, "head") && argc == 3) { args[n++] = "rev-parse"; args[n++] = "--verify"; args[n++] = "HEAD"; }
153
- else if (!strcmp(verb, "branch") && argc == 3) { args[n++] = "symbolic-ref"; args[n++] = "--quiet"; args[n++] = "HEAD"; }
154
- else if (!strcmp(verb, "identity") && argc == 3) { args[n++] = "var"; args[n++] = "GIT_AUTHOR_IDENT"; }
155
- else if (!strcmp(verb, "committer") && argc == 3) { args[n++] = "var"; args[n++] = "GIT_COMMITTER_IDENT"; }
156
- else if (!strcmp(verb, "hash") && argc == 3) { args[n++] = "hash-object"; args[n++] = "-w"; args[n++] = "--stdin"; }
157
- else if (!strcmp(verb, "tree") && argc == 3) { args[n++] = "mktree"; args[n++] = "-z"; }
158
- else if (!strcmp(verb, "ls-tree") && argc == 4 && hex(argv[3])) {
159
- args[n++] = "ls-tree"; args[n++] = "-rz"; args[n++] = "--full-tree"; args[n++] = argv[3];
160
- } else if (!strcmp(verb, "index-tree") && argc == 3) { args[n++] = "ls-files"; args[n++] = "--stage"; args[n++] = "-z"; }
161
- else if (!strcmp(verb, "commit") && argc == 5 && hex(argv[3]) && hex(argv[4])) {
162
- args[n++] = "commit-tree"; args[n++] = argv[3]; args[n++] = "-p"; args[n++] = argv[4];
163
- } else if (!strcmp(verb, "ref") && argc == 6 && ref(argv[3]) && hex(argv[4]) && hex(argv[5])) {
164
- args[n++] = "update-ref"; args[n++] = "--no-deref"; args[n++] = "-m"; args[n++] = "Code60 journal";
165
- args[n++] = argv[3]; args[n++] = argv[4]; args[n++] = argv[5];
166
- } else if (!strcmp(verb, "read-tree") && argc == 5 && hex(argv[3]) && token(argv[4])) {
167
- char index[80]; snprintf(index, sizeof(index), ".code60-index-%s", argv[4]);
168
- if (setenv("GIT_INDEX_FILE", index, 1) < 0) die();
169
- args[n++] = "read-tree"; args[n++] = "--reset"; args[n++] = argv[3];
170
- } else die();
171
- args[n] = NULL;
172
- if (fchdir(git) < 0) die();
173
- close(3); close(git);
174
- execv("/Library/Developer/CommandLineTools/usr/bin/git", args);
175
- die();
176
- }
@@ -1,149 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { isIP } from "node:net";
3
- import { domainToASCII } from "node:url";
4
- import { BrokerError } from "./types.js";
5
- export function canonical(value) {
6
- const ancestors = new Set();
7
- const visit = (v) => {
8
- if (v === null || typeof v === "string" || typeof v === "boolean")
9
- return JSON.stringify(v);
10
- if (typeof v === "number" && Number.isFinite(v))
11
- return JSON.stringify(v);
12
- if (typeof v !== "object" || v === null || ancestors.has(v))
13
- throw new BrokerError("invalid_json", 400);
14
- if (!Array.isArray(v) && Object.getPrototypeOf(v) !== Object.prototype && Object.getPrototypeOf(v) !== null) {
15
- throw new BrokerError("invalid_json", 400);
16
- }
17
- ancestors.add(v);
18
- let result;
19
- if (Array.isArray(v)) {
20
- if (Object.keys(v).length !== v.length)
21
- throw new BrokerError("invalid_json", 400);
22
- result = `[${v.map(visit).join(",")}]`;
23
- }
24
- else {
25
- result = `{${Object.keys(v).sort().map(k => `${JSON.stringify(k)}:${visit(v[k])}`).join(",")}}`;
26
- }
27
- ancestors.delete(v);
28
- return result;
29
- };
30
- return visit(value);
31
- }
32
- export function digest(value) {
33
- return `sha256:${createHash("sha256").update(canonical(value)).digest("hex")}`;
34
- }
35
- export function jsonCopy(value) { return JSON.parse(canonical(value)); }
36
- export function relativePath(path) {
37
- if (path === ".")
38
- return path;
39
- if (!path || /[\\\0]/u.test(path) || path.startsWith("/") ||
40
- path.split("/").some(c => !c || c === "." || c === ".."))
41
- throw new BrokerError("invalid_resource_path", 422);
42
- return path;
43
- }
44
- export function normalizeHost(host) {
45
- const raw = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
46
- if (isIP(raw) === 6)
47
- return new URL(`http://[${raw}]/`).hostname.slice(1, -1);
48
- if (isIP(raw) === 4)
49
- return raw;
50
- if (/[:/%\\\s@?#]/u.test(raw))
51
- throw new BrokerError("invalid_network_host", 422);
52
- const ascii = domainToASCII(raw.toLowerCase().replace(/\.$/u, ""));
53
- if (!ascii || ascii.length > 253 || ascii.split(".").some(l => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u.test(l))) {
54
- throw new BrokerError("invalid_network_host", 422);
55
- }
56
- // Reject alternate numeric IPv4 spellings rather than delegating their interpretation.
57
- if (/^[0-9.]+$/u.test(ascii) || /^0x/iu.test(ascii))
58
- throw new BrokerError("invalid_network_host", 422);
59
- return ascii;
60
- }
61
- export function normalizeResources(resources) {
62
- return resources.map(input => {
63
- const r = jsonCopy(input);
64
- if (!/^sha256:[a-f0-9]{64}$/u.test(r.identityDigest))
65
- throw new BrokerError("invalid_resource_identity", 422);
66
- if (r.kind === "filesystem") {
67
- if (!["workspace", "scratch", "deployment"].includes(r.root) || !["read", "write", "delete"].includes(r.operation) ||
68
- (r.root === "deployment" ? !r.rootId : r.rootId !== undefined))
69
- throw new BrokerError("invalid_resource", 422);
70
- r.path = relativePath(r.path);
71
- }
72
- else if (r.kind === "network") {
73
- if (!["http", "https", "tcp", "udp"].includes(r.protocol) || !Number.isInteger(r.port) || r.port < 1 || r.port > 65535) {
74
- throw new BrokerError("invalid_resource", 422);
75
- }
76
- r.host = normalizeHost(r.host);
77
- }
78
- else
79
- throw new BrokerError("invalid_resource", 422);
80
- return r;
81
- });
82
- }
83
- function strongest(effects) {
84
- return effects.includes("deny") ? "deny" : effects.includes("require_approval") ? "require_approval" : effects.includes("allow") ? "allow" : "deny";
85
- }
86
- export function validatePolicy(policy) {
87
- if (policy.defaultEffect !== "deny" || !Array.isArray(policy.rules))
88
- throw new BrokerError("invalid_policy", 422);
89
- for (const rule of policy.rules) {
90
- if (!["deny", "require_approval", "allow"].includes(rule.effect))
91
- throw new BrokerError("invalid_policy", 422);
92
- if (rule.kind === "tool") {
93
- if (typeof rule.toolId !== "string" || !rule.toolId)
94
- throw new BrokerError("invalid_policy", 422);
95
- }
96
- else if (rule.kind === "filesystem") {
97
- relativePath(rule.path);
98
- if (!["workspace", "scratch", "deployment"].includes(rule.root) || typeof rule.recursive !== "boolean" ||
99
- (rule.root === "deployment" ? !rule.rootId : rule.rootId !== undefined) ||
100
- !Array.isArray(rule.operations) || !rule.operations.length ||
101
- rule.operations.some(op => !["read", "write", "delete"].includes(op)))
102
- throw new BrokerError("invalid_policy", 422);
103
- }
104
- else if (rule.kind === "network") {
105
- if (rule.host !== "*")
106
- normalizeHost(rule.host);
107
- if (!["http", "https", "tcp", "udp"].includes(rule.protocol) || !Number.isInteger(rule.port) ||
108
- rule.port < 1 || rule.port > 65535)
109
- throw new BrokerError("invalid_policy", 422);
110
- }
111
- else
112
- throw new BrokerError("invalid_policy", 422);
113
- }
114
- }
115
- function matches(rule, tool, resource) {
116
- if (tool !== undefined)
117
- return rule.kind === "tool" && (rule.toolId === "*" || rule.toolId === tool);
118
- if (!resource || rule.kind !== resource.kind)
119
- return false;
120
- if (rule.kind === "filesystem" && resource.kind === "filesystem") {
121
- relativePath(rule.path);
122
- return rule.root === resource.root && rule.rootId === resource.rootId && rule.operations.includes(resource.operation) &&
123
- (rule.path === resource.path || (rule.recursive && (rule.path === "." || resource.path.startsWith(`${rule.path}/`))));
124
- }
125
- return rule.kind === "network" && resource.kind === "network" &&
126
- rule.protocol === resource.protocol && rule.port === resource.port &&
127
- (rule.host === "*" || normalizeHost(rule.host) === resource.host);
128
- }
129
- export function evaluatePolicy(policy, toolId, resources) {
130
- validatePolicy(policy);
131
- const each = [strongest(policy.rules.filter(r => matches(r, toolId, undefined)).map(r => r.effect))];
132
- for (const resource of normalizeResources(resources)) {
133
- each.push(strongest(policy.rules.filter(r => matches(r, undefined, resource)).map(r => r.effect)));
134
- }
135
- return strongest(each.includes("deny") ? ["deny"] : each);
136
- }
137
- export function evaluate(binding, toolId, resources) {
138
- const actual = normalizeResources(resources);
139
- if (!binding.configuredTools.includes(toolId) ||
140
- (binding.role === "verifier" && actual.some(r => r.kind === "filesystem" && r.root === "workspace" && r.operation !== "read")))
141
- return "deny";
142
- const effects = [evaluatePolicy(binding.permissions, toolId, actual), evaluatePolicy(binding.deploymentPermissions, toolId, actual)];
143
- return effects.includes("deny") ? "deny" : strongest(effects);
144
- }
145
- export function actionDigests(_binding, toolId, arguments_, resources) {
146
- // Pinned source fixtures hash ActionSpec itself. Scope is independently bound
147
- // by the immutable action/claim row and checked on every admission and dispatch.
148
- return { actionDigest: digest({ toolId, arguments: arguments_, resources }), resourceDigest: digest(resources) };
149
- }
@@ -1,14 +0,0 @@
1
- import { fstatSync } from "node:fs";
2
- import { BrokerError } from "./types.js";
3
- /** Root acquires this SAME open description with git-helper startup-lock BEFORE
4
- * opening/recovering mutable engine state. Borrowed FDs are close-only: never
5
- * LOCK_UN. Every writer child inherits it until that child actually exits. */
6
- export function startupLockIdentity(fd) {
7
- if (!Number.isInteger(fd) || fd < 0)
8
- throw new BrokerError("invalid_startup_lock", 422);
9
- const stat = fstatSync(fd, { bigint: true });
10
- if (!stat.isFile() || stat.uid !== BigInt(process.geteuid()) || stat.nlink !== 1n ||
11
- stat.size !== 0n || (stat.mode & 63n))
12
- throw new BrokerError("invalid_startup_lock", 422);
13
- return `${stat.dev}:${stat.ino}`;
14
- }
@@ -1,11 +0,0 @@
1
- export class BrokerError extends Error {
2
- code;
3
- status;
4
- persist;
5
- constructor(code, status = 409, persist = false) {
6
- super(code);
7
- this.code = code;
8
- this.status = status;
9
- this.persist = persist;
10
- }
11
- }