@sigrun/sigrun 0.0.0-stage → 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 (130) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/CONTEXT.md +163 -0
  3. package/LICENSE +21 -0
  4. package/README.md +691 -2
  5. package/THIRD_PARTY_NOTICES.md +28 -0
  6. package/dist/backup/marker.js +80 -0
  7. package/dist/backup/run-backup.js +339 -0
  8. package/dist/cli.js +952 -0
  9. package/dist/commands/expand.js +245 -0
  10. package/dist/commands/templates.js +272 -0
  11. package/dist/config.js +1146 -0
  12. package/dist/extension.d.ts +431 -0
  13. package/dist/harness/activity.js +42 -0
  14. package/dist/harness/ambient.js +261 -0
  15. package/dist/harness/auth.js +130 -0
  16. package/dist/harness/boot.js +865 -0
  17. package/dist/harness/builtins.js +191 -0
  18. package/dist/harness/event-bus.js +1203 -0
  19. package/dist/harness/health.js +30 -0
  20. package/dist/harness/identity/index.js +37 -0
  21. package/dist/harness/identity/invites.js +94 -0
  22. package/dist/harness/identity/json-store.js +108 -0
  23. package/dist/harness/identity/setup-code.js +81 -0
  24. package/dist/harness/identity/tokens.js +101 -0
  25. package/dist/harness/identity/users.js +93 -0
  26. package/dist/harness/interactions.js +283 -0
  27. package/dist/harness/loader.js +1236 -0
  28. package/dist/harness/memory-default.js +35 -0
  29. package/dist/harness/naming.js +193 -0
  30. package/dist/harness/packages.js +1002 -0
  31. package/dist/harness/providers/auth-bridge.js +60 -0
  32. package/dist/harness/providers/index.js +277 -0
  33. package/dist/harness/providers/models-store.js +105 -0
  34. package/dist/harness/providers/refresh.js +161 -0
  35. package/dist/harness/providers/scheduler.js +89 -0
  36. package/dist/harness/registry.js +9 -0
  37. package/dist/harness/reserved-sections.js +24 -0
  38. package/dist/harness/seam-host.js +239 -0
  39. package/dist/harness/sections/context-files.js +78 -0
  40. package/dist/harness/sections/model-guidance.js +77 -0
  41. package/dist/harness/settings.js +1053 -0
  42. package/dist/harness/stores.js +450 -0
  43. package/dist/harness/tools.js +500 -0
  44. package/dist/harness/workspace.js +73 -0
  45. package/dist/index.js +39 -0
  46. package/dist/jobs/docs.js +257 -0
  47. package/dist/jobs/fire.js +342 -0
  48. package/dist/jobs/index.js +228 -0
  49. package/dist/jobs/observe.js +165 -0
  50. package/dist/jobs/reconcile.js +245 -0
  51. package/dist/jobs/schedule.js +77 -0
  52. package/dist/jobs/spec.js +248 -0
  53. package/dist/jobs/task.js +190 -0
  54. package/dist/jobs/transfer.js +53 -0
  55. package/dist/serve.js +164 -0
  56. package/dist/server/auth/claim-lock.js +28 -0
  57. package/dist/server/auth/ip.js +51 -0
  58. package/dist/server/auth/login-limiter.js +52 -0
  59. package/dist/server/auth/loopback.js +47 -0
  60. package/dist/server/auth/pipeline.js +330 -0
  61. package/dist/server/auth/principal.js +26 -0
  62. package/dist/server/commands.js +198 -0
  63. package/dist/server/content-parts.js +142 -0
  64. package/dist/server/context.js +13 -0
  65. package/dist/server/conversation-handler.js +61 -0
  66. package/dist/server/conversation-ops.js +310 -0
  67. package/dist/server/events/hub.js +39 -0
  68. package/dist/server/events/types.js +8 -0
  69. package/dist/server/helpers.js +351 -0
  70. package/dist/server/host-bridge.js +131 -0
  71. package/dist/server/index.js +232 -0
  72. package/dist/server/notifications.js +185 -0
  73. package/dist/server/ownership.js +67 -0
  74. package/dist/server/readiness.js +36 -0
  75. package/dist/server/routes/auth.js +172 -0
  76. package/dist/server/routes/conversations.js +341 -0
  77. package/dist/server/routes/events.js +161 -0
  78. package/dist/server/routes/extension-routes.js +127 -0
  79. package/dist/server/routes/extensions.js +168 -0
  80. package/dist/server/routes/files.js +308 -0
  81. package/dist/server/routes/interactions.js +260 -0
  82. package/dist/server/routes/jobs.js +271 -0
  83. package/dist/server/routes/meta.js +146 -0
  84. package/dist/server/routes/metrics.js +219 -0
  85. package/dist/server/routes/onboarding.js +268 -0
  86. package/dist/server/routes/probes.js +53 -0
  87. package/dist/server/routes/providers.js +198 -0
  88. package/dist/server/routes/settings.js +48 -0
  89. package/dist/server/routes/stream.js +131 -0
  90. package/dist/server/routes/submissions.js +317 -0
  91. package/dist/server/routes/users.js +169 -0
  92. package/dist/server/schema-fixture.js +950 -0
  93. package/dist/server/session-meta.js +247 -0
  94. package/dist/server/static.js +169 -0
  95. package/dist/server/views.js +71 -0
  96. package/dist/skills/index.js +418 -0
  97. package/node_modules/@sigrun/shared/CHANGELOG.md +16 -0
  98. package/node_modules/@sigrun/shared/LICENSE +21 -0
  99. package/node_modules/@sigrun/shared/README.md +10 -0
  100. package/node_modules/@sigrun/shared/dist/access.d.ts +55 -0
  101. package/node_modules/@sigrun/shared/dist/access.js +72 -0
  102. package/node_modules/@sigrun/shared/dist/ambient.d.ts +111 -0
  103. package/node_modules/@sigrun/shared/dist/ambient.js +23 -0
  104. package/node_modules/@sigrun/shared/dist/commands.d.ts +75 -0
  105. package/node_modules/@sigrun/shared/dist/commands.js +25 -0
  106. package/node_modules/@sigrun/shared/dist/conversations.d.ts +31 -0
  107. package/node_modules/@sigrun/shared/dist/conversations.js +94 -0
  108. package/node_modules/@sigrun/shared/dist/interactions.d.ts +91 -0
  109. package/node_modules/@sigrun/shared/dist/interactions.js +21 -0
  110. package/node_modules/@sigrun/shared/dist/jobs.d.ts +100 -0
  111. package/node_modules/@sigrun/shared/dist/jobs.js +19 -0
  112. package/node_modules/@sigrun/shared/dist/json.d.ts +20 -0
  113. package/node_modules/@sigrun/shared/dist/json.js +13 -0
  114. package/node_modules/@sigrun/shared/dist/session-meta.d.ts +103 -0
  115. package/node_modules/@sigrun/shared/dist/session-meta.js +13 -0
  116. package/node_modules/@sigrun/shared/dist/settings.d.ts +401 -0
  117. package/node_modules/@sigrun/shared/dist/settings.js +19 -0
  118. package/node_modules/@sigrun/shared/dist/themes.d.ts +50 -0
  119. package/node_modules/@sigrun/shared/dist/themes.js +156 -0
  120. package/node_modules/@sigrun/shared/dist/turns.d.ts +102 -0
  121. package/node_modules/@sigrun/shared/dist/turns.js +166 -0
  122. package/node_modules/@sigrun/shared/dist/view-delta.d.ts +54 -0
  123. package/node_modules/@sigrun/shared/dist/view-delta.js +135 -0
  124. package/node_modules/@sigrun/shared/dist/views.d.ts +742 -0
  125. package/node_modules/@sigrun/shared/dist/views.js +38 -0
  126. package/node_modules/@sigrun/shared/package.json +83 -0
  127. package/package.json +89 -5
  128. package/webui/dist/assets/index-Rl0KhCLa.css +1 -0
  129. package/webui/dist/assets/index-rOiARZLF.js +50 -0
  130. package/webui/dist/index.html +37 -0
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Built-in extensions (Task 2, pi parity): codemode, MCP and tool search
3
+ * ship WITH core — present by default, disableable via settings
4
+ * `builtinExtensions`, replaceable by a same-named configured extension.
5
+ *
6
+ * pi 1.3.0 ships these three as built-ins; a default sigrun install
7
+ * mirrors that, so a friend installing sigrun gets pi's tool surface
8
+ * without configuring anything.
9
+ *
10
+ * Resolution root (Ruling 2): built-ins resolve through core's OWN
11
+ * node_modules via `createRequire(import.meta.url)` — they are core
12
+ * `dependencies`, never installed into the packages dir, and never pass
13
+ * through `syncPackages`. A built-in that cannot be resolved from core's
14
+ * tree at all yields an entry whose `import()` fails, and the loader
15
+ * quarantines it (one `status: "quarantined"` outcome naming the
16
+ * package), boot continues — never a throw (Ruling 7).
17
+ *
18
+ * Replacement (Ruling 5): a configured extension whose resolved package
19
+ * name equals a built-in's name REPLACES that built-in — the built-in is
20
+ * skipped, the configured one loads normally, one warning names both, and
21
+ * `/v1/extensions` reports the built-in's row with `builtin: true` plus
22
+ * `replacedBy: "<the configured specifier>"`. The configured name is
23
+ * derived from its specifier through the packages helpers
24
+ * (`readPackageName` for path-shaped entries, `parsePackageSpecifier`
25
+ * otherwise), never by string equality on the raw specifier.
26
+ *
27
+ * Disabled (Ruling 6): `builtinExtensions: {codemode?, mcp?, toolSearch?}`
28
+ * (each defaulting to `true`, restart-required). A disabled built-in is
29
+ * absent from `/v1/extensions` entirely; one log line records the skip.
30
+ *
31
+ * Quarantine test seam: callers may pass additional specifier strings
32
+ * (`resolveBuiltins`'s third parameter), resolved like the real built-ins
33
+ * (through core's tree; an absolute path passes through verbatim). The
34
+ * boot wires it from `OpenHarnessOptions.extraBuiltins` — the hermetic
35
+ * seam the quarantine test uses, never a settings field.
36
+ */
37
+ import { createRequire } from "node:module";
38
+ import { basename, dirname, isAbsolute, resolve } from "node:path";
39
+ import { fileURLToPath, pathToFileURL } from "node:url";
40
+ import { parsePackageSpecifier, readPackageName } from "./packages.js";
41
+ /**
42
+ * The three built-ins, in load order (codemode before tool-search: both
43
+ * wrap pi-durable's own extensions and neither depends on the other, but
44
+ * the order pins the tool-collision story should names ever overlap).
45
+ * Specifiers are the published package names (Task 3) — npm keys a file:
46
+ * dependency by the target's own manifest name, so the key must be the
47
+ * name the packages publish under (the dev shape carries `file:` values
48
+ * under these same keys until Task 8 publishes exact `0.1.0`s).
49
+ */
50
+ export const BUILTIN_EXTENSIONS = [
51
+ { key: "codemode", specifier: "@sigrun/ext-codemode", slug: "codemode" },
52
+ { key: "mcp", specifier: "@sigrun/ext-mcp", slug: "sigrun-mcp" },
53
+ { key: "toolSearch", specifier: "@sigrun/ext-tool-search", slug: "tool-search" },
54
+ ];
55
+ /** The core-anchored require (built-ins resolve from core's own node_modules). */
56
+ const coreRequire = createRequire(import.meta.url);
57
+ /**
58
+ * Resolve one specifier's load entry through core's own node_modules.
59
+ * An unresolvable name yields an entry of the name itself: the loader's
60
+ * `import()` fails on it and quarantines with the not-found message
61
+ * naming the package (Ruling 2 — loud, never a throw). Absolute paths
62
+ * (the test seam's fixture URLs) pass through verbatim.
63
+ */
64
+ function builtinEntry(specifier) {
65
+ if (specifier.startsWith("file://") ||
66
+ specifier.startsWith("/") ||
67
+ specifier.startsWith("./") ||
68
+ specifier.startsWith("../")) {
69
+ return { name: specifier, entry: specifier };
70
+ }
71
+ try {
72
+ const entry = pathToFileURL(coreRequire.resolve(specifier)).href;
73
+ // The package root: the nearest manifest at or above the resolved
74
+ // entry (the `exports` map may not export `./package.json`, so a
75
+ // `resolve(name + "/package.json")` probe is not reliable).
76
+ let dir = dirname(fileURLToPath(entry));
77
+ let packageDir;
78
+ for (let hops = 0; hops < 6; hops++) {
79
+ if (basename(dir) === "node_modules")
80
+ break;
81
+ if (readPackageName(dir) !== undefined) {
82
+ packageDir = dir;
83
+ break;
84
+ }
85
+ const parent = dirname(dir);
86
+ if (parent === dir)
87
+ break;
88
+ dir = parent;
89
+ }
90
+ return {
91
+ name: specifier,
92
+ entry,
93
+ ...(packageDir === undefined ? {} : { packageDir }),
94
+ };
95
+ }
96
+ catch {
97
+ return { name: specifier, entry: specifier };
98
+ }
99
+ }
100
+ /**
101
+ * The package name a configured load entry resolves to, when derivable:
102
+ * path-shaped entries read the nearest manifest (`readPackageName`);
103
+ * bare specifiers parse (`parsePackageSpecifier`). `undefined` when
104
+ * nothing derives (a nameless bare entry) — such an entry can never
105
+ * replace a built-in.
106
+ */
107
+ function configuredPackageName(entry) {
108
+ const base = entry.entry ?? entry.name;
109
+ if (base === undefined)
110
+ return undefined;
111
+ let path;
112
+ if (base.startsWith("file://")) {
113
+ try {
114
+ path = fileURLToPath(base);
115
+ }
116
+ catch {
117
+ path = undefined;
118
+ }
119
+ }
120
+ else if (base.startsWith("file:") ||
121
+ base.startsWith("/") ||
122
+ base.startsWith("./") ||
123
+ base.startsWith("../")) {
124
+ path = resolve(base.startsWith("file:") ? base.slice("file:".length) : base);
125
+ }
126
+ if (path !== undefined && isAbsolute(path)) {
127
+ // A path-shaped entry: the nearest manifest at or above it names
128
+ // the package (npm's own file:-dependency rule). A directory's
129
+ // manifest reads directly; a FILE entry starts at its directory.
130
+ const fileShaped = /\.(m?js|ts|cjs|tgz)$/.test(path);
131
+ let dir = fileShaped && !path.endsWith(".tgz") ? dirname(path) : path;
132
+ for (let hops = 0; hops < 6; hops++) {
133
+ const name = readPackageName(dir);
134
+ if (name !== undefined)
135
+ return name;
136
+ const parent = dirname(dir);
137
+ if (parent === dir)
138
+ return undefined;
139
+ dir = parent;
140
+ }
141
+ return undefined;
142
+ }
143
+ return parsePackageSpecifier(base).name;
144
+ }
145
+ /**
146
+ * Resolve which built-ins load this boot, against the settings file's
147
+ * `builtinExtensions` disables and the configured extension list's
148
+ * replacements. Built-ins load FIRST (boot prepends the returned list);
149
+ * the replacement rule removes a built-in whose package name matches a
150
+ * configured entry's resolved package name.
151
+ *
152
+ * One log line per skipped built-in (disabled or replaced) — never per
153
+ * boot loop.
154
+ */
155
+ export function resolveBuiltins(settings, configured,
156
+ /** Test seam: additional built-in specifiers (fixtures), resolved like the real ones. */
157
+ extra = []) {
158
+ const toggles = settings.builtinExtensions;
159
+ const load = [];
160
+ const skipped = [];
161
+ // The configured package names, computed once (replacement matching):
162
+ // name → the display specifier the warning and `replacedBy` report.
163
+ const configuredNames = new Map();
164
+ for (const entry of configured) {
165
+ const name = configuredPackageName(entry);
166
+ if (name !== undefined && !configuredNames.has(name)) {
167
+ configuredNames.set(name, entry.name ?? entry.entry ?? name);
168
+ }
169
+ }
170
+ for (const builtin of BUILTIN_EXTENSIONS) {
171
+ if (toggles?.[builtin.key] === false) {
172
+ console.info(`builtins: "${builtin.specifier}" disabled via settings builtinExtensions.${builtin.key} — skipping`);
173
+ skipped.push({ key: builtin.key, reason: "disabled" });
174
+ continue;
175
+ }
176
+ const replacement = configuredNames.get(builtin.specifier);
177
+ if (replacement !== undefined) {
178
+ console.warn(`builtins: configured extension "${replacement}" replaces the built-in "${builtin.specifier}" (the built-in is skipped)`);
179
+ skipped.push({ key: builtin.key, reason: "replaced", by: replacement });
180
+ continue;
181
+ }
182
+ load.push(builtinEntry(builtin.specifier));
183
+ }
184
+ // The test-seam extra entries (the boot's `extraBuiltins` option):
185
+ // resolved exactly like the real built-ins, appended after them,
186
+ // reported builtin.
187
+ for (const specifier of extra) {
188
+ load.push(builtinEntry(specifier));
189
+ }
190
+ return { load, skipped };
191
+ }