@maiaos/agent 0.1.0-canary.10

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 (187) hide show
  1. package/README.md +54 -0
  2. package/dist/auth/index.d.ts +3 -0
  3. package/dist/auth/index.d.ts.map +1 -0
  4. package/dist/auth/index.js +3 -0
  5. package/dist/auth/index.js.map +1 -0
  6. package/dist/auth/maia-auth.d.ts +23 -0
  7. package/dist/auth/maia-auth.d.ts.map +1 -0
  8. package/dist/auth/maia-auth.js +97 -0
  9. package/dist/auth/maia-auth.js.map +1 -0
  10. package/dist/auth/memory-credentials.d.ts +9 -0
  11. package/dist/auth/memory-credentials.d.ts.map +1 -0
  12. package/dist/auth/memory-credentials.js +23 -0
  13. package/dist/auth/memory-credentials.js.map +1 -0
  14. package/dist/extensions/goal/command.d.ts +28 -0
  15. package/dist/extensions/goal/command.d.ts.map +1 -0
  16. package/dist/extensions/goal/command.js +80 -0
  17. package/dist/extensions/goal/command.js.map +1 -0
  18. package/dist/extensions/goal/context.d.ts +24 -0
  19. package/dist/extensions/goal/context.d.ts.map +1 -0
  20. package/dist/extensions/goal/context.js +35 -0
  21. package/dist/extensions/goal/context.js.map +1 -0
  22. package/dist/extensions/goal/extension.d.ts +7 -0
  23. package/dist/extensions/goal/extension.d.ts.map +1 -0
  24. package/dist/extensions/goal/extension.js +179 -0
  25. package/dist/extensions/goal/extension.js.map +1 -0
  26. package/dist/extensions/goal/index.d.ts +2 -0
  27. package/dist/extensions/goal/index.d.ts.map +1 -0
  28. package/dist/extensions/goal/index.js +2 -0
  29. package/dist/extensions/goal/index.js.map +1 -0
  30. package/dist/extensions/goal/section.d.ts +22 -0
  31. package/dist/extensions/goal/section.d.ts.map +1 -0
  32. package/dist/extensions/goal/section.js +49 -0
  33. package/dist/extensions/goal/section.js.map +1 -0
  34. package/dist/extensions/process/extension.d.ts +3 -0
  35. package/dist/extensions/process/extension.d.ts.map +1 -0
  36. package/dist/extensions/process/extension.js +79 -0
  37. package/dist/extensions/process/extension.js.map +1 -0
  38. package/dist/extensions/process/index.d.ts +2 -0
  39. package/dist/extensions/process/index.d.ts.map +1 -0
  40. package/dist/extensions/process/index.js +2 -0
  41. package/dist/extensions/process/index.js.map +1 -0
  42. package/dist/extensions/process/manager.d.ts +30 -0
  43. package/dist/extensions/process/manager.d.ts.map +1 -0
  44. package/dist/extensions/process/manager.js +156 -0
  45. package/dist/extensions/process/manager.js.map +1 -0
  46. package/dist/extensions/prompt-section/index.d.ts +2 -0
  47. package/dist/extensions/prompt-section/index.d.ts.map +1 -0
  48. package/dist/extensions/prompt-section/index.js +2 -0
  49. package/dist/extensions/prompt-section/index.js.map +1 -0
  50. package/dist/extensions/prompt-section/prompt-section.d.ts +26 -0
  51. package/dist/extensions/prompt-section/prompt-section.d.ts.map +1 -0
  52. package/dist/extensions/prompt-section/prompt-section.js +28 -0
  53. package/dist/extensions/prompt-section/prompt-section.js.map +1 -0
  54. package/dist/extensions/safety/command-wrappers.d.ts +31 -0
  55. package/dist/extensions/safety/command-wrappers.d.ts.map +1 -0
  56. package/dist/extensions/safety/command-wrappers.js +247 -0
  57. package/dist/extensions/safety/command-wrappers.js.map +1 -0
  58. package/dist/extensions/safety/destructive-guard.d.ts +24 -0
  59. package/dist/extensions/safety/destructive-guard.d.ts.map +1 -0
  60. package/dist/extensions/safety/destructive-guard.js +178 -0
  61. package/dist/extensions/safety/destructive-guard.js.map +1 -0
  62. package/dist/extensions/safety/index.d.ts +3 -0
  63. package/dist/extensions/safety/index.d.ts.map +1 -0
  64. package/dist/extensions/safety/index.js +3 -0
  65. package/dist/extensions/safety/index.js.map +1 -0
  66. package/dist/extensions/safety/lifecycle.d.ts +3 -0
  67. package/dist/extensions/safety/lifecycle.d.ts.map +1 -0
  68. package/dist/extensions/safety/lifecycle.js +92 -0
  69. package/dist/extensions/safety/lifecycle.js.map +1 -0
  70. package/dist/extensions/safety/shell-tokens.d.ts +13 -0
  71. package/dist/extensions/safety/shell-tokens.d.ts.map +1 -0
  72. package/dist/extensions/safety/shell-tokens.js +115 -0
  73. package/dist/extensions/safety/shell-tokens.js.map +1 -0
  74. package/dist/extensions/search/bounds.d.ts +22 -0
  75. package/dist/extensions/search/bounds.d.ts.map +1 -0
  76. package/dist/extensions/search/bounds.js +35 -0
  77. package/dist/extensions/search/bounds.js.map +1 -0
  78. package/dist/extensions/search/extension.d.ts +7 -0
  79. package/dist/extensions/search/extension.d.ts.map +1 -0
  80. package/dist/extensions/search/extension.js +18 -0
  81. package/dist/extensions/search/extension.js.map +1 -0
  82. package/dist/extensions/search/index.d.ts +2 -0
  83. package/dist/extensions/search/index.d.ts.map +1 -0
  84. package/dist/extensions/search/index.js +2 -0
  85. package/dist/extensions/search/index.js.map +1 -0
  86. package/dist/extensions/tasks/context.d.ts +20 -0
  87. package/dist/extensions/tasks/context.d.ts.map +1 -0
  88. package/dist/extensions/tasks/context.js +36 -0
  89. package/dist/extensions/tasks/context.js.map +1 -0
  90. package/dist/extensions/tasks/extension.d.ts +7 -0
  91. package/dist/extensions/tasks/extension.d.ts.map +1 -0
  92. package/dist/extensions/tasks/extension.js +178 -0
  93. package/dist/extensions/tasks/extension.js.map +1 -0
  94. package/dist/extensions/tasks/index.d.ts +2 -0
  95. package/dist/extensions/tasks/index.d.ts.map +1 -0
  96. package/dist/extensions/tasks/index.js +2 -0
  97. package/dist/extensions/tasks/index.js.map +1 -0
  98. package/dist/extensions/tasks/summary.d.ts +20 -0
  99. package/dist/extensions/tasks/summary.d.ts.map +1 -0
  100. package/dist/extensions/tasks/summary.js +50 -0
  101. package/dist/extensions/tasks/summary.js.map +1 -0
  102. package/dist/extensions/title/extension.d.ts +4 -0
  103. package/dist/extensions/title/extension.d.ts.map +1 -0
  104. package/dist/extensions/title/extension.js +37 -0
  105. package/dist/extensions/title/extension.js.map +1 -0
  106. package/dist/extensions/title/index.d.ts +2 -0
  107. package/dist/extensions/title/index.d.ts.map +1 -0
  108. package/dist/extensions/title/index.js +2 -0
  109. package/dist/extensions/title/index.js.map +1 -0
  110. package/dist/extensions/title/title.d.ts +9 -0
  111. package/dist/extensions/title/title.d.ts.map +1 -0
  112. package/dist/extensions/title/title.js +92 -0
  113. package/dist/extensions/title/title.js.map +1 -0
  114. package/dist/home/index.d.ts +2 -0
  115. package/dist/home/index.d.ts.map +1 -0
  116. package/dist/home/index.js +2 -0
  117. package/dist/home/index.js.map +1 -0
  118. package/dist/home/maia-home.d.ts +17 -0
  119. package/dist/home/maia-home.d.ts.map +1 -0
  120. package/dist/home/maia-home.js +84 -0
  121. package/dist/home/maia-home.js.map +1 -0
  122. package/dist/index.d.ts +9 -0
  123. package/dist/index.d.ts.map +1 -0
  124. package/dist/index.js +9 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/login/index.d.ts +2 -0
  127. package/dist/login/index.d.ts.map +1 -0
  128. package/dist/login/index.js +2 -0
  129. package/dist/login/index.js.map +1 -0
  130. package/dist/login/provider-login.d.ts +43 -0
  131. package/dist/login/provider-login.d.ts.map +1 -0
  132. package/dist/login/provider-login.js +153 -0
  133. package/dist/login/provider-login.js.map +1 -0
  134. package/dist/managed-worker/index.d.ts +2 -0
  135. package/dist/managed-worker/index.d.ts.map +1 -0
  136. package/dist/managed-worker/index.js +2 -0
  137. package/dist/managed-worker/index.js.map +1 -0
  138. package/dist/managed-worker/main.d.ts +3 -0
  139. package/dist/managed-worker/main.d.ts.map +1 -0
  140. package/dist/managed-worker/main.js +319362 -0
  141. package/dist/managed-worker/main.js.map +1 -0
  142. package/dist/managed-worker/main.meta.json +1 -0
  143. package/dist/managed-worker/operation-channel.d.ts +24 -0
  144. package/dist/managed-worker/operation-channel.d.ts.map +1 -0
  145. package/dist/managed-worker/operation-channel.js +145 -0
  146. package/dist/managed-worker/operation-channel.js.map +1 -0
  147. package/dist/managed-worker/protocol.d.ts +76 -0
  148. package/dist/managed-worker/protocol.d.ts.map +1 -0
  149. package/dist/managed-worker/protocol.js +318 -0
  150. package/dist/managed-worker/protocol.js.map +1 -0
  151. package/dist/managed-worker/worker.d.ts +38 -0
  152. package/dist/managed-worker/worker.d.ts.map +1 -0
  153. package/dist/managed-worker/worker.js +437 -0
  154. package/dist/managed-worker/worker.js.map +1 -0
  155. package/dist/resources/index.d.ts +2 -0
  156. package/dist/resources/index.d.ts.map +1 -0
  157. package/dist/resources/index.js +2 -0
  158. package/dist/resources/index.js.map +1 -0
  159. package/dist/resources/resources.d.ts +21 -0
  160. package/dist/resources/resources.d.ts.map +1 -0
  161. package/dist/resources/resources.js +198 -0
  162. package/dist/resources/resources.js.map +1 -0
  163. package/dist/runner/index.d.ts +2 -0
  164. package/dist/runner/index.d.ts.map +1 -0
  165. package/dist/runner/index.js +2 -0
  166. package/dist/runner/index.js.map +1 -0
  167. package/dist/runner/runner.d.ts +31 -0
  168. package/dist/runner/runner.d.ts.map +1 -0
  169. package/dist/runner/runner.js +346 -0
  170. package/dist/runner/runner.js.map +1 -0
  171. package/dist/runtime/index.d.ts +3 -0
  172. package/dist/runtime/index.d.ts.map +1 -0
  173. package/dist/runtime/index.js +3 -0
  174. package/dist/runtime/index.js.map +1 -0
  175. package/dist/runtime/kernel.d.ts +18 -0
  176. package/dist/runtime/kernel.d.ts.map +1 -0
  177. package/dist/runtime/kernel.js +23 -0
  178. package/dist/runtime/kernel.js.map +1 -0
  179. package/dist/runtime/runtime.d.ts +31 -0
  180. package/dist/runtime/runtime.d.ts.map +1 -0
  181. package/dist/runtime/runtime.js +124 -0
  182. package/dist/runtime/runtime.js.map +1 -0
  183. package/dist/runtime/startup-network-policy.d.ts +9 -0
  184. package/dist/runtime/startup-network-policy.d.ts.map +1 -0
  185. package/dist/runtime/startup-network-policy.js +25 -0
  186. package/dist/runtime/startup-network-policy.js.map +1 -0
  187. package/package.json +79 -0
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @maiaos/agent
2
+
3
+ Maia's own AI coding agent, `maia agent`, and the managed worker that Maia Node
4
+ runs, both built on the official
5
+ [`@earendil-works/pi-coding-agent`](https://www.npmjs.com/package/@earendil-works/pi-coding-agent)
6
+ SDK.
7
+
8
+ > **Pre-release.** npm carries only `nightly` and `canary` builds, which are
9
+ > not release-qualified. No stable release exists
10
+ > ([D-132](https://github.com/vllnt/maia/blob/main/docs/decisions.md#d-132)).
11
+
12
+ ## Requirements
13
+
14
+ Node.js 24.22.1.
15
+
16
+ ## Install
17
+
18
+ `maia agent` ships with the `maia` CLI:
19
+
20
+ ```sh
21
+ pnpm add -g @maiaos/cli@nightly
22
+ ```
23
+
24
+ To embed the library in your own process, use
25
+ `pnpm add @maiaos/agent@nightly`.
26
+
27
+ ## Usage
28
+
29
+ ```sh
30
+ maia agent # interactive; type /login to sign in
31
+ maia agent --print --no-session -- "Explain this repository"
32
+ maia agent --json-events --no-session -- "Review the current diff"
33
+ ```
34
+
35
+ Pi supplies the agent loop, models, providers, TUI, sessions and extensions.
36
+ Maia adds Maia-owned paths and credentials, digest-pinned project extensions
37
+ and Skills, a few reviewed built-ins, and the boundary to Maia Node. It never
38
+ runs an installed `pi` executable or reads `~/.pi`.
39
+
40
+ Every entry sets `PI_OFFLINE=1` and `PI_SKIP_VERSION_CHECK=1`. Project
41
+ extension code runs with your operating-system permissions, so review it
42
+ before you pin its digest.
43
+
44
+ ## Status
45
+
46
+ **Source candidate.** `maia agent` and its built-ins work from source. Running
47
+ Maia Agent as a general Node worker for swarms is planned.
48
+
49
+ ## Links
50
+
51
+ - [Agent architecture](https://github.com/vllnt/maia/blob/main/docs/maia-agent/architecture.md)
52
+ - [CLI reference](https://github.com/vllnt/maia/blob/main/docs/reference/cli.md)
53
+ - [Security policy](https://github.com/vllnt/maia/blob/main/SECURITY.md)
54
+ - [Repository](https://github.com/vllnt/maia)
@@ -0,0 +1,3 @@
1
+ export { assertMaiaApiKey, isMaiaOAuthCredential, type MaiaAuthFile, type MaiaOAuthCredential, type MaiaProviderCredential, MAX_MAIA_API_KEY_BYTES, MAX_MAIA_AUTH_PROVIDERS, parseMaiaAuthFile, } from "./maia-auth.js";
2
+ export { createMemoryCredentials, type MaiaAgentProviderCredential, } from "./memory-credentials.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { assertMaiaApiKey, isMaiaOAuthCredential, MAX_MAIA_API_KEY_BYTES, MAX_MAIA_AUTH_PROVIDERS, parseMaiaAuthFile, } from "./maia-auth.js";
2
+ export { createMemoryCredentials, } from "./memory-credentials.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EAIrB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,GAExB,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,23 @@
1
+ export declare const MAX_MAIA_API_KEY_BYTES: number;
2
+ /** Pi's catalog lists about 40 providers; Maia keeps one credential per provider. */
3
+ export declare const MAX_MAIA_AUTH_PROVIDERS = 64;
4
+ export type MaiaOAuthCredential = {
5
+ readonly access: string;
6
+ readonly accountId?: string;
7
+ readonly expires: number;
8
+ readonly refresh: string;
9
+ readonly type: "oauth";
10
+ };
11
+ /** Pi stores a key, provider environment values (such as a region), both, or neither for ambient credentials. */
12
+ type MaiaApiKeyCredential = {
13
+ readonly env?: Readonly<Record<string, string>>;
14
+ readonly key?: string;
15
+ readonly type: "api_key";
16
+ };
17
+ export type MaiaProviderCredential = MaiaApiKeyCredential | MaiaOAuthCredential;
18
+ export type MaiaAuthFile = Readonly<Record<string, MaiaProviderCredential>>;
19
+ export declare const assertMaiaApiKey: (key: string) => string;
20
+ export declare const parseMaiaAuthFile: (text: string) => MaiaAuthFile;
21
+ export declare const isMaiaOAuthCredential: (value: MaiaProviderCredential) => value is MaiaOAuthCredential;
22
+ export {};
23
+ //# sourceMappingURL=maia-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maia-auth.d.ts","sourceRoot":"","sources":["../../src/auth/maia-auth.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,QAAW,CAAC;AAC/C,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAO1C,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,iHAAiH;AACjH,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAEhF,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAa5E,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,MAW9C,CAAC;AA4EF,eAAO,MAAM,iBAAiB,SAAU,MAAM,KAAG,YA2BhD,CAAC;AAEF,eAAO,MAAM,qBAAqB,UACzB,sBAAsB,KAC5B,KAAK,IAAI,mBAA6C,CAAC"}
@@ -0,0 +1,97 @@
1
+ export const MAX_MAIA_API_KEY_BYTES = 8 * 1024;
2
+ /** Pi's catalog lists about 40 providers; Maia keeps one credential per provider. */
3
+ export const MAX_MAIA_AUTH_PROVIDERS = 64;
4
+ const MAX_MAIA_OAUTH_TOKEN_BYTES = 32 * 1024;
5
+ const MAX_MAIA_PROVIDER_ENV_ENTRIES = 16;
6
+ const identifierPattern = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u;
7
+ const environmentNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/u;
8
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9
+ const isBoundedString = (value, maximum) => typeof value === "string" &&
10
+ value.length > 0 &&
11
+ Buffer.byteLength(value, "utf8") <= maximum;
12
+ const isIdentifier = (value) => isBoundedString(value, 128) && identifierPattern.test(value);
13
+ export const assertMaiaApiKey = (key) => {
14
+ const trimmed = key.trim();
15
+ if (trimmed.length === 0 ||
16
+ trimmed.includes("\0") ||
17
+ trimmed.includes("\n") ||
18
+ Buffer.byteLength(trimmed, "utf8") > MAX_MAIA_API_KEY_BYTES) {
19
+ throw new TypeError("The API key is empty or exceeds its bound.");
20
+ }
21
+ return trimmed;
22
+ };
23
+ /** A token that may be empty: OpenRouter's subscription stores no refresh token. */
24
+ const isOptionalToken = (value) => typeof value === "string" &&
25
+ Buffer.byteLength(value, "utf8") <= MAX_MAIA_OAUTH_TOKEN_BYTES;
26
+ const parseOAuthCredential = (value) => {
27
+ if (value.type !== "oauth" ||
28
+ !isBoundedString(value.access, MAX_MAIA_OAUTH_TOKEN_BYTES) ||
29
+ !isOptionalToken(value.refresh) ||
30
+ typeof value.expires !== "number" ||
31
+ !Number.isSafeInteger(value.expires) ||
32
+ value.expires < 0 ||
33
+ (value.accountId !== undefined && !isBoundedString(value.accountId, 512))) {
34
+ throw new TypeError("Maia auth.json contains an invalid OAuth credential.");
35
+ }
36
+ return {
37
+ access: value.access,
38
+ ...(value.accountId === undefined ? {} : { accountId: value.accountId }),
39
+ expires: value.expires,
40
+ refresh: value.refresh,
41
+ type: "oauth",
42
+ };
43
+ };
44
+ const providerSetting = ([name, setting]) => environmentNamePattern.test(name) &&
45
+ isBoundedString(setting, MAX_MAIA_API_KEY_BYTES)
46
+ ? [[name, setting]]
47
+ : [];
48
+ const parseProviderEnvironment = (value) => {
49
+ const entries = isRecord(value) ? Object.entries(value) : [];
50
+ const settings = entries.flatMap(providerSetting);
51
+ if (!isRecord(value) ||
52
+ entries.length > MAX_MAIA_PROVIDER_ENV_ENTRIES ||
53
+ settings.length !== entries.length) {
54
+ throw new TypeError("Maia auth.json contains invalid provider settings.");
55
+ }
56
+ return Object.fromEntries(settings);
57
+ };
58
+ const parseApiKeyCredential = (value) => {
59
+ if (value.type !== "api_key" ||
60
+ (value.key !== undefined && typeof value.key !== "string")) {
61
+ throw new TypeError("Maia auth.json contains an invalid API key credential.");
62
+ }
63
+ return {
64
+ ...(value.env === undefined
65
+ ? {}
66
+ : { env: parseProviderEnvironment(value.env) }),
67
+ ...(typeof value.key === "string"
68
+ ? { key: assertMaiaApiKey(value.key) }
69
+ : {}),
70
+ type: "api_key",
71
+ };
72
+ };
73
+ export const parseMaiaAuthFile = (text) => {
74
+ const parsed = JSON.parse(text);
75
+ if (!isRecord(parsed)) {
76
+ throw new TypeError("Maia auth.json must contain an object.");
77
+ }
78
+ const providerIds = Object.keys(parsed);
79
+ if (providerIds.length > MAX_MAIA_AUTH_PROVIDERS) {
80
+ throw new TypeError("Maia auth.json exceeds the provider bound.");
81
+ }
82
+ return providerIds.reduce((auth, providerId) => {
83
+ const credential = parsed[providerId];
84
+ if (!isIdentifier(providerId) || !isRecord(credential)) {
85
+ throw new TypeError("Maia auth.json contains an invalid provider.");
86
+ }
87
+ if (credential.type === "oauth") {
88
+ return { ...auth, [providerId]: parseOAuthCredential(credential) };
89
+ }
90
+ if (credential.type === "api_key") {
91
+ return { ...auth, [providerId]: parseApiKeyCredential(credential) };
92
+ }
93
+ throw new TypeError("Maia auth.json contains an unknown credential type.");
94
+ }, {});
95
+ };
96
+ export const isMaiaOAuthCredential = (value) => value.type === "oauth";
97
+ //# sourceMappingURL=maia-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maia-auth.js","sourceRoot":"","sources":["../../src/auth/maia-auth.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,IAAI,CAAC;AAC/C,qFAAqF;AACrF,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAEzC,MAAM,iBAAiB,GAAG,gCAAgC,CAAC;AAC3D,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAqB3D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,MAAM,eAAe,GAAG,CAAC,KAAc,EAAE,OAAe,EAAmB,EAAE,CAC3E,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,CAAC,MAAM,GAAG,CAAC;IAChB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC;AAE9C,MAAM,YAAY,GAAG,CAAC,KAAc,EAAmB,EAAE,CACvD,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAU,EAAE;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UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;QACtE,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,qDAAqD,CACtD,CAAC;IACJ,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAA6B,EACC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Credential, CredentialStore } from "@earendil-works/pi-ai";
2
+ export type MaiaAgentProviderCredential = {
3
+ readonly auth: Extract<Credential, {
4
+ readonly type: "oauth";
5
+ }>;
6
+ readonly providerId: string;
7
+ };
8
+ export declare const createMemoryCredentials: (credential?: MaiaAgentProviderCredential) => CredentialStore;
9
+ //# sourceMappingURL=memory-credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-credentials.d.ts","sourceRoot":"","sources":["../../src/auth/memory-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEzE,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC/D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,gBACrB,2BAA2B,KACvC,eA2BF,CAAC"}
@@ -0,0 +1,23 @@
1
+ export const createMemoryCredentials = (credential) => {
2
+ const data = new Map(credential === undefined ? [] : [[credential.providerId, credential.auth]]);
3
+ return {
4
+ delete: (providerId) => {
5
+ data.delete(providerId);
6
+ return Promise.resolve();
7
+ },
8
+ list: () => Promise.resolve([...data.entries()].map(([providerId, value]) => ({
9
+ providerId,
10
+ type: value.type,
11
+ }))),
12
+ modify: (providerId, fn) => fn(data.get(providerId)).then((next) => {
13
+ if (next === undefined) {
14
+ data.delete(providerId);
15
+ return next;
16
+ }
17
+ data.set(providerId, next);
18
+ return next;
19
+ }),
20
+ read: (providerId) => Promise.resolve(data.get(providerId)),
21
+ };
22
+ };
23
+ //# sourceMappingURL=memory-credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-credentials.js","sourceRoot":"","sources":["../../src/auth/memory-credentials.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,UAAwC,EACvB,EAAE;IACnB,MAAM,IAAI,GAAG,IAAI,GAAG,CAClB,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAC3E,CAAC;IACF,OAAO;QACL,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE;YACrB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CACT,OAAO,CAAC,OAAO,CACb,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAChD,UAAU;YACV,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC,CAAC,CACJ;QACH,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CACzB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACrC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACxB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;QACJ,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;KAC5D,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** A `/goal` request: a read or a mutation the goal tool also accepts. */
2
+ export type GoalCommand = {
3
+ readonly action: "abandon" | "done" | "pause" | "resume";
4
+ } | {
5
+ readonly action: "rewrite";
6
+ readonly objective: string;
7
+ } | {
8
+ readonly action: "show" | "status";
9
+ };
10
+ /** A rejected `/goal` line and the reason shown to the user. */
11
+ export type GoalCommandRejection = {
12
+ readonly rejected: string;
13
+ };
14
+ /**
15
+ * Parses `/goal` arguments. Nothing means `status`; text that starts with no
16
+ * known verb becomes the new goal.
17
+ */
18
+ export declare const parseGoalCommand: (argumentsText: string) => GoalCommand | GoalCommandRejection;
19
+ /** Verb completions for `/goal`. */
20
+ export declare const goalCompletions: (prefix: string) => {
21
+ label: "abandon" | "done" | "pause" | "resume" | "rewrite" | "show" | "status";
22
+ value: "abandon" | "done" | "pause" | "resume" | "rewrite" | "show" | "status";
23
+ }[];
24
+ /** The one-line summary for `/goal status` and every change. */
25
+ export declare const formatGoalStatus: (value: unknown) => string;
26
+ /** Every goal field, for `/goal show`. */
27
+ export declare const formatGoalDetails: (value: unknown) => string;
28
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/extensions/goal/command.ts"],"names":[],"mappings":"AAuBA,0EAA0E;AAC1E,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC;AAE3C,gEAAgE;AAChE,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAoCjE;;;GAGG;AACH,eAAO,MAAM,gBAAgB,kBACZ,MAAM,KACpB,WAAW,GAAG,oBAUhB,CAAC;AAEF,oCAAoC;AACpC,eAAO,MAAM,eAAe,WAAY,MAAM;;;GAK7C,CAAC;AAOF,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,UAAW,OAAO,KAAG,MAOjD,CAAC;AAKF,0CAA0C;AAC1C,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,MASlD,CAAC"}
@@ -0,0 +1,80 @@
1
+ const MAXIMUM_OBJECTIVE_LENGTH = 2048;
2
+ const ACTIONS = [
3
+ "abandon",
4
+ "done",
5
+ "pause",
6
+ "resume",
7
+ "rewrite",
8
+ "show",
9
+ "status",
10
+ ];
11
+ const VERB = /^(abandon|clear|done|pause|raw|resume|rewrite|show|status)(?:\s+([\s\S]+))?$/iu;
12
+ const rewrite = (prose) => prose.length > MAXIMUM_OBJECTIVE_LENGTH
13
+ ? {
14
+ rejected: `The goal objective is limited to ${String(MAXIMUM_OBJECTIVE_LENGTH)} characters.`,
15
+ }
16
+ : { action: "rewrite", objective: prose };
17
+ const TRANSITIONS = ["abandon", "done", "pause", "resume"];
18
+ const TRANSITION_NAMES = new Set(TRANSITIONS);
19
+ const isTransition = (action) => TRANSITION_NAMES.has(action);
20
+ const verb = (action, rest) => {
21
+ if (action === "rewrite") {
22
+ return rest === undefined
23
+ ? { rejected: "Usage: /goal rewrite <objective>" }
24
+ : rewrite(rest);
25
+ }
26
+ if (action === "show" || action === "status" || isTransition(action)) {
27
+ return rest === undefined
28
+ ? { action }
29
+ : { rejected: `/goal ${action} takes no arguments.` };
30
+ }
31
+ return {
32
+ rejected: `/goal ${action} is not supported: use /goal rewrite <objective>, /goal done or /goal abandon.`,
33
+ };
34
+ };
35
+ /**
36
+ * Parses `/goal` arguments. Nothing means `status`; text that starts with no
37
+ * known verb becomes the new goal.
38
+ */
39
+ export const parseGoalCommand = (argumentsText) => {
40
+ const trimmed = argumentsText.trim();
41
+ if (trimmed.length === 0)
42
+ return { action: "status" };
43
+ const match = VERB.exec(trimmed);
44
+ if (match === null)
45
+ return rewrite(trimmed);
46
+ const rest = match[2]?.trim();
47
+ return verb((match[1] ?? "").toLowerCase(), rest === undefined || rest.length === 0 ? undefined : rest);
48
+ };
49
+ /** Verb completions for `/goal`. */
50
+ export const goalCompletions = (prefix) => {
51
+ const normalized = prefix.trim().toLowerCase();
52
+ return ACTIONS.filter((action) => action.startsWith(normalized)).map((value) => ({ label: value, value }));
53
+ };
54
+ const isGoal = (value) => typeof value === "object" &&
55
+ value !== null &&
56
+ typeof Reflect.get(value, "objective") === "string";
57
+ /** The one-line summary for `/goal status` and every change. */
58
+ export const formatGoalStatus = (value) => {
59
+ if (!isGoal(value))
60
+ return "No session goal. Set one with /goal <objective>.";
61
+ return [
62
+ `Goal [${value.status}] revision ${String(value.revision)}: ${value.objective}`,
63
+ `Next: ${value.next}`,
64
+ `Verification: ${value.verification}`,
65
+ ].join("\n");
66
+ };
67
+ const bulletList = (items) => items.length === 0 ? [" (none)"] : items.map((item) => ` - ${item}`);
68
+ /** Every goal field, for `/goal show`. */
69
+ export const formatGoalDetails = (value) => {
70
+ if (!isGoal(value))
71
+ return formatGoalStatus(value);
72
+ return [
73
+ formatGoalStatus(value),
74
+ "Success:",
75
+ ...bulletList(value.success),
76
+ "Constraints:",
77
+ ...bulletList(value.constraints),
78
+ ].join("\n");
79
+ };
80
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
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Q;IACzB,KAAK,KAAK,IAAI;IACd,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,QAAQ,CAAC;AAEtD,gEAAgE;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAU,EAAE;IACzD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,OAAO,kDAAkD,CAAC;IAC9E,OAAO;QACL,SAAS,KAAK,CAAC,MAAM,cAAc,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,SAAS,EAAE;QAC/E,SAAS,KAAK,CAAC,IAAI,EAAE;QACrB,iBAAiB,KAAK,CAAC,YAAY,EAAE;KACtC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,KAAwB,EAAqB,EAAE,CACjE,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;AAEzE,0CAA0C;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAU,EAAE;IAC1D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACnD,OAAO;QACL,gBAAgB,CAAC,KAAK,CAAC;QACvB,UAAU;QACV,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC;QAC5B,cAAc;QACd,GAAG,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC;KACjC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { Effect } from "effect";
3
+ import { type GoalCommand } from "./command.js";
4
+ import { type GoalSnapshot } from "./section.js";
5
+ declare const GoalStoreError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
6
+ readonly _tag: "GoalStoreError";
7
+ } & Readonly<A>;
8
+ /** A goal state that is missing, unreadable, unsafe or refuses the change. */
9
+ export declare class GoalStoreError extends GoalStoreError_base<{
10
+ readonly message: string;
11
+ }> {
12
+ }
13
+ /** The goal ledger of one Session, as the goal tool reads and changes it. */
14
+ export type GoalStore = {
15
+ readonly read: (sessionId: string) => Effect.Effect<GoalSnapshot | undefined, GoalStoreError>;
16
+ readonly run: (sessionId: string, command: GoalCommand) => Effect.Effect<unknown, GoalStoreError>;
17
+ };
18
+ /**
19
+ * Registers the `/goal` command for people, never the model, and the bounded active-goal
20
+ * section added to the system prompt before each run.
21
+ */
22
+ export declare const registerGoalContext: (pi: ExtensionAPI, store: GoalStore) => void;
23
+ export {};
24
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/extensions/goal/context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,YAAY,EAGb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;;;;AAEtB,8EAA8E;AAC9E,qBAAa,cAAe,SAAQ,oBAAmC;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;CAAG;AAEL,6EAA6E;AAC7E,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,CACb,SAAS,EAAE,MAAM,KACd,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,SAAS,EAAE,cAAc,CAAC,CAAC;IAC7D,QAAQ,CAAC,GAAG,EAAE,CACZ,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,KACjB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;CAC7C,CAAC;AAuCF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,OAAQ,YAAY,SAAS,SAAS,SAWrE,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { Data, Effect } from "effect";
2
+ import { formatGoalDetails, formatGoalStatus, goalCompletions, parseGoalCommand, } from "./command.js";
3
+ import { buildGoalSection, GOAL_SECTION, } from "./section.js";
4
+ /** A goal state that is missing, unreadable, unsafe or refuses the change. */
5
+ export class GoalStoreError extends Data.TaggedError("GoalStoreError") {
6
+ }
7
+ const notify = (context, text, level) => Effect.sync(() => {
8
+ context.ui.notify(text, level);
9
+ });
10
+ const runCommand = (store, argumentsText, context) => {
11
+ const parsed = parseGoalCommand(argumentsText);
12
+ if ("rejected" in parsed)
13
+ return notify(context, parsed.rejected, "warning");
14
+ const format = parsed.action === "show" ? formatGoalDetails : formatGoalStatus;
15
+ return store.run(context.sessionManager.getSessionId(), parsed).pipe(Effect.flatMap((goal) => notify(context, format(goal), "info")), Effect.catchTag("GoalStoreError", (error) => notify(context, error.message, "error")));
16
+ };
17
+ const projectGoal = (store, event, context) => store.read(context.sessionManager.getSessionId()).pipe(Effect.map((goal) => {
18
+ const section = buildGoalSection(goal);
19
+ if (section === undefined)
20
+ return;
21
+ event.systemPromptOptions.sections[GOAL_SECTION] = section.text;
22
+ }));
23
+ /**
24
+ * Registers the `/goal` command for people, never the model, and the bounded active-goal
25
+ * section added to the system prompt before each run.
26
+ */
27
+ export const registerGoalContext = (pi, store) => {
28
+ pi.registerCommand("goal", {
29
+ description: "Show, rewrite, pause, resume or close this session's goal (/goal <objective> rewrites it)",
30
+ getArgumentCompletions: goalCompletions,
31
+ handler: (argumentsText, context) => Effect.runPromise(runCommand(store, argumentsText, context)),
32
+ });
33
+ pi.on("before_agent_start", (event, context) => Effect.runPromise(projectGoal(store, event, context)));
34
+ };
35
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/extensions/goal/context.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAEhB,eAAe,EACf,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,YAAY,GAEb,MAAM,cAAc,CAAC;AAEtB,8EAA8E;AAC9E,MAAM,OAAO,cAAe,SAAQ,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAEnE;CAAG;AAeL,MAAM,MAAM,GAAG,CAAC,OAAgC,EAAE,IAAY,EAAE,KAAY,EAAE,EAAE,CAC9E,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;IACf,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AAEL,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,aAAqB,EACrB,OAAgC,EACX,EAAE;IACvB,MAAM,MAAM,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC/C,IAAI,UAAU,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC7E,MAAM,MAAM,GACV,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAClE,OAAO,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,CAClE,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,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API } from "@earendil-works/pi-coding-agent";
2
+ /** `standalone` adds the human `/goal` command and the goal prompt section. */
3
+ export type GoalExtensionOptions = {
4
+ readonly standalone?: boolean;
5
+ };
6
+ export declare const makeGoalExtension: (stateRoot: string, durableSessionId?: string, options?: GoalExtensionOptions) => (pi: ExtensionAPI) => void;
7
+ //# sourceMappingURL=extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../src/extensions/goal/extension.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,iCAAiC,CAAC;AA6OzC,+EAA+E;AAC/E,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAErE,eAAO,MAAM,iBAAiB,cAEf,MAAM,qBACE,MAAM,YACf,oBAAoB,UAE3B,YAAY,KAAG,IAkBnB,CAAC"}
@@ -0,0 +1,179 @@
1
+ import { lstat, mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+ import { Type } from "@earendil-works/pi-ai";
4
+ import { Effect } from "effect";
5
+ import { GoalStoreError, registerGoalContext, } from "./context.js";
6
+ const MAX_GOAL_BYTES = 16 * 1024;
7
+ const parameters = Type.Object({
8
+ action: Type.Union([
9
+ Type.Literal("rewrite"),
10
+ Type.Literal("update"),
11
+ Type.Literal("status"),
12
+ Type.Literal("show"),
13
+ Type.Literal("verify"),
14
+ Type.Literal("pause"),
15
+ Type.Literal("resume"),
16
+ Type.Literal("done"),
17
+ Type.Literal("abandon"),
18
+ ]),
19
+ constraints: Type.Optional(Type.Array(Type.String({ maxLength: 512 }), { maxItems: 16 })),
20
+ evidence: Type.Optional(Type.String({ maxLength: 4096 })),
21
+ next: Type.Optional(Type.String({ maxLength: 1024 })),
22
+ objective: Type.Optional(Type.String({ maxLength: 2048 })),
23
+ success: Type.Optional(Type.Array(Type.String({ maxLength: 512 }), { maxItems: 16 })),
24
+ });
25
+ const isGoalState = (value) => typeof value === "object" &&
26
+ value !== null &&
27
+ typeof Reflect.get(value, "objective") === "string" &&
28
+ typeof Reflect.get(value, "next") === "string" &&
29
+ typeof Reflect.get(value, "revision") === "number" &&
30
+ Array.isArray(Reflect.get(value, "constraints")) &&
31
+ Array.isArray(Reflect.get(value, "success"));
32
+ const goalPath = (stateRoot, sessionId) => join(stateRoot, "sessions", sessionId, "goal.json");
33
+ const readDurableGoal = async (path) => {
34
+ try {
35
+ const stats = await lstat(path);
36
+ if (!stats.isFile() ||
37
+ stats.isSymbolicLink() ||
38
+ stats.size > MAX_GOAL_BYTES) {
39
+ throw new Error("The session goal state is unsafe or too large.");
40
+ }
41
+ const value = JSON.parse(await readFile(path, "utf8"));
42
+ if (!isGoalState(value))
43
+ throw new Error("The session goal state is invalid.");
44
+ return value;
45
+ }
46
+ catch (error) {
47
+ if (error.code === "ENOENT")
48
+ return undefined;
49
+ throw error;
50
+ }
51
+ };
52
+ const writeDurableGoal = async (path, goal) => {
53
+ await mkdir(dirname(path), { mode: 0o700, recursive: true });
54
+ const text = `${JSON.stringify(goal, undefined, 2)}\n`;
55
+ if (Buffer.byteLength(text, "utf8") > MAX_GOAL_BYTES) {
56
+ throw new Error("The session goal state exceeds its byte limit.");
57
+ }
58
+ const temporary = `${path}.${String(process.pid)}.${String(goal.revision)}.tmp`;
59
+ await writeFile(temporary, text, { flag: "wx", mode: 0o600 });
60
+ await rename(temporary, path);
61
+ };
62
+ const textResult = (value) => ({
63
+ content: [{ text: JSON.stringify(value), type: "text" }],
64
+ details: value,
65
+ });
66
+ const requireActiveGoal = (goal) => {
67
+ if (goal === undefined)
68
+ throw new Error("No session goal exists.");
69
+ if (goal.status === "completed" || goal.status === "abandoned") {
70
+ throw new Error("The session goal is terminal.");
71
+ }
72
+ return goal;
73
+ };
74
+ const rewriteGoal = (input) => {
75
+ if (input.objective === undefined || input.objective.trim().length === 0) {
76
+ throw new Error("Goal rewrite requires an objective.");
77
+ }
78
+ return {
79
+ constraints: input.constraints ?? [],
80
+ next: input.next?.trim() || "Choose the next smallest verifiable action.",
81
+ objective: input.objective.trim(),
82
+ revision: 1,
83
+ status: "active",
84
+ success: input.success ?? [],
85
+ updatedAt: Date.now(),
86
+ verification: "not_run",
87
+ };
88
+ };
89
+ const updateGoal = (goal, input) => ({
90
+ ...goal,
91
+ ...(input.constraints === undefined
92
+ ? {}
93
+ : { constraints: input.constraints }),
94
+ ...(input.next === undefined ? {} : { next: input.next }),
95
+ ...(input.objective === undefined ? {} : { objective: input.objective }),
96
+ revision: goal.revision + 1,
97
+ ...(input.success === undefined ? {} : { success: input.success }),
98
+ updatedAt: Date.now(),
99
+ verification: "not_run",
100
+ });
101
+ const statusGoal = (goal, status) => ({
102
+ ...goal,
103
+ revision: goal.revision + 1,
104
+ status,
105
+ updatedAt: Date.now(),
106
+ });
107
+ const actionStatus = {
108
+ abandon: "abandoned",
109
+ done: "completed",
110
+ pause: "paused",
111
+ resume: "active",
112
+ };
113
+ const verifiedGoal = (goal, evidence) => ({
114
+ ...goal,
115
+ ...(evidence === undefined ? {} : { evidence }),
116
+ revision: goal.revision + 1,
117
+ updatedAt: Date.now(),
118
+ verification: "unknown",
119
+ });
120
+ const mutateGoal = (current, input) => {
121
+ if (input.action === "rewrite")
122
+ return rewriteGoal(input);
123
+ const active = requireActiveGoal(current);
124
+ if (input.action === "update")
125
+ return updateGoal(active, input);
126
+ if (input.action === "verify")
127
+ return verifiedGoal(active, input.evidence);
128
+ if (input.action === "status" || input.action === "show") {
129
+ throw new Error("Goal status is read-only.");
130
+ }
131
+ return statusGoal(active, actionStatus[input.action]);
132
+ };
133
+ const runGoalAction = async (path, input) => {
134
+ const current = await readDurableGoal(path);
135
+ if (input.action === "status" || input.action === "show") {
136
+ return textResult(current ?? { status: "none" });
137
+ }
138
+ const next = mutateGoal(current, input);
139
+ await writeDurableGoal(path, next);
140
+ return textResult(next);
141
+ };
142
+ const createExecuteGoal = (stateRoot, durableSessionId) => (...arguments_) => runGoalAction(goalPath(stateRoot, durableSessionId ?? arguments_[4].sessionManager.getSessionId()), arguments_[1]);
143
+ const storeError = (cause) => new GoalStoreError({
144
+ message: cause instanceof Error ? cause.message : String(cause),
145
+ });
146
+ // The goal ledger lifted into Effect for the standalone /goal command and
147
+ // the goal prompt section.
148
+ const goalStore = (stateRoot, durableSessionId) => {
149
+ const path = (sessionId) => goalPath(stateRoot, durableSessionId ?? sessionId);
150
+ return {
151
+ read: (sessionId) => Effect.tryPromise({
152
+ catch: storeError,
153
+ try: () => readDurableGoal(path(sessionId)),
154
+ }),
155
+ run: (sessionId, command) => Effect.tryPromise({
156
+ catch: storeError,
157
+ try: () => runGoalAction(path(sessionId), command),
158
+ }).pipe(Effect.map((result) => result.details)),
159
+ };
160
+ };
161
+ export const makeGoalExtension = (stateRoot, durableSessionId, options) => (pi) => {
162
+ if (options?.standalone === true) {
163
+ registerGoalContext(pi, goalStore(stateRoot, durableSessionId));
164
+ }
165
+ pi.registerTool({
166
+ description: "Own one durable objective for this agent session; update status and record bounded verification evidence.",
167
+ execute: createExecuteGoal(stateRoot, durableSessionId),
168
+ executionMode: "sequential",
169
+ label: "Goal",
170
+ name: "goal",
171
+ parameters,
172
+ promptGuidelines: [
173
+ "Keep the session objective in goal and work progress in task.",
174
+ "goal verify records evidence as unknown until independently checked; it never grants authority.",
175
+ ],
176
+ promptSnippet: "Own one durable objective for this agent session",
177
+ });
178
+ };
179
+ //# sourceMappingURL=extension.js.map