aismemory 0.8.9 → 0.8.11

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 (78) hide show
  1. package/README.md +61 -9
  2. package/dist/agent-key-mode.d.ts +26 -0
  3. package/dist/agent-key-mode.js +166 -40
  4. package/dist/agent-only-pass.d.ts +41 -0
  5. package/dist/agent-only-pass.js +539 -0
  6. package/dist/ais-http-error.js +6 -4
  7. package/dist/ais-http.d.ts +11 -0
  8. package/dist/ais-http.js +31 -17
  9. package/dist/cli/hooks.d.ts +40 -6
  10. package/dist/cli/hooks.js +318 -69
  11. package/dist/cli/install.d.ts +8 -0
  12. package/dist/cli/install.js +15 -0
  13. package/dist/cli/orientation-load.d.ts +18 -0
  14. package/dist/cli/orientation-load.js +50 -0
  15. package/dist/cli/read-claude-memory-tree.d.ts +37 -0
  16. package/dist/cli/read-claude-memory-tree.js +247 -2
  17. package/dist/cli/setup-core.js +7 -3
  18. package/dist/cli/slack.d.ts +2 -0
  19. package/dist/cli/slack.js +263 -0
  20. package/dist/cli/sync-memory.js +6 -3
  21. package/dist/cli-info.d.ts +1 -0
  22. package/dist/cli-info.js +4 -2
  23. package/dist/decision-card.d.ts +42 -0
  24. package/dist/decision-card.js +50 -0
  25. package/dist/decision-ledger.d.ts +24 -0
  26. package/dist/decision-ledger.js +59 -0
  27. package/dist/decision-receipt.d.ts +33 -0
  28. package/dist/decision-receipt.js +72 -0
  29. package/dist/device-poll.d.ts +16 -7
  30. package/dist/device-poll.js +31 -3
  31. package/dist/handoff-doc.d.ts +9 -0
  32. package/dist/handoff-doc.js +53 -0
  33. package/dist/hydration.d.ts +1 -1
  34. package/dist/hydration.js +7 -2
  35. package/dist/inbox-client.js +33 -26
  36. package/dist/index.js +281 -114
  37. package/dist/lesson-advice.d.ts +16 -0
  38. package/dist/lesson-advice.js +56 -0
  39. package/dist/lesson-tags.d.ts +6 -0
  40. package/dist/lesson-tags.js +7 -0
  41. package/dist/lessons.d.ts +2 -0
  42. package/dist/lessons.js +62 -0
  43. package/dist/library-tools.d.ts +22 -0
  44. package/dist/library-tools.js +72 -0
  45. package/dist/mcp/tools.d.ts +3 -0
  46. package/dist/mcp/tools.js +129 -49
  47. package/dist/mcp-instructions.d.ts +1 -1
  48. package/dist/mcp-instructions.js +4 -1
  49. package/dist/operating-layer-read.d.ts +38 -0
  50. package/dist/operating-layer-read.js +164 -0
  51. package/dist/pending-device-flow.js +1 -12
  52. package/dist/pipeline/bulk-store.d.ts +1 -0
  53. package/dist/pipeline/bulk-store.js +20 -0
  54. package/dist/pipeline/types.d.ts +2 -0
  55. package/dist/recall-warning.d.ts +14 -0
  56. package/dist/recall-warning.js +36 -0
  57. package/dist/request-timeout.d.ts +27 -2
  58. package/dist/request-timeout.js +92 -2
  59. package/dist/run-pass-mode.js +35 -29
  60. package/dist/session-identity.js +3 -1
  61. package/dist/session-start.d.ts +15 -5
  62. package/dist/session-start.js +57 -13
  63. package/dist/skill-fetch.d.ts +30 -0
  64. package/dist/skill-fetch.js +88 -0
  65. package/dist/slack-tools.d.ts +44 -0
  66. package/dist/slack-tools.js +156 -0
  67. package/dist/sources/local-claude.js +16 -2
  68. package/dist/sources/types.d.ts +2 -0
  69. package/dist/startup-identity.d.ts +4 -0
  70. package/dist/startup-identity.js +2 -0
  71. package/dist/tool-args.d.ts +28 -3
  72. package/dist/tool-args.js +92 -8
  73. package/dist/tool-scope-filter.d.ts +29 -0
  74. package/dist/tool-scope-filter.js +123 -0
  75. package/dist/version-check.d.ts +30 -3
  76. package/dist/version-check.js +59 -4
  77. package/dist/workspace-key-mode.js +37 -36
  78. package/package.json +4 -3
package/dist/ais-http.js CHANGED
@@ -6,8 +6,8 @@ import { isAuthErrorResult } from './auth-staleness.js';
6
6
  import { AisHttpError, AisInvalidJsonHttpError } from './ais-http-error.js';
7
7
  import { emitTelemetry } from './telemetry.js';
8
8
  import { retryAfterOf, shouldHonourRetryAfter, sleepSeconds } from './retry-after.js';
9
- import { readPackageVersion, setServerUpdateNotice } from './version-check.js';
10
- import { getAisRequestTimeoutMs, toAisRequestError } from './request-timeout.js';
9
+ import { readPackageVersion, setServerMinimumVersion, setServerUpdateNotice, } from './version-check.js';
10
+ import { aisRequestSignal, getAisRequestTimeoutMs, setInboxReadStage, toAisRequestError } from './request-timeout.js';
11
11
  import { withDeclaredAgent } from './declared-agent.js';
12
12
  import { captureCredentialExpiry, withCredentialExpiry } from './credential-expiry.js';
13
13
  // GETs are idempotent, so a single upstream 502/503 is worth one bounded
@@ -24,6 +24,8 @@ export const AIS_GET_RETRYABLE_STATUSES = new Set([502, 503]);
24
24
  export const AIS_GET_RETRY_DELAY_MS = 250;
25
25
  export const CLIENT_VERSION_HEADER = 'X-AIS-Client-Version';
26
26
  export const UPDATE_NOTICE_HEADER = 'X-AIS-Update-Notice';
27
+ /** Structured minimum the client compares locally (CORBOT-4142F77E). */
28
+ export const MIN_CLIENT_VERSION_HEADER = 'X-AIS-Min-Client-Version';
27
29
  let clientVersionValue;
28
30
  /** `aismemory/<package version>`, from the one shared version reader; null when unreadable. */
29
31
  function clientVersionHeaderValue() {
@@ -37,14 +39,23 @@ function clientVersionHeaderValue() {
37
39
  }
38
40
  return clientVersionValue;
39
41
  }
40
- function withClientVersion(headers) {
42
+ /** Attach `X-AIS-Client-Version` for every AIS HTTP stack (bearer, agent-key, …). */
43
+ export function withAisClientVersion(headers) {
41
44
  const value = clientVersionHeaderValue();
42
45
  if (value !== null)
43
46
  headers[CLIENT_VERSION_HEADER] = value;
44
47
  return headers;
45
48
  }
46
- /** Hand a server-sent update notice to the same path whoami/full_context read. */
47
- function captureUpdateNotice(res) {
49
+ /**
50
+ * Hand server-sent version signals to the same path whoami / full_context /
51
+ * first-tool reads. Structured minimum (CORBOT-4142F77E) is preferred; the
52
+ * free-text notice covers older servers that only set X-AIS-Update-Notice.
53
+ * Exported so agent-key / workspace-key / run-pass HTTP helpers share one path.
54
+ */
55
+ export function captureServerVersionHeaders(res) {
56
+ const minimum = res.headers.get(MIN_CLIENT_VERSION_HEADER);
57
+ if (minimum !== null)
58
+ setServerMinimumVersion(minimum);
48
59
  const notice = res.headers.get(UPDATE_NOTICE_HEADER);
49
60
  if (notice !== null)
50
61
  setServerUpdateNotice(notice);
@@ -78,9 +89,11 @@ function buildUrl(path) {
78
89
  const baseUrl = aisUrl.endsWith('/') ? aisUrl : `${aisUrl}/`;
79
90
  return new URL(path, baseUrl).toString();
80
91
  }
81
- async function readJsonBody(res, path) {
92
+ async function readJsonBody(res, path, method = 'GET') {
82
93
  const warning = captureCredentialExpiry(res);
94
+ setInboxReadStage(`${method} ${path}: body`);
83
95
  const text = await res.text();
96
+ setInboxReadStage(`${method} ${path}: body`);
84
97
  if (text.trim() === '')
85
98
  return null;
86
99
  try {
@@ -93,7 +106,7 @@ async function readJsonBody(res, path) {
93
106
  }
94
107
  }
95
108
  export async function aisPost(path, body, token) {
96
- const headers = withDeclaredAgent(withClientVersion({ 'Content-Type': 'application/json' }));
109
+ const headers = withDeclaredAgent(withAisClientVersion({ 'Content-Type': 'application/json' }));
97
110
  if (token)
98
111
  headers['Authorization'] = `Bearer ${token}`;
99
112
  const timeoutMs = getAisRequestTimeoutMs();
@@ -104,7 +117,7 @@ export async function aisPost(path, body, token) {
104
117
  headers,
105
118
  body: JSON.stringify(body),
106
119
  redirect: 'error',
107
- signal: AbortSignal.timeout(timeoutMs),
120
+ signal: aisRequestSignal(path, timeoutMs, 'POST'),
108
121
  });
109
122
  }
110
123
  catch (err) {
@@ -116,8 +129,8 @@ export async function aisPost(path, body, token) {
116
129
  });
117
130
  throw wrapped;
118
131
  }
119
- captureUpdateNotice(res);
120
- const data = await readJsonBody(res, path);
132
+ captureServerVersionHeaders(res);
133
+ const data = await readJsonBody(res, path, 'POST');
121
134
  if (!res.ok) {
122
135
  emitTelemetry({
123
136
  event: 'ais.http.failure',
@@ -135,7 +148,7 @@ export async function aisPost(path, body, token) {
135
148
  return data;
136
149
  }
137
150
  export async function aisPatch(path, body, token) {
138
- const headers = withDeclaredAgent(withClientVersion({ 'Content-Type': 'application/json' }));
151
+ const headers = withDeclaredAgent(withAisClientVersion({ 'Content-Type': 'application/json' }));
139
152
  if (token)
140
153
  headers['Authorization'] = `Bearer ${token}`;
141
154
  const timeoutMs = getAisRequestTimeoutMs();
@@ -146,7 +159,7 @@ export async function aisPatch(path, body, token) {
146
159
  headers,
147
160
  body: JSON.stringify(body),
148
161
  redirect: 'error',
149
- signal: AbortSignal.timeout(timeoutMs),
162
+ signal: aisRequestSignal(path, timeoutMs, 'PATCH'),
150
163
  });
151
164
  }
152
165
  catch (err) {
@@ -158,8 +171,8 @@ export async function aisPatch(path, body, token) {
158
171
  });
159
172
  throw wrapped;
160
173
  }
161
- captureUpdateNotice(res);
162
- const data = await readJsonBody(res, path);
174
+ captureServerVersionHeaders(res);
175
+ const data = await readJsonBody(res, path, 'PATCH');
163
176
  if (!res.ok) {
164
177
  emitTelemetry({
165
178
  event: 'ais.http.failure',
@@ -180,9 +193,9 @@ export async function aisGet(path, token) {
180
193
  for (;;) {
181
194
  try {
182
195
  res = await fetch(buildUrl(path), {
183
- headers: withDeclaredAgent(withClientVersion({ 'Authorization': `Bearer ${token}` })),
196
+ headers: withDeclaredAgent(withAisClientVersion({ 'Authorization': `Bearer ${token}` })),
184
197
  redirect: 'error',
185
- signal: AbortSignal.timeout(timeoutMs),
198
+ signal: aisRequestSignal(path, timeoutMs),
186
199
  });
187
200
  }
188
201
  catch (err) {
@@ -204,6 +217,7 @@ export async function aisGet(path, token) {
204
217
  captureCredentialExpiry(res);
205
218
  attempt += 1;
206
219
  emitTelemetry({ event: 'ais.http.retry', path, httpStatus: res.status });
220
+ setInboxReadStage(`GET ${path}: retry delay`);
207
221
  if (retryAfter === null) {
208
222
  await new Promise((resolve) => setTimeout(resolve, AIS_GET_RETRY_DELAY_MS));
209
223
  }
@@ -214,7 +228,7 @@ export async function aisGet(path, token) {
214
228
  }
215
229
  break;
216
230
  }
217
- captureUpdateNotice(res);
231
+ captureServerVersionHeaders(res);
218
232
  const data = await readJsonBody(res, path);
219
233
  if (!res.ok) {
220
234
  emitTelemetry({
@@ -31,14 +31,19 @@ export interface HookClient {
31
31
  credentialKey: string;
32
32
  call(tool: HookTool, args: Record<string, unknown>): Promise<unknown>;
33
33
  }
34
+ interface HookReadClient extends HookClient {
35
+ lessonCredentialKey?: string;
36
+ get(path: string): Promise<unknown>;
37
+ }
34
38
  /** A failure whose message is already the one-line, secret-free hint we print. */
35
39
  export declare class HookFailure extends Error {
36
40
  }
37
41
  export declare const NO_CREDENTIAL_HINT = "no credential; set AIS_WORKSPACE_KEY and AIS_AGENT_ID or run aismemory to sign in";
38
- export declare function resolveHookClient(env: NodeJS.ProcessEnv, home: string): Promise<HookClient>;
42
+ export declare function resolveHookClient(env: NodeJS.ProcessEnv, home: string): Promise<HookReadClient>;
39
43
  export declare function redactSecrets(text: string): string;
40
44
  /** One concise, secret-free stderr line naming the cause and the fix. */
41
45
  export declare function describeHookFailure(err: unknown): string;
46
+ /** Character budget for the rules and recalled memory blocks. */
42
47
  export declare const SESSION_START_MAX_CHARS = 8000;
43
48
  /** Per-run tags: stored text cannot guess the nonce, so it cannot close the block. */
44
49
  export declare function contextTags(nonce: string): {
@@ -46,14 +51,15 @@ export declare function contextTags(nonce: string): {
46
51
  close: string;
47
52
  };
48
53
  export declare const CONTEXT_PREAMBLE: string;
49
- export declare const OPERATING_LAYER_MAX_CHARS = 3000;
54
+ export declare const OPERATING_LAYER_MAX_CHARS = 6000;
55
+ export declare const OPERATING_LAYER_AGENT_RULES_RESERVED_CHARS = 2500;
50
56
  export declare function rulesTags(nonce: string): {
51
57
  open: string;
52
58
  close: string;
53
59
  };
54
60
  export declare const OPERATING_LAYER_PREAMBLE: string;
55
- /** Strip zero-width and bidi controls from rule text (same set as {@link inline}). */
56
- export declare function stripInvisibles(text: string): string;
61
+ /** Strip invisible controls, optionally preserving the original Unicode characters in a saved note. */
62
+ export declare function stripInvisibles(text: string, normalize?: boolean): string;
57
63
  /**
58
64
  * Stored text is one line and never a heading: other principals (grant
59
65
  * holders, shared sources) can write these fields. The nonce is what stops a
@@ -61,8 +67,13 @@ export declare function stripInvisibles(text: string): string;
61
67
  * fullwidth brackets) only keeps the block readable.
62
68
  */
63
69
  export declare function inline(text: string): string;
64
- /** The compact, delimited markdown block Claude Code adds to the session. */
65
- export declare function formatSessionContext(response: unknown, agentId: string, nonce?: string): string;
70
+ /**
71
+ * The compact, delimited markdown block Claude Code adds to the session.
72
+ * reservedChars is output already printed ahead of it (the RULES head), so
73
+ * the status line, rules and recalled memory share SESSION_START_MAX_CHARS.
74
+ * Startup skill bodies retain their separate byte budget.
75
+ */
76
+ export declare function formatSessionContext(response: unknown, agentId: string, nonce?: string, reservedChars?: number): string;
66
77
  export interface HookOutput {
67
78
  stdout: string;
68
79
  stderr: string;
@@ -72,7 +83,22 @@ export interface HookDeps {
72
83
  home?: string;
73
84
  /** Runs `git <args>` in `cwd` and resolves its stdout. */
74
85
  runGit?: (cwd: string, args: string[]) => Promise<string>;
86
+ /** Session-start time budget; past it the hook prints RULES NOT LOADED. */
87
+ budgetMs?: number;
88
+ /** Claude Code's SessionStart `source`: startup, resume, clear or compact. */
89
+ source?: string;
75
90
  }
91
+ export declare const SESSION_START_BUDGET_MS = 5000;
92
+ export declare const RULES_FIRST_REPLY = "Say the RULES line above, word for word, as the first line of your first reply.";
93
+ /**
94
+ * The rules come back after compaction and on resume, but the ask to repeat
95
+ * the line belongs to the first reply of a conversation, not the middle of one.
96
+ */
97
+ export declare function asksForRulesLine(source: string | undefined): boolean;
98
+ /** The `source` field of Claude Code's SessionStart hook input, if any. */
99
+ export declare function sessionStartSource(stdin: string): string | undefined;
100
+ /** `version` is a verified layer version (sha256:<64 hex>). */
101
+ export declare function rulesLoadedLine(version: string, ruleCount: number, rulesShown?: number): string;
76
102
  export declare function runSessionStart(deps?: HookDeps): Promise<HookOutput>;
77
103
  export interface SetupFullContextResult {
78
104
  response: unknown;
@@ -91,5 +117,13 @@ export declare function lastUserMessage(transcriptPath: string | undefined): Pro
91
117
  /** The handoff summary stored before compaction. */
92
118
  export declare function buildPreCompactSummary(input: z.infer<typeof hookInputSchema>, runGit?: typeof defaultRunGit): Promise<string>;
93
119
  export declare function runPreCompact(stdin: string, deps?: HookDeps): Promise<HookOutput>;
120
+ /**
121
+ * CORBOT-1417ABA6: the hook entries and the settings file they belong in,
122
+ * printed only. It never reads or writes that file, so nothing already in it
123
+ * (an env block holding a key, say) is echoed. The default target is the
124
+ * user-level ~/.claude/settings.json, which every Claude Code session for this
125
+ * OS user loads, in any folder.
126
+ */
127
+ export declare function printHookFragment(dir: string, version: string): string;
94
128
  export declare function main(argv: string[]): Promise<void>;
95
129
  export {};