@notis_ai/cli 0.2.32 → 0.2.33

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 (81) hide show
  1. package/README.md +74 -9
  2. package/dist/agent-hooks/notis-agent-hook.mjs +4330 -891
  3. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  4. package/dist/base-skills/notis-cli/SKILL.md +7 -3
  5. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  6. package/dist/base-skills/notis-spaces/SKILL.md +5 -3
  7. package/dist/base-skills/notis-spaces/references/comments.md +94 -0
  8. package/dist/base-skills/notis-spaces/references/context.md +20 -19
  9. package/dist/base-skills/notis-spaces/references/design.md +3 -2
  10. package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
  11. package/dist/base-skills/notis-spaces/references/store.md +24 -1
  12. package/dist/sdk/src/components/SelectionActionBar.tsx +42 -7
  13. package/dist/sdk/src/components/SpaceTextComments.tsx +284 -0
  14. package/dist/sdk/src/config.ts +3 -1
  15. package/dist/sdk/src/functions.ts +203 -0
  16. package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
  17. package/dist/sdk/src/hooks/useCollectionInteractions.ts +7 -2
  18. package/dist/sdk/src/hooks/useConnection.ts +102 -0
  19. package/dist/sdk/src/hooks/useFunction.ts +42 -0
  20. package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
  21. package/dist/sdk/src/index.ts +15 -4
  22. package/dist/sdk/src/runtime.ts +16 -1
  23. package/dist/sdk/src/space.ts +333 -33
  24. package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
  25. package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
  26. package/dist/skill-sync/index.js +239 -30
  27. package/dist/skill-sync-worker.mjs +453 -124
  28. package/dist/space-harness/host.js +213 -92
  29. package/dist/space-sdk/dist/chunk-4GWS2IFO.js +3 -0
  30. package/dist/space-sdk/dist/index.js +3 -3
  31. package/dist/space-sdk/dist/ui.js +8 -7
  32. package/dist/space-sdk/src/config.ts +3 -1
  33. package/dist/space-sdk/src/functions.ts +203 -0
  34. package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
  35. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +2 -0
  36. package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
  37. package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
  38. package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
  39. package/dist/space-sdk/src/index.d.ts +10 -4
  40. package/dist/space-sdk/src/runtime.d.ts +14 -1
  41. package/dist/space-sdk/src/space.ts +333 -33
  42. package/dist/space-sdk/src/tailwind-candidates.d.ts +185 -152
  43. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +7 -4
  44. package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +10 -2
  45. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +55 -88
  46. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +9 -0
  47. package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
  48. package/dist/space-sdk/src/ui/comments/index.d.ts +1 -1
  49. package/dist/space-sdk/src/ui/comments/paneParts.d.ts +27 -5
  50. package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
  51. package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
  52. package/dist/space-sdk/src/ui/comments/useComments.d.ts +64 -74
  53. package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
  54. package/dist/space-sdk/src/ui/index.d.ts +1 -1
  55. package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
  56. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
  57. package/dist/view-renderer/dist/host.js +280 -159
  58. package/package.json +3 -3
  59. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
  60. package/skills/notis-spaces/cli.md +3 -3
  61. package/src/cli.js +2 -1
  62. package/src/command-specs/index.js +3 -0
  63. package/src/command-specs/repository-secrets.js +171 -0
  64. package/src/command-specs/spaces.js +3 -3
  65. package/src/runtime/agent-credential.js +175 -0
  66. package/src/runtime/agent-identity.js +92 -15
  67. package/src/runtime/app-platform.js +8 -0
  68. package/src/runtime/auth-recovery.js +14 -0
  69. package/src/runtime/profiles.js +15 -0
  70. package/src/runtime/skill-sync/index.ts +3 -2
  71. package/src/runtime/skill-sync/symlink-manager.ts +354 -35
  72. package/src/runtime/skill-sync/types.ts +10 -1
  73. package/src/runtime/space-functions.js +211 -0
  74. package/src/runtime/space-platform.js +12 -3
  75. package/src/runtime/space-source.js +116 -13
  76. package/src/runtime/space-test-server.js +22 -4
  77. package/src/runtime/space-verification.js +3 -1
  78. package/src/runtime/transport.js +15 -0
  79. package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
  80. package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
  81. package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
@@ -9,16 +9,22 @@ import { usageError } from './errors.js';
9
9
  * An agent's declared identity, sent on every backend call.
10
10
  *
11
11
  * Any agent driving the CLI (Claude Code or Codex on a person's computer, a script, a Cloud Computer session) says
12
- * who it is with `--agent-name`, `--agent-id` and `--agent-thread`, or the NOTIS_AGENT_NAME, NOTIS_AGENT_ID and
13
- * NOTIS_AGENT_THREAD variables (a flag wins over its variable). The backend then treats what the call writes as that
12
+ * who it is with `--agent-name`, `--agent-id`, `--agent-thread` and `--agent-thread-name`, or the NOTIS_AGENT_NAME,
13
+ * NOTIS_AGENT_ID, NOTIS_AGENT_THREAD and NOTIS_AGENT_THREAD_NAME variables (a flag wins over its variable). The backend then treats what the call writes as that
14
14
  * agent's, not the person's: a comment's Author is the declared name, it never counts as the person's comment and it
15
15
  * never wakes the agent that wrote it. The declaration is self-asserted: it names the writer, it never grants access.
16
16
  *
17
17
  * The name is a band name: a fresh lowercase imaginary rock-band name, lowercase letters and digits in at least two
18
- * words joined by hyphens, 3 to 60 characters, such as fred-and-the-machine. The name is only a name: the id decides
19
- * which comments are the agent's own. Without an explicit id the CLI generates a random one the first time a name is
20
- * used on this computer and keeps it for that name in `agents.json`, next to the CLI config file (so
21
- * NOTIS_CLI_CONFIG_FILE moves it too), written under the config lock. An explicit id always wins.
18
+ * words joined by hyphens, 3 to 60 characters, such as fred-and-the-machine, never a harness or product name
19
+ * (RESERVED_AGENT_NAMES: claude, codex, notis-agent...), so each sub-agent shows. The name is only a name: the id
20
+ * decides which comments are the agent's own. The id may be the agent's own session id (a T3 thread id, a Codex or
21
+ * Claude session id); without one the CLI generates a random one the first time a name is used on this computer and
22
+ * keeps it for that name in `agents.json`, next to the CLI config file (so NOTIS_CLI_CONFIG_FILE moves it too),
23
+ * written under the config lock. An explicit id always wins.
24
+ *
25
+ * The thread name labels the thread the agent works in (a T3 thread title, "PR #3851"), shown after its name on its
26
+ * comments and on the Goes to line. The harness (claude_code, codex, cursor_agent...) is detected from the
27
+ * environment the agent's tool sets (detectAgentHarness), or NOTIS_AGENT_HARNESS, and shows as its logo.
22
28
  *
23
29
  * The values travel percent-encoded (encodeURIComponent) in the X-Notis-Agent-* headers. The backend applies the same
24
30
  * rules (server/lib/delegated_agents/declared_agent.py) and refuses a comment written through the CLI without a name.
@@ -26,23 +32,64 @@ import { usageError } from './errors.js';
26
32
  export const AGENT_NAME_HEADER = 'X-Notis-Agent-Name';
27
33
  export const AGENT_ID_HEADER = 'X-Notis-Agent-Id';
28
34
  export const AGENT_THREAD_HEADER = 'X-Notis-Agent-Thread';
35
+ export const AGENT_THREAD_NAME_HEADER = 'X-Notis-Agent-Thread-Name';
36
+ export const AGENT_HARNESS_HEADER = 'X-Notis-Agent-Harness';
29
37
  export const AGENT_IDENTITY_ENV = {
30
38
  name: 'NOTIS_AGENT_NAME',
31
39
  id: 'NOTIS_AGENT_ID',
32
40
  thread: 'NOTIS_AGENT_THREAD',
41
+ threadName: 'NOTIS_AGENT_THREAD_NAME',
42
+ harness: 'NOTIS_AGENT_HARNESS',
33
43
  };
34
44
  export const AGENT_NAME_MIN = 3;
35
45
  export const AGENT_NAME_LIMIT = 60;
36
46
  export const BAND_NAME_EXAMPLE = 'fred-and-the-machine';
37
47
  export const BAND_NAME_RULE = `a fresh lowercase imaginary rock-band name: lowercase letters and digits in at least two words joined by hyphens, ${AGENT_NAME_MIN} to ${AGENT_NAME_LIMIT} characters, such as ${BAND_NAME_EXAMPLE}`;
38
48
  export const AGENT_IDS_VERSION = 1;
49
+ export const AGENT_ID_MIN = 3;
39
50
  export const AGENT_ID_LIMIT = 128;
40
51
  export const AGENT_THREAD_LIMIT = 512;
52
+ export const AGENT_THREAD_NAME_LIMIT = 80;
53
+ export const AGENT_HARNESS_LIMIT = 40;
54
+ // A harness or product name is no band name (server/lib/delegated_agents/declared_agent.py RESERVED_NAMES, the same list).
55
+ const RESERVED_BASES = ['claude', 'claude-code', 'codex', 'cursor', 'cursor-agent', 'gemini', 'notis', 't3', 't3-code',
56
+ 'opencode', 'agent', 'assistant', 'bot'];
57
+ export const RESERVED_AGENT_NAMES = Object.freeze(new Set(
58
+ RESERVED_BASES.flatMap((base) => [base, `${base}-cli`, `${base}-agent`]),
59
+ ));
41
60
 
42
61
  const BAND_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)+$/;
43
62
  const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:@/+-]*$/;
44
63
  // Printable ASCII without spaces: an id or a link.
45
64
  const THREAD_PATTERN = /^[\x21-\x7e]+$/;
65
+ // eslint-disable-next-line no-control-regex
66
+ const CONTROL_PATTERN = /[\x00-\x1f\x7f]/;
67
+ const HARNESS_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
68
+
69
+ /**
70
+ * The harness running this process, from the variables each tool sets in the shells it starts, or null. Claude Code
71
+ * sets CLAUDECODE=1 with CLAUDE_CODE_ENTRYPOINT and CLAUDE_CODE_SESSION_ID, Codex CODEX_* (CODEX_SANDBOX,
72
+ * CODEX_THREAD_ID...; CODEX_HOME is a person's own setting), Cursor's agent CURSOR_AGENT, Gemini CLI GEMINI_CLI,
73
+ * OpenCode OPENCODE; AI_AGENT names it in the shared convention. T3 Code runs one of these, which names the harness.
74
+ */
75
+ export function detectAgentHarness(env = process.env) {
76
+ const set = (name) => typeof env[name] === 'string' && env[name].trim() !== '';
77
+ if (set('CLAUDECODE') || set('CLAUDE_CODE_ENTRYPOINT') || set('CLAUDE_CODE_SESSION_ID')) return 'claude_code';
78
+ if (Object.keys(env).some((key) => key.startsWith('CODEX_') && key !== 'CODEX_HOME' && set(key))) return 'codex';
79
+ if (set('CURSOR_AGENT')) return 'cursor_agent';
80
+ if (set('GEMINI_CLI')) return 'gemini';
81
+ if (set('OPENCODE')) return 'opencode';
82
+ const named = String(env.AI_AGENT ?? '').toLowerCase();
83
+ if (named.startsWith('claude')) return 'claude_code';
84
+ if (named.startsWith('codex')) return 'codex';
85
+ if (named.startsWith('cursor')) return 'cursor_agent';
86
+ return null;
87
+ }
88
+
89
+ /** Whether `name` is a harness or product name rather than a band name (RESERVED_AGENT_NAMES). */
90
+ export function isReservedAgentName(name) {
91
+ return typeof name === 'string' && RESERVED_AGENT_NAMES.has(name.trim().toLowerCase());
92
+ }
46
93
 
47
94
  function pick(flag, variable) {
48
95
  if (typeof flag === 'string') return flag;
@@ -56,18 +103,30 @@ export function readAgentIdentity(globalOptions = {}, env = process.env) {
56
103
  id: pick(globalOptions.agentId, env[AGENT_IDENTITY_ENV.id]),
57
104
  thread: pick(globalOptions.agentThread, env[AGENT_IDENTITY_ENV.thread]),
58
105
  };
59
- return Object.values(raw).some((value) => typeof value === 'string' && value.trim()) ? raw : null;
106
+ const threadName = pick(globalOptions.agentThreadName, env[AGENT_IDENTITY_ENV.threadName]);
107
+ if (threadName !== undefined) raw.threadName = threadName;
108
+ if (!Object.values(raw).some((value) => typeof value === 'string' && value.trim())) return null;
109
+ // The harness alone declares nothing: it is only sent with a declaration.
110
+ const harness = pick(undefined, env[AGENT_IDENTITY_ENV.harness]) ?? detectAgentHarness(env);
111
+ return harness ? { ...raw, harness } : raw;
60
112
  }
61
113
 
62
- /** The validated declaration ({name, id?, thread?}), or null; a usage error names what to fix. */
114
+ /** The validated declaration ({name, id?, thread?, threadName?, harness?}), or null; a usage error names what to fix. */
63
115
  export function validateAgentIdentity(raw) {
64
116
  if (!raw) return null;
65
117
  const name = String(raw.name ?? '').trim();
66
118
  const id = String(raw.id ?? '').trim();
67
119
  const thread = String(raw.thread ?? '').trim();
120
+ const threadName = String(raw.threadName ?? '').trim();
121
+ const harnessText = String(raw.harness ?? '').trim().toLowerCase();
68
122
  if (!name) {
69
123
  throw usageError(
70
- `Name the agent: set ${AGENT_IDENTITY_ENV.name} (or --agent-name) whenever ${AGENT_IDENTITY_ENV.id} or ${AGENT_IDENTITY_ENV.thread} is set.`,
124
+ `Name the agent: set ${AGENT_IDENTITY_ENV.name} (or --agent-name) whenever ${AGENT_IDENTITY_ENV.id}, ${AGENT_IDENTITY_ENV.thread} or ${AGENT_IDENTITY_ENV.threadName} is set.`,
125
+ );
126
+ }
127
+ if (isReservedAgentName(name)) {
128
+ throw usageError(
129
+ `${AGENT_IDENTITY_ENV.name} (or --agent-name) "${name.slice(0, AGENT_NAME_LIMIT)}" is a harness or product name, not a band name. Pick ${BAND_NAME_RULE}, of your own for this agent, and keep it.`,
71
130
  );
72
131
  }
73
132
  if (!isBandName(name)) {
@@ -75,9 +134,9 @@ export function validateAgentIdentity(raw) {
75
134
  `${AGENT_IDENTITY_ENV.name} (or --agent-name) must be ${BAND_NAME_RULE}. Pick one for this agent and keep it.`,
76
135
  );
77
136
  }
78
- if (id && (id.length > AGENT_ID_LIMIT || !ID_PATTERN.test(id))) {
137
+ if (id && (id.length < AGENT_ID_MIN || id.length > AGENT_ID_LIMIT || !ID_PATTERN.test(id))) {
79
138
  throw usageError(
80
- `${AGENT_IDENTITY_ENV.id} must be at most ${AGENT_ID_LIMIT} characters: letters, digits and . _ : @ / + - , starting with a letter or digit.`,
139
+ `${AGENT_IDENTITY_ENV.id} must be ${AGENT_ID_MIN} to ${AGENT_ID_LIMIT} characters: letters, digits and . _ : @ / + - , starting with a letter or digit (your own session id, or leave it unset and the CLI keeps one for the name).`,
81
140
  );
82
141
  }
83
142
  if (thread && (thread.length > AGENT_THREAD_LIMIT || !THREAD_PATTERN.test(thread))) {
@@ -85,7 +144,20 @@ export function validateAgentIdentity(raw) {
85
144
  `${AGENT_IDENTITY_ENV.thread} must be a thread id or link of at most ${AGENT_THREAD_LIMIT} characters, without spaces.`,
86
145
  );
87
146
  }
88
- return { name, ...(id ? { id } : {}), ...(thread ? { thread } : {}) };
147
+ if (threadName && (Array.from(threadName).length > AGENT_THREAD_NAME_LIMIT || CONTROL_PATTERN.test(threadName))) {
148
+ throw usageError(
149
+ `${AGENT_IDENTITY_ENV.threadName} (or --agent-thread-name) must be the name of the thread you work in, at most ${AGENT_THREAD_NAME_LIMIT} characters on one line.`,
150
+ );
151
+ }
152
+ // A harness that is no identifier is dropped, never refused: it only picks a logo.
153
+ const harness = harnessText.length <= AGENT_HARNESS_LIMIT && HARNESS_PATTERN.test(harnessText) ? harnessText : '';
154
+ return {
155
+ name,
156
+ ...(id ? { id } : {}),
157
+ ...(thread ? { thread } : {}),
158
+ ...(threadName ? { threadName } : {}),
159
+ ...(harness ? { harness } : {}),
160
+ };
89
161
  }
90
162
 
91
163
  const RAW_HEADER_LIMIT = AGENT_THREAD_LIMIT;
@@ -101,13 +173,15 @@ function rawIdentityHeaders(raw) {
101
173
  put(AGENT_NAME_HEADER, raw?.name);
102
174
  put(AGENT_ID_HEADER, raw?.id);
103
175
  put(AGENT_THREAD_HEADER, raw?.thread);
176
+ put(AGENT_THREAD_NAME_HEADER, raw?.threadName);
177
+ put(AGENT_HARNESS_HEADER, raw?.harness);
104
178
  return headers;
105
179
  }
106
180
 
107
- /** Whether `name` follows the band-name rule (BAND_NAME_RULE). */
181
+ /** Whether `name` follows the band-name rule (BAND_NAME_RULE) and is no harness or product name. */
108
182
  export function isBandName(name) {
109
183
  return typeof name === 'string' && name.length >= AGENT_NAME_MIN && name.length <= AGENT_NAME_LIMIT
110
- && BAND_NAME.test(name);
184
+ && BAND_NAME.test(name) && !isReservedAgentName(name);
111
185
  }
112
186
 
113
187
  export function agentIdsFile(configFile = resolveCliConfigFile()) {
@@ -128,7 +202,8 @@ function readAgentIds(file) {
128
202
 
129
203
  function storedId(agents, name) {
130
204
  const id = Object.hasOwn(agents, name) ? agents[name] : null;
131
- return typeof id === 'string' && id.length <= AGENT_ID_LIMIT && ID_PATTERN.test(id) ? id : null;
205
+ return typeof id === 'string' && id.length >= AGENT_ID_MIN && id.length <= AGENT_ID_LIMIT && ID_PATTERN.test(id)
206
+ ? id : null;
132
207
  }
133
208
 
134
209
  /**
@@ -183,5 +258,7 @@ export function agentIdentityHeaders(runtime, options = {}) {
183
258
  const headers = { [AGENT_NAME_HEADER]: encodeURIComponent(identity.name) };
184
259
  if (id) headers[AGENT_ID_HEADER] = encodeURIComponent(id);
185
260
  if (identity.thread) headers[AGENT_THREAD_HEADER] = encodeURIComponent(identity.thread);
261
+ if (identity.threadName) headers[AGENT_THREAD_NAME_HEADER] = encodeURIComponent(identity.threadName);
262
+ if (identity.harness) headers[AGENT_HARNESS_HEADER] = encodeURIComponent(identity.harness);
186
263
  return headers;
187
264
  }
@@ -189,12 +189,20 @@ function stripNotisSdkImports(source) {
189
189
  .replace(/import\s+type\s+[\s\S]*?from\s+['"][^'"]*['"]\s*;?/g, '')
190
190
  .replace(/import\s*{([^}]+)}\s+from\s+['"]@notis\/sdk\/config['"]\s*;?/g, (_statement, names) => {
191
191
  const declarations = [];
192
+ const schemas = [];
192
193
  for (const imported of names.split(',').map(value => value.trim()).filter(Boolean)) {
193
194
  if (imported.startsWith('type ')) continue;
195
+ // The function input schemas are values, not identity helpers: take them from the project's own
196
+ // SDK package entry (built JavaScript), the one copy of them.
197
+ if (/^(threadHookInput|threadSettleInput|commentOptionInput)(?:\s+as\s+[A-Za-z_$][\w$]*)?$/.test(imported)) {
198
+ schemas.push(imported);
199
+ continue;
200
+ }
194
201
  const match = imported.match(/^(defineNotisApp|defineSpace|defineSpaces)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);
195
202
  if (!match) throw usageError(`Unsupported configuration helper: ${imported}`);
196
203
  declarations.push(`const ${match[2] || match[1]} = (value) => value;`);
197
204
  }
205
+ if (schemas.length) declarations.unshift(`import { ${schemas.join(', ')} } from '@notis/sdk';`);
198
206
  return declarations.join('\n');
199
207
  });
200
208
  }
@@ -88,6 +88,20 @@ export function createExpiredAuthError(runtime) {
88
88
  ],
89
89
  });
90
90
  }
91
+ if (runtime?.credentialSource === 'env' && runtime.agentEnvJwt) {
92
+ // A Notis agent's Cloud Computer credential and every renewal of it lapsed (agent-credential.js).
93
+ return new CliError({
94
+ code: 'auth_expired',
95
+ message: 'NOTIS_JWT is expired: this agent\'s Notis credential lapsed',
96
+ exitCode: EXIT_CODES.auth,
97
+ details: { credential_source: 'env', agent_credential: true },
98
+ hints: [
99
+ {
100
+ message: 'Start a new Cloud Computer command: it gets a fresh credential naming this agent.',
101
+ },
102
+ ],
103
+ });
104
+ }
91
105
  if (runtime?.credentialSource === 'env') {
92
106
  return new CliError({
93
107
  code: 'auth_expired',
@@ -14,6 +14,7 @@ import { getAuthRecovery, quoteShellArgument } from './auth-recovery.js';
14
14
  import { channelFromProfile, cliCommandForChannel, pinnedReleaseChannel } from './channel.js';
15
15
  import { resolveRetryEnabled } from './retry.js';
16
16
  import { readAgentIdentity } from './agent-identity.js';
17
+ import { selectAgentCredential } from './agent-credential.js';
17
18
  import {
18
19
  LIVE_API_HOSTS,
19
20
  currentApiOrigin,
@@ -864,6 +865,7 @@ export function resolveRuntimeProfile(
864
865
  const oauthJwt = profile.oauth_access_token;
865
866
  let jwt;
866
867
  let credentialKind;
868
+ let agentEnvJwt = null;
867
869
 
868
870
  // A dev credential is a real Supabase token for the worktree's test user. It
869
871
  // is only ever spendable against the loopback backend that minted it, so a
@@ -890,6 +892,17 @@ export function resolveRuntimeProfile(
890
892
  } else if (envJwt) {
891
893
  jwt = envJwt;
892
894
  credentialKind = 'env';
895
+ // A Cloud Computer command's credential naming its agent: the newest unexpired of it and its renewal
896
+ // (agent-credential.js). Any other environment token is used as is.
897
+ try {
898
+ const selected = selectAgentCredential(envJwt, { configFile: resolveConfigFile() });
899
+ if (selected) {
900
+ jwt = selected.jwt;
901
+ agentEnvJwt = envJwt;
902
+ }
903
+ } catch {
904
+ // An unreadable cache leaves the environment token in use.
905
+ }
893
906
  } else if (
894
907
  oauthJwt
895
908
  && !credentialIsExpired({ credentialKind: 'oauth', jwt: oauthJwt }, profile)
@@ -997,6 +1010,8 @@ export function resolveRuntimeProfile(
997
1010
  jwt,
998
1011
  credentialKind,
999
1012
  credentialSource: credentialKind,
1013
+ // The NOTIS_JWT of a managed agent credential, set only when `jwt` may be renewed (agent-credential.js).
1014
+ agentEnvJwt,
1000
1015
  oauthAccessToken: profile.oauth_access_token,
1001
1016
  oauthRefreshToken: profile.oauth_refresh_token,
1002
1017
  oauthAccessExpiresAt: profile.oauth_access_expires_at,
@@ -10,6 +10,7 @@ import type {
10
10
  SyncPullResponse,
11
11
  SyncSettings,
12
12
  SyncedSkill,
13
+ VerifiedAgentLinks,
13
14
  } from "./types";
14
15
  import { normalizeAgentTargets } from "./types";
15
16
  import { assertNativePull, checkedNativeReference, isNativeSkill, nativeState } from './native-identity';
@@ -343,7 +344,7 @@ function buildSyncState(
343
344
  pullResponse: SyncPullResponse,
344
345
  localSkills: LocalSkill[],
345
346
  lastSyncedAt: string | null,
346
- verifiedAgentLinks: Record<string, Partial<AgentTargets>> = {},
347
+ verifiedAgentLinks: Record<string, VerifiedAgentLinks> = {},
347
348
  failedContentNames: ReadonlySet<string> = new Set(),
348
349
  appliedRevisions: AppliedCloudRevisions = {},
349
350
  appliedFiles: Record<string, string[] | undefined> = {},
@@ -636,7 +637,7 @@ export async function materializeCloudSkillsForLocalShell(
636
637
 
637
638
  const relinkSkillNames = new Set(options.relinkSkillNames || []);
638
639
  const failures = [...failedDownloads];
639
- const verifiedLinks: Record<string, Partial<AgentTargets>> = {};
640
+ const verifiedLinks: Record<string, VerifiedAgentLinks> = {};
640
641
  for (const skill of pullResponse.skills) {
641
642
  const previous = previousState.skills[skill.name];
642
643
  if (skill.updated_at && previous?.cloudId === skill.id && previous.cloudUpdatedAt === skill.updated_at) {