@cursor/july 0.1.2 → 0.1.4

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 (232) hide show
  1. package/AGENTS.md +16 -5
  2. package/README.md +8 -9
  3. package/dist/bin/agent-serve.d.ts +3 -1
  4. package/dist/bin/agent-serve.d.ts.map +1 -1
  5. package/dist/bin/agent-serve.js +416 -155
  6. package/dist/channels/slack/log.d.ts +1 -1
  7. package/dist/channels/slack/log.d.ts.map +1 -1
  8. package/dist/channels/slack/log.js +4 -5
  9. package/dist/channels/slack/setup.js +1 -1
  10. package/dist/channels/slack/socket-mode.d.ts.map +1 -1
  11. package/dist/channels/slack/socket-mode.js +10 -9
  12. package/dist/docs/404.html +2 -2
  13. package/dist/docs/ab.html +3 -3
  14. package/dist/docs/assets/{app.Oje4vhlk.js → app.DF-Yx4OP.js} +1 -1
  15. package/dist/docs/assets/chunks/@localSearchIndexroot.0XrheBv2.js +1 -0
  16. package/dist/docs/assets/chunks/{VPLocalSearchBox.H5XZ2zCB.js → VPLocalSearchBox.DSeJSudL.js} +1 -1
  17. package/dist/docs/assets/chunks/{theme.CTR_TuaE.js → theme.DZVLTXOC.js} +2 -2
  18. package/dist/docs/assets/{index.md.m81y7TY7.js → index.md.Cylk70gg.js} +1 -1
  19. package/dist/docs/assets/{quickstart.md.CfU8_uTC.js → quickstart.md.BU6Iwi_9.js} +18 -6
  20. package/dist/docs/assets/{reference_cli.md.DA730zCu.js → reference_cli.md.Bv6pOxcF.js} +11 -6
  21. package/dist/docs/assets/{reference_cli.md.DA730zCu.lean.js → reference_cli.md.Bv6pOxcF.lean.js} +1 -1
  22. package/dist/docs/building-with-agents.html +3 -3
  23. package/dist/docs/concepts.html +3 -3
  24. package/dist/docs/deployment.html +3 -3
  25. package/dist/docs/evals.html +3 -3
  26. package/dist/docs/guides/agent-to-agent.html +3 -3
  27. package/dist/docs/guides/cloud-runtime.html +3 -3
  28. package/dist/docs/guides/github.html +3 -3
  29. package/dist/docs/guides/human-in-the-loop.html +3 -3
  30. package/dist/docs/guides/slack.html +3 -3
  31. package/dist/docs/guides/webhooks.html +3 -3
  32. package/dist/docs/hashmap.json +1 -1
  33. package/dist/docs/hillclimbing.html +3 -3
  34. package/dist/docs/index.html +5 -5
  35. package/dist/docs/quickstart.html +22 -10
  36. package/dist/docs/reference/agent-config.html +3 -3
  37. package/dist/docs/reference/channels.html +3 -3
  38. package/dist/docs/reference/cli.html +14 -9
  39. package/dist/docs/reference/connections.html +3 -3
  40. package/dist/docs/reference/hooks.html +3 -3
  41. package/dist/docs/reference/http-api.html +3 -3
  42. package/dist/docs/reference/instructions.html +3 -3
  43. package/dist/docs/reference/playground.html +3 -3
  44. package/dist/docs/reference/project-layout.html +3 -3
  45. package/dist/docs/reference/schedules.html +3 -3
  46. package/dist/docs/reference/sessions.html +3 -3
  47. package/dist/docs/reference/skills.html +3 -3
  48. package/dist/docs/reference/subagents.html +3 -3
  49. package/dist/docs/reference/tools.html +3 -3
  50. package/dist/docs/scaffolding-agents.html +3 -3
  51. package/dist/docs/storage.html +3 -3
  52. package/dist/docs/troubleshooting.html +3 -3
  53. package/dist/internal/ab-collector.js +3 -3
  54. package/dist/internal/ab-fold.js +1 -1
  55. package/dist/internal/chat-client.d.ts +29 -3
  56. package/dist/internal/chat-client.d.ts.map +1 -1
  57. package/dist/internal/chat-client.js +180 -27
  58. package/dist/internal/cli-ax.d.ts +83 -2
  59. package/dist/internal/cli-ax.d.ts.map +1 -1
  60. package/dist/internal/cli-ax.js +626 -52
  61. package/dist/internal/cli-cursor.d.ts.map +1 -1
  62. package/dist/internal/cli-cursor.js +8 -36
  63. package/dist/internal/cli-deploy.d.ts +59 -3
  64. package/dist/internal/cli-deploy.d.ts.map +1 -1
  65. package/dist/internal/cli-deploy.js +316 -38
  66. package/dist/internal/cli-github.js +13 -13
  67. package/dist/internal/cursor/account-mcp.js +3 -3
  68. package/dist/internal/cursor/backend-client.js +1 -1
  69. package/dist/internal/cursor/credentials.d.ts +14 -3
  70. package/dist/internal/cursor/credentials.d.ts.map +1 -1
  71. package/dist/internal/cursor/credentials.js +21 -6
  72. package/dist/internal/cursor/github-credentials.js +3 -3
  73. package/dist/internal/cursor-event-relay.js +1 -1
  74. package/dist/internal/cursor-relay-core.d.ts +1 -1
  75. package/dist/internal/cursor-relay-core.d.ts.map +1 -1
  76. package/dist/internal/cursor-relay-core.js +2 -1
  77. package/dist/internal/cursor-slack-relay.js +1 -1
  78. package/dist/internal/deploy-client.d.ts +9 -1
  79. package/dist/internal/deploy-client.d.ts.map +1 -1
  80. package/dist/internal/deploy-client.js +23 -3
  81. package/dist/internal/deploy-source.d.ts +35 -0
  82. package/dist/internal/deploy-source.d.ts.map +1 -0
  83. package/dist/internal/deploy-source.js +118 -0
  84. package/dist/internal/discovery.d.ts +11 -0
  85. package/dist/internal/discovery.d.ts.map +1 -1
  86. package/dist/internal/discovery.js +43 -14
  87. package/dist/internal/distribution.d.ts +7 -0
  88. package/dist/internal/distribution.d.ts.map +1 -1
  89. package/dist/internal/distribution.js +7 -0
  90. package/dist/internal/docs-site.js +3 -3
  91. package/dist/internal/eval-run-store.d.ts.map +1 -1
  92. package/dist/internal/eval-run-store.js +10 -9
  93. package/dist/internal/eval-runner.d.ts +2 -0
  94. package/dist/internal/eval-runner.d.ts.map +1 -1
  95. package/dist/internal/eval-runner.js +2 -0
  96. package/dist/internal/event-mapper.d.ts +54 -1
  97. package/dist/internal/event-mapper.d.ts.map +1 -1
  98. package/dist/internal/event-mapper.js +151 -41
  99. package/dist/internal/github-fanout.js +2 -2
  100. package/dist/internal/host-platforms.js +5 -5
  101. package/dist/internal/init-project.d.ts +88 -1
  102. package/dist/internal/init-project.d.ts.map +1 -1
  103. package/dist/internal/init-project.js +221 -31
  104. package/dist/internal/install-cursor-skills.d.ts +64 -0
  105. package/dist/internal/install-cursor-skills.d.ts.map +1 -0
  106. package/dist/internal/install-cursor-skills.js +274 -0
  107. package/dist/internal/logs-client.d.ts +60 -0
  108. package/dist/internal/logs-client.d.ts.map +1 -0
  109. package/dist/internal/logs-client.js +311 -0
  110. package/dist/internal/mcp-endpoint.d.ts.map +1 -1
  111. package/dist/internal/mcp-endpoint.js +1 -1
  112. package/dist/internal/open-browser.d.ts +5 -0
  113. package/dist/internal/open-browser.d.ts.map +1 -0
  114. package/dist/internal/open-browser.js +34 -0
  115. package/dist/internal/playground/toolchain.d.ts.map +1 -1
  116. package/dist/internal/playground/toolchain.js +19 -14
  117. package/dist/internal/playground-proxy.d.ts +69 -0
  118. package/dist/internal/playground-proxy.d.ts.map +1 -0
  119. package/dist/internal/playground-proxy.js +468 -0
  120. package/dist/internal/prompt-context.d.ts +35 -0
  121. package/dist/internal/prompt-context.d.ts.map +1 -0
  122. package/dist/internal/prompt-context.js +71 -0
  123. package/dist/internal/reminder-runner.d.ts.map +1 -1
  124. package/dist/internal/reminder-runner.js +11 -11
  125. package/dist/internal/request-headers.d.ts +11 -0
  126. package/dist/internal/request-headers.d.ts.map +1 -0
  127. package/dist/internal/request-headers.js +14 -0
  128. package/dist/internal/resolve-prod-target.d.ts +44 -0
  129. package/dist/internal/resolve-prod-target.d.ts.map +1 -0
  130. package/dist/internal/resolve-prod-target.js +134 -0
  131. package/dist/internal/resolved-connections.js +5 -5
  132. package/dist/internal/run-client.d.ts +2 -2
  133. package/dist/internal/run-client.d.ts.map +1 -1
  134. package/dist/internal/run-client.js +38 -23
  135. package/dist/internal/schedule-runner.js +1 -1
  136. package/dist/internal/server.d.ts.map +1 -1
  137. package/dist/internal/server.js +23 -17
  138. package/dist/internal/session-engine.d.ts +1 -1
  139. package/dist/internal/session-engine.d.ts.map +1 -1
  140. package/dist/internal/session-engine.js +34 -19
  141. package/dist/internal/sessions-client.d.ts +34 -0
  142. package/dist/internal/sessions-client.d.ts.map +1 -0
  143. package/dist/internal/sessions-client.js +193 -0
  144. package/dist/internal/storage-coordinator.js +6 -6
  145. package/dist/internal/stream-progress.d.ts.map +1 -1
  146. package/dist/internal/stream-progress.js +31 -3
  147. package/dist/internal/terminal-style.d.ts +22 -0
  148. package/dist/internal/terminal-style.d.ts.map +1 -0
  149. package/dist/internal/terminal-style.js +49 -0
  150. package/dist/internal/trajectory.d.ts +10 -5
  151. package/dist/internal/trajectory.d.ts.map +1 -1
  152. package/dist/internal/trajectory.js +82 -10
  153. package/dist/internal/update-check.d.ts +93 -0
  154. package/dist/internal/update-check.d.ts.map +1 -0
  155. package/dist/internal/update-check.js +431 -0
  156. package/dist/internal/workspace.d.ts +11 -0
  157. package/dist/internal/workspace.d.ts.map +1 -1
  158. package/dist/internal/workspace.js +38 -4
  159. package/dist/playground/assets/index-Ct_Usdm8.css +1 -0
  160. package/dist/playground/assets/index-Dsyb-Vaj.js +319 -0
  161. package/dist/playground/index.html +2 -2
  162. package/dist/types.d.ts +29 -2
  163. package/dist/types.d.ts.map +1 -1
  164. package/docs/README.md +0 -1
  165. package/docs/quickstart.md +22 -7
  166. package/docs/reference/cli.md +51 -3
  167. package/package.json +4 -1
  168. package/skills/ab/SKILL.md +8 -8
  169. package/skills/create-agent/SKILL.md +28 -22
  170. package/skills/debug/SKILL.md +11 -11
  171. package/skills/evals/SKILL.md +16 -16
  172. package/skills/framework-map/SKILL.md +6 -6
  173. package/skills/github/SKILL.md +13 -13
  174. package/skills/hillclimb/SKILL.md +10 -10
  175. package/skills/setup-slack/SKILL.md +14 -14
  176. package/src/bin/agent-serve.ts +451 -191
  177. package/src/channels/slack/log.ts +5 -5
  178. package/src/channels/slack/setup.ts +1 -1
  179. package/src/channels/slack/socket-mode.ts +11 -9
  180. package/src/internal/ab-collector.ts +3 -3
  181. package/src/internal/ab-fold.ts +1 -1
  182. package/src/internal/chat-client.ts +252 -37
  183. package/src/internal/cli-ax.ts +761 -72
  184. package/src/internal/cli-cursor.ts +14 -42
  185. package/src/internal/cli-deploy.ts +428 -49
  186. package/src/internal/cli-github.ts +13 -15
  187. package/src/internal/cursor/account-mcp.ts +3 -3
  188. package/src/internal/cursor/backend-client.ts +1 -1
  189. package/src/internal/cursor/credentials.ts +26 -7
  190. package/src/internal/cursor/github-credentials.ts +3 -3
  191. package/src/internal/cursor-event-relay.ts +1 -1
  192. package/src/internal/cursor-relay-core.ts +4 -2
  193. package/src/internal/cursor-slack-relay.ts +1 -1
  194. package/src/internal/deploy-client.ts +45 -4
  195. package/src/internal/deploy-source.ts +133 -0
  196. package/src/internal/discovery.ts +53 -16
  197. package/src/internal/distribution.ts +8 -0
  198. package/src/internal/docs-site.ts +3 -3
  199. package/src/internal/eval-run-store.ts +10 -11
  200. package/src/internal/eval-runner.ts +5 -0
  201. package/src/internal/event-mapper.ts +222 -42
  202. package/src/internal/github-fanout.ts +2 -2
  203. package/src/internal/host-platforms.ts +5 -5
  204. package/src/internal/init-project.ts +333 -51
  205. package/src/internal/install-cursor-skills.ts +327 -0
  206. package/src/internal/logs-client.ts +442 -0
  207. package/src/internal/mcp-endpoint.ts +1 -3
  208. package/src/internal/open-browser.ts +41 -0
  209. package/src/internal/playground/toolchain.ts +18 -16
  210. package/src/internal/playground-proxy.ts +576 -0
  211. package/src/internal/prompt-context.ts +95 -0
  212. package/src/internal/reminder-runner.ts +11 -17
  213. package/src/internal/request-headers.ts +23 -0
  214. package/src/internal/resolve-prod-target.ts +182 -0
  215. package/src/internal/resolved-connections.ts +5 -5
  216. package/src/internal/run-client.ts +39 -36
  217. package/src/internal/schedule-runner.ts +1 -1
  218. package/src/internal/server.ts +25 -16
  219. package/src/internal/session-engine.ts +35 -18
  220. package/src/internal/sessions-client.ts +216 -0
  221. package/src/internal/storage-coordinator.ts +6 -6
  222. package/src/internal/stream-progress.ts +36 -2
  223. package/src/internal/terminal-style.ts +74 -0
  224. package/src/internal/trajectory.ts +91 -13
  225. package/src/internal/update-check.ts +552 -0
  226. package/src/internal/workspace.ts +42 -4
  227. package/src/types.ts +45 -7
  228. package/dist/docs/assets/chunks/@localSearchIndexroot.zwQ9RCQ7.js +0 -1
  229. package/dist/playground/assets/index-B1Qc9h2u.css +0 -1
  230. package/dist/playground/assets/index-CpDYCj8W.js +0 -79
  231. /package/dist/docs/assets/{index.md.m81y7TY7.lean.js → index.md.Cylk70gg.lean.js} +0 -0
  232. /package/dist/docs/assets/{quickstart.md.CfU8_uTC.lean.js → quickstart.md.BU6Iwi_9.lean.js} +0 -0
@@ -0,0 +1,431 @@
1
+ /**
2
+ * Outdated-version warning + `agentkit update`.
3
+ *
4
+ * Every CLI run of a published install compares its own version against the
5
+ * npm registry's `latest` dist-tag and warns on stderr when behind. The
6
+ * registry lookup is cached under the config dir
7
+ * (`~/.config/agent-serve/update-check.json`) so most runs never touch the
8
+ * network; a stale cache refreshes inline under a short timeout, and any
9
+ * network failure is silent (the warning is best-effort, never a blocker).
10
+ *
11
+ * `agentkit update` re-runs the lookup fresh, figures out how this copy was
12
+ * installed (global npm/pnpm/yarn/bun, or a project dependency), and runs the
13
+ * matching install command.
14
+ */
15
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
19
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
22
+ });
23
+ };
24
+ import { spawn } from "node:child_process";
25
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
26
+ import { dirname, join, sep } from "node:path";
27
+ import { z } from "zod";
28
+ import { configDirPath } from "./cursor/credentials.js";
29
+ import { describeError } from "./describe-error.js";
30
+ import { CLI_COMMAND_NAME, isCompiledDistribution, PACKAGE_NAME, packageRootDir, packageVersion, } from "./distribution.js";
31
+ import { stderrPalette } from "./terminal-style.js";
32
+ const NPM_REGISTRY_URL = "https://registry.npmjs.org";
33
+ /** Refresh the registry lookup at most this often. */
34
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
35
+ /** Inline refresh budget; a slow registry must not stall the command. */
36
+ const WARN_FETCH_TIMEOUT_MS = 1500;
37
+ /** `agentkit update` runs interactively, so it can afford a real timeout. */
38
+ const UPDATE_FETCH_TIMEOUT_MS = 10000;
39
+ function parseVersion(version) {
40
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(version.trim());
41
+ if (match === null) {
42
+ return undefined;
43
+ }
44
+ return {
45
+ release: [Number(match[1]), Number(match[2]), Number(match[3])],
46
+ prerelease: match[4] === undefined ? [] : match[4].split("."),
47
+ };
48
+ }
49
+ /**
50
+ * Semver-style ordering: negative when `a < b`, 0 when equal, positive when
51
+ * `a > b`. Unparseable versions compare equal (never warn on garbage).
52
+ */
53
+ export function compareVersions(a, b) {
54
+ const pa = parseVersion(a);
55
+ const pb = parseVersion(b);
56
+ if (pa === undefined || pb === undefined) {
57
+ return 0;
58
+ }
59
+ for (let i = 0; i < 3; i++) {
60
+ const diff = pa.release[i] - pb.release[i];
61
+ if (diff !== 0) {
62
+ return diff;
63
+ }
64
+ }
65
+ // A release outranks any prerelease of the same triple.
66
+ if (pa.prerelease.length === 0 || pb.prerelease.length === 0) {
67
+ return pb.prerelease.length - pa.prerelease.length;
68
+ }
69
+ const len = Math.max(pa.prerelease.length, pb.prerelease.length);
70
+ for (let i = 0; i < len; i++) {
71
+ const ia = pa.prerelease[i];
72
+ const ib = pb.prerelease[i];
73
+ // A longer prerelease list outranks its prefix (1.0.0-a.1 > 1.0.0-a).
74
+ if (ia === undefined) {
75
+ return -1;
76
+ }
77
+ if (ib === undefined) {
78
+ return 1;
79
+ }
80
+ const na = /^\d+$/.test(ia) ? Number(ia) : undefined;
81
+ const nb = /^\d+$/.test(ib) ? Number(ib) : undefined;
82
+ if (na !== undefined && nb !== undefined) {
83
+ if (na !== nb) {
84
+ return na - nb;
85
+ }
86
+ }
87
+ else if (na !== undefined) {
88
+ return -1; // numeric identifiers sort before alphanumeric ones
89
+ }
90
+ else if (nb !== undefined) {
91
+ return 1;
92
+ }
93
+ else if (ia !== ib) {
94
+ return ia < ib ? -1 : 1;
95
+ }
96
+ }
97
+ return 0;
98
+ }
99
+ // ============================================================================
100
+ // Registry lookup
101
+ // ============================================================================
102
+ const distTagResponseSchema = z.object({ version: z.string() });
103
+ /**
104
+ * Latest published version of the package, from the registry's `latest`
105
+ * dist-tag. Returns undefined on any failure (offline, 404 pre-publish, …).
106
+ */
107
+ export function fetchLatestPublishedVersion(options) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ var _a, _b, _c;
110
+ const fetchImpl = (_a = options === null || options === void 0 ? void 0 : options.fetchImpl) !== null && _a !== void 0 ? _a : fetch;
111
+ const packageName = (_b = options === null || options === void 0 ? void 0 : options.packageName) !== null && _b !== void 0 ? _b : PACKAGE_NAME;
112
+ // Scoped names keep the `@` but encode the `/` for the registry path.
113
+ const url = `${NPM_REGISTRY_URL}/${packageName.replace("/", "%2F")}/latest`;
114
+ try {
115
+ const response = yield fetchImpl(url, {
116
+ headers: { accept: "application/json" },
117
+ signal: AbortSignal.timeout((_c = options === null || options === void 0 ? void 0 : options.timeoutMs) !== null && _c !== void 0 ? _c : WARN_FETCH_TIMEOUT_MS),
118
+ });
119
+ if (!response.ok) {
120
+ return undefined;
121
+ }
122
+ const body = distTagResponseSchema.safeParse(yield response.json());
123
+ if (!body.success || parseVersion(body.data.version) === undefined) {
124
+ return undefined;
125
+ }
126
+ return body.data.version;
127
+ }
128
+ catch (_d) {
129
+ return undefined;
130
+ }
131
+ });
132
+ }
133
+ // ============================================================================
134
+ // Cache (one JSON file next to credentials.json)
135
+ // ============================================================================
136
+ const cacheSchema = z.object({
137
+ /** Epoch ms of the last registry lookup attempt (success or not). */
138
+ checkedAt: z.number(),
139
+ /** Last version the registry reported; absent when lookups keep failing. */
140
+ latestVersion: z.string().optional(),
141
+ });
142
+ export function updateCheckCachePath(configDir) {
143
+ return join(configDir !== null && configDir !== void 0 ? configDir : configDirPath(), "update-check.json");
144
+ }
145
+ export function readUpdateCheckCache(configDir) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ let raw;
148
+ try {
149
+ raw = yield readFile(updateCheckCachePath(configDir), "utf8");
150
+ }
151
+ catch (_a) {
152
+ return undefined;
153
+ }
154
+ try {
155
+ const parsed = cacheSchema.safeParse(JSON.parse(raw));
156
+ return parsed.success ? parsed.data : undefined;
157
+ }
158
+ catch (_b) {
159
+ return undefined;
160
+ }
161
+ });
162
+ }
163
+ export function writeUpdateCheckCache(cache, configDir) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const path = updateCheckCachePath(configDir);
166
+ try {
167
+ yield mkdir(dirname(path), { recursive: true, mode: 0o700 });
168
+ yield writeFile(path, `${JSON.stringify(cache, null, 2)}\n`);
169
+ }
170
+ catch (_a) {
171
+ // Best-effort; a read-only config dir just means re-checking next run.
172
+ }
173
+ });
174
+ }
175
+ /**
176
+ * Print an outdated-version warning to stderr when a newer release exists.
177
+ *
178
+ * Never throws and never blocks longer than {@link WARN_FETCH_TIMEOUT_MS}.
179
+ * Suppressed on source-checkout runs (there is no installed copy to update),
180
+ * in CI, and via NO_UPDATE_NOTIFIER / AGENT_SERVE_NO_UPDATE_CHECK.
181
+ */
182
+ export function warnIfOutdated(options) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ var _a, _b, _c, _d;
185
+ const env = (_a = options === null || options === void 0 ? void 0 : options.env) !== null && _a !== void 0 ? _a : process.env;
186
+ if (isTruthyEnv(env.AGENT_SERVE_NO_UPDATE_CHECK) ||
187
+ isTruthyEnv(env.NO_UPDATE_NOTIFIER) ||
188
+ isTruthyEnv(env.CI)) {
189
+ return;
190
+ }
191
+ if ((options === null || options === void 0 ? void 0 : options.force) !== true && !isCompiledDistribution()) {
192
+ return;
193
+ }
194
+ const now = (_b = options === null || options === void 0 ? void 0 : options.now) !== null && _b !== void 0 ? _b : Date.now();
195
+ const currentVersion = (_c = options === null || options === void 0 ? void 0 : options.currentVersion) !== null && _c !== void 0 ? _c : packageVersion();
196
+ const cached = yield readUpdateCheckCache(options === null || options === void 0 ? void 0 : options.configDir);
197
+ let latestVersion = cached === null || cached === void 0 ? void 0 : cached.latestVersion;
198
+ const fresh = cached !== undefined && now - cached.checkedAt < CHECK_INTERVAL_MS;
199
+ if (!fresh) {
200
+ const fetched = yield fetchLatestPublishedVersion({
201
+ fetchImpl: options === null || options === void 0 ? void 0 : options.fetchImpl,
202
+ timeoutMs: WARN_FETCH_TIMEOUT_MS,
203
+ });
204
+ latestVersion = fetched !== null && fetched !== void 0 ? fetched : latestVersion;
205
+ // checkedAt always advances so a flaky registry backs off to one
206
+ // attempt per interval instead of one per command.
207
+ yield writeUpdateCheckCache({ checkedAt: now, latestVersion }, options === null || options === void 0 ? void 0 : options.configDir);
208
+ }
209
+ if (latestVersion === undefined ||
210
+ compareVersions(currentVersion, latestVersion) >= 0) {
211
+ return;
212
+ }
213
+ const c = stderrPalette();
214
+ const err = (_d = options === null || options === void 0 ? void 0 : options.err) !== null && _d !== void 0 ? _d : ((text) => void process.stderr.write(text));
215
+ err(`${c.yellow("warning:")} ${CLI_COMMAND_NAME} ${currentVersion} is outdated (latest is ${latestVersion}). Run \`${CLI_COMMAND_NAME} update\` to upgrade.\n`);
216
+ });
217
+ }
218
+ function isTruthyEnv(value) {
219
+ return value !== undefined && value !== "" && value !== "0";
220
+ }
221
+ /**
222
+ * Figure out how the running copy was installed and which command upgrades
223
+ * it. Detection is path-shape based (global stores have recognizable
224
+ * layouts), then falls back to walking up to the project that declares the
225
+ * dependency. Returns undefined for layouts we cannot safely upgrade
226
+ * (npx cache, unrecognized stores).
227
+ */
228
+ export function detectUpdateCommand(args) {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ var _a;
231
+ const packageName = (_a = args.packageName) !== null && _a !== void 0 ? _a : PACKAGE_NAME;
232
+ const spec = `${packageName}@latest`;
233
+ const posixRoot = args.packageRoot.split(sep).join("/");
234
+ // npx / pnpm dlx caches are ephemeral; a fresh `npx agentkit` already
235
+ // resolves latest, and upgrading the cache entry in place helps nobody.
236
+ if (posixRoot.includes("/_npx/") || posixRoot.includes("/.pnpm-store/")) {
237
+ return undefined;
238
+ }
239
+ if (posixRoot.includes("/pnpm/global/")) {
240
+ return {
241
+ cmd: "pnpm",
242
+ args: ["add", "-g", spec],
243
+ reason: "installed with pnpm --global",
244
+ };
245
+ }
246
+ if (posixRoot.includes("/.bun/install/global/")) {
247
+ return {
248
+ cmd: "bun",
249
+ args: ["add", "-g", spec],
250
+ reason: "installed with bun --global",
251
+ };
252
+ }
253
+ if (posixRoot.includes("/yarn/global/") ||
254
+ posixRoot.includes("/.config/yarn/global/")) {
255
+ return {
256
+ cmd: "yarn",
257
+ args: ["global", "add", spec],
258
+ reason: "installed with yarn global",
259
+ };
260
+ }
261
+ // A project that depends on the package: upgrade the dependency there,
262
+ // with whichever package manager the lockfile says the project uses.
263
+ const projectDir = yield findDependingProjectDir(args.packageRoot, packageName);
264
+ if (projectDir !== undefined) {
265
+ const pm = yield detectProjectPackageManager(projectDir);
266
+ const command = pm === "pnpm"
267
+ ? { cmd: "pnpm", args: ["add", spec] }
268
+ : pm === "yarn"
269
+ ? { cmd: "yarn", args: ["add", spec] }
270
+ : pm === "bun"
271
+ ? { cmd: "bun", args: ["add", spec] }
272
+ : { cmd: "npm", args: ["install", spec] };
273
+ return Object.assign(Object.assign({}, command), { cwd: projectDir, reason: `project dependency in ${projectDir}` });
274
+ }
275
+ // Global npm layout: <prefix>/lib/node_modules/<name> (or <prefix>\
276
+ // node_modules\<name> on Windows), with no depending project above it.
277
+ if (posixRoot.includes("/node_modules/")) {
278
+ return {
279
+ cmd: "npm",
280
+ args: ["install", "-g", spec],
281
+ reason: "installed with npm --global",
282
+ };
283
+ }
284
+ return undefined;
285
+ });
286
+ }
287
+ /**
288
+ * Nearest ancestor with a package.json that declares `packageName` as a
289
+ * dependency. Skips directories inside node_modules (pnpm's virtual store
290
+ * nests package.json files that are not the user's project).
291
+ */
292
+ function findDependingProjectDir(packageRoot, packageName) {
293
+ return __awaiter(this, void 0, void 0, function* () {
294
+ let dir = dirname(packageRoot);
295
+ for (let depth = 0; depth < 30; depth++) {
296
+ const parent = dirname(dir);
297
+ if (parent === dir) {
298
+ return undefined;
299
+ }
300
+ const inNodeModules = dir
301
+ .split(sep)
302
+ .some((part) => part === "node_modules" || part === ".pnpm");
303
+ if (!inNodeModules && (yield declaresDependency(dir, packageName))) {
304
+ return dir;
305
+ }
306
+ dir = parent;
307
+ }
308
+ return undefined;
309
+ });
310
+ }
311
+ function declaresDependency(dir, packageName) {
312
+ return __awaiter(this, void 0, void 0, function* () {
313
+ var _a, _b;
314
+ let raw;
315
+ try {
316
+ raw = yield readFile(join(dir, "package.json"), "utf8");
317
+ }
318
+ catch (_c) {
319
+ return false;
320
+ }
321
+ const manifestSchema = z.object({
322
+ dependencies: z.record(z.string()).optional(),
323
+ devDependencies: z.record(z.string()).optional(),
324
+ });
325
+ try {
326
+ const parsed = manifestSchema.safeParse(JSON.parse(raw));
327
+ if (!parsed.success) {
328
+ return false;
329
+ }
330
+ return (((_a = parsed.data.dependencies) === null || _a === void 0 ? void 0 : _a[packageName]) !== undefined ||
331
+ ((_b = parsed.data.devDependencies) === null || _b === void 0 ? void 0 : _b[packageName]) !== undefined);
332
+ }
333
+ catch (_d) {
334
+ return false;
335
+ }
336
+ });
337
+ }
338
+ function detectProjectPackageManager(projectDir) {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ const exists = (file) => __awaiter(this, void 0, void 0, function* () {
341
+ try {
342
+ yield stat(join(projectDir, file));
343
+ return true;
344
+ }
345
+ catch (_a) {
346
+ return false;
347
+ }
348
+ });
349
+ if (yield exists("pnpm-lock.yaml")) {
350
+ return "pnpm";
351
+ }
352
+ if (yield exists("yarn.lock")) {
353
+ return "yarn";
354
+ }
355
+ if ((yield exists("bun.lock")) || (yield exists("bun.lockb"))) {
356
+ return "bun";
357
+ }
358
+ return "npm";
359
+ });
360
+ }
361
+ /** `agentkit update` — upgrade this install to the latest published version. */
362
+ export function cmdUpdate(options) {
363
+ return __awaiter(this, void 0, void 0, function* () {
364
+ var _a, _b, _c, _d, _e, _f;
365
+ const c = stderrPalette();
366
+ const out = (_a = options === null || options === void 0 ? void 0 : options.out) !== null && _a !== void 0 ? _a : ((text) => void process.stdout.write(text));
367
+ const err = (_b = options === null || options === void 0 ? void 0 : options.err) !== null && _b !== void 0 ? _b : ((text) => void process.stderr.write(text));
368
+ const compiled = (_c = options === null || options === void 0 ? void 0 : options.compiled) !== null && _c !== void 0 ? _c : isCompiledDistribution();
369
+ if (!compiled) {
370
+ err(`${CLI_COMMAND_NAME} is running from a source checkout, not an installed package; update it with git instead.\n`);
371
+ return 1;
372
+ }
373
+ const currentVersion = (_d = options === null || options === void 0 ? void 0 : options.currentVersion) !== null && _d !== void 0 ? _d : packageVersion();
374
+ const latestVersion = yield fetchLatestPublishedVersion({
375
+ fetchImpl: options === null || options === void 0 ? void 0 : options.fetchImpl,
376
+ timeoutMs: UPDATE_FETCH_TIMEOUT_MS,
377
+ });
378
+ if (latestVersion === undefined) {
379
+ err(`Could not reach the npm registry to look up the latest ${PACKAGE_NAME} version. Check your network and retry.\n`);
380
+ return 1;
381
+ }
382
+ if (compareVersions(currentVersion, latestVersion) >= 0) {
383
+ out(`${CLI_COMMAND_NAME} ${currentVersion} is already the latest version.\n`);
384
+ yield writeUpdateCheckCache({ checkedAt: Date.now(), latestVersion }, options === null || options === void 0 ? void 0 : options.configDir);
385
+ return 0;
386
+ }
387
+ const command = yield detectUpdateCommand({
388
+ packageRoot: (_e = options === null || options === void 0 ? void 0 : options.packageRoot) !== null && _e !== void 0 ? _e : packageRootDir(),
389
+ });
390
+ if (command === undefined) {
391
+ err(`${CLI_COMMAND_NAME} ${currentVersion} is outdated (latest is ${latestVersion}), but this install's layout was not recognized.\nUpgrade it yourself, e.g. \`npm install -g ${PACKAGE_NAME}@latest\` for a global install, or bump the ${PACKAGE_NAME} dependency in your project.\n`);
392
+ return 1;
393
+ }
394
+ const rendered = [command.cmd, ...command.args].join(" ");
395
+ err(c.dim(`Updating ${CLI_COMMAND_NAME} ${currentVersion} → ${latestVersion} (${command.reason}):\n ${rendered}\n`));
396
+ const run = (_f = options === null || options === void 0 ? void 0 : options.runCommand) !== null && _f !== void 0 ? _f : runUpdateCommand;
397
+ let code;
398
+ try {
399
+ code = yield run(command);
400
+ }
401
+ catch (error) {
402
+ err(`\`${rendered}\` failed: ${describeError(error)}\n`);
403
+ return 1;
404
+ }
405
+ if (code !== 0) {
406
+ err(`\`${rendered}\` exited with code ${code}.\n`);
407
+ return code;
408
+ }
409
+ yield writeUpdateCheckCache({ checkedAt: Date.now(), latestVersion }, options === null || options === void 0 ? void 0 : options.configDir);
410
+ out(`Updated ${CLI_COMMAND_NAME} to ${latestVersion}. New commands run the new version.\n`);
411
+ return 0;
412
+ });
413
+ }
414
+ function runUpdateCommand(command) {
415
+ return new Promise((resolve, reject) => {
416
+ // Windows-only shell: npm/pnpm/yarn/bun are .cmd shims there, and Node
417
+ // refuses to spawn .cmd files without a shell (EINVAL, CVE-2024-27980
418
+ // hardening). Injection-safe: cmd and args are module-level constants
419
+ // from detectUpdateCommand (never user or registry input).
420
+ // nosemgrep: javascript.lang.security.audit.spawn-shell-true.spawn-shell-true
421
+ const child = spawn(command.cmd, command.args, {
422
+ stdio: "inherit",
423
+ cwd: command.cwd,
424
+ shell: process.platform === "win32",
425
+ });
426
+ child.on("error", reject);
427
+ child.on("close", (code) => {
428
+ resolve(code !== null && code !== void 0 ? code : 1);
429
+ });
430
+ });
431
+ }
@@ -18,6 +18,17 @@ export interface MaterializeWorkspaceOptions {
18
18
  }
19
19
  /** Relative path of an agent-side tool script inside the session workspace. */
20
20
  export declare function agentToolScriptPath(toolName: string): string;
21
+ /**
22
+ * Always-on identity line prepended when composing instructions. Sourced from
23
+ * {@link ResolvedAgent.name} (`defineAgent({ name })`, else package/dir name)
24
+ * so agents know who they are without restating it in authored prose.
25
+ */
26
+ export declare function buildIdentityPreamble(name: string): string;
27
+ /**
28
+ * Prepend {@link buildIdentityPreamble} to authored instructions. Used when
29
+ * loading `instructions.md` / `.ts` / dir into {@link ResolvedAgent.instructions}.
30
+ */
31
+ export declare function withIdentityPreamble(name: string, instructions: string | undefined): string | undefined;
21
32
  /**
22
33
  * Markdown catalog of agent-side tools for AGENTS.md / cloud first prompt.
23
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/internal/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACd,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,aAAa,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,GAAE;IAAE,cAAc,EAAE,OAAO,CAAA;CAA8B,GAC/D,MAAM,CA6CR;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,IAAI,CAAC,CAmCf;AAmDD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAO3D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CAMf"}
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/internal/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,aAAa,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,GAAG,SAAS,CAapB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,GAAE;IAAE,cAAc,EAAE,OAAO,CAAA;CAA8B,GAC/D,MAAM,CA6CR;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,IAAI,CAAC,CAqCf;AAmDD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAO3D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -18,10 +18,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
18
  import { chmod, copyFile, mkdir, stat, writeFile } from "node:fs/promises";
19
19
  import { dirname, join, relative, resolve } from "node:path";
20
20
  import { parseFrontmatter, serializeFrontmatter } from "./frontmatter.js";
21
+ import { buildIdentitySection } from "./prompt-context.js";
21
22
  /** Relative path of an agent-side tool script inside the session workspace. */
22
23
  export function agentToolScriptPath(toolName) {
23
24
  return `.agent-serve/tools/${toolName}.sh`;
24
25
  }
26
+ /**
27
+ * Always-on identity line prepended when composing instructions. Sourced from
28
+ * {@link ResolvedAgent.name} (`defineAgent({ name })`, else package/dir name)
29
+ * so agents know who they are without restating it in authored prose.
30
+ */
31
+ export function buildIdentityPreamble(name) {
32
+ const trimmed = name.trim();
33
+ if (trimmed === "") {
34
+ return "";
35
+ }
36
+ return `You are ${trimmed}. That is your name; use it when people ask who you are.`;
37
+ }
38
+ /**
39
+ * Prepend {@link buildIdentityPreamble} to authored instructions. Used when
40
+ * loading `instructions.md` / `.ts` / dir into {@link ResolvedAgent.instructions}.
41
+ */
42
+ export function withIdentityPreamble(name, instructions) {
43
+ var _a;
44
+ const preamble = buildIdentityPreamble(name);
45
+ const body = (_a = instructions === null || instructions === void 0 ? void 0 : instructions.trim()) !== null && _a !== void 0 ? _a : "";
46
+ if (preamble === "" && body === "") {
47
+ return undefined;
48
+ }
49
+ if (preamble === "") {
50
+ return body === "" ? undefined : body;
51
+ }
52
+ if (body === "") {
53
+ return preamble;
54
+ }
55
+ return `${preamble}\n\n${body}`;
56
+ }
25
57
  /**
26
58
  * Markdown catalog of agent-side tools for AGENTS.md / cloud first prompt.
27
59
  *
@@ -80,12 +112,14 @@ export function materializeWorkspace(options) {
80
112
  const agentToolsSection = buildAgentToolsCatalog(agent.tools, {
81
113
  includeScripts: false,
82
114
  });
83
- const agentsMd = [(_b = (_a = agent.instructions) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "", agentToolsSection]
115
+ const agentsMd = [
116
+ (_b = (_a = agent.instructions) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "",
117
+ buildIdentitySection(agent),
118
+ agentToolsSection,
119
+ ]
84
120
  .filter((part) => part !== "")
85
121
  .join("\n\n");
86
- if (agentsMd !== "") {
87
- yield writeFile(join(workspaceDir, "AGENTS.md"), agentsMd, "utf8");
88
- }
122
+ yield writeFile(join(workspaceDir, "AGENTS.md"), agentsMd, "utf8");
89
123
  for (const tool of agent.tools) {
90
124
  if (tool.execution !== "agent" || tool.script === undefined) {
91
125
  continue;