zam-core 0.5.1 → 0.5.3

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.
package/dist/index.d.ts CHANGED
@@ -1586,6 +1586,10 @@ interface ReviewContext {
1586
1586
  }
1587
1587
  /** Default cap on resolved content length, so bridge JSON / terminal output stays bounded. */
1588
1588
  declare const DEFAULT_REVIEW_CONTEXT_MAX_CHARS = 6000;
1589
+ /** How long resolved review context stays in the in-process cache (5 minutes). */
1590
+ declare const REVIEW_CONTEXT_CACHE_TTL_MS: number;
1591
+ /** Clear the in-process review-context cache (mainly for tests). */
1592
+ declare function clearReviewContextCache(): void;
1589
1593
  /**
1590
1594
  * Resolves a given token's source_link into readable textual content.
1591
1595
  */
@@ -1785,9 +1789,8 @@ declare function planUpdate(decision: UpdateDecision): UpdateStep[];
1785
1789
  * and NOT the personal folder, so the mode never travels through a shared Turso
1786
1790
  * database or a synced folder, where it would be wrong for the other machine.
1787
1791
  *
1788
- * The personal-content folder itself is unchanged: it stays the existing
1789
- * `personal.workspace_dir` setting, and can already point at any local or
1790
- * file-synced directory (Drive, OneDrive, Dropbox, iCloud) — no GitHub required.
1792
+ * Workspace selection is machine-local too: `activeWorkspaceId` points at one
1793
+ * entry in `workspaces`, while legacy database settings are migrated by the CLI.
1791
1794
  */
1792
1795
 
1793
1796
  type InstallMode = "developer" | "default";
@@ -1799,6 +1802,8 @@ interface InstallConfig {
1799
1802
  ai?: MachineAiConfig;
1800
1803
  /** Machine-local paths to existing personal/team/community workspaces. */
1801
1804
  workspaces?: WorkspaceConfig[];
1805
+ /** Machine-local id of the workspace currently active in this install. */
1806
+ activeWorkspaceId?: string;
1802
1807
  }
1803
1808
  type MachineAiRole = "vision" | "recall" | "text";
1804
1809
  type MachineApiFlavor = "chat-completions" | "anthropic-messages";
@@ -1852,6 +1857,9 @@ declare function getMachineAiConfig(path?: string): MachineAiConfig;
1852
1857
  declare function saveMachineAiConfig(ai: MachineAiConfig, path?: string): void;
1853
1858
  declare function getConfiguredWorkspaces(path?: string): WorkspaceConfig[];
1854
1859
  declare function saveConfiguredWorkspaces(workspaces: WorkspaceConfig[], path?: string): void;
1860
+ declare function getActiveWorkspaceId(path?: string): string | undefined;
1861
+ declare function setActiveWorkspaceId(id: string | undefined, path?: string): void;
1862
+ declare function getActiveWorkspace(path?: string): WorkspaceConfig | undefined;
1855
1863
  declare function upsertConfiguredWorkspace(workspace: WorkspaceConfig, path?: string): WorkspaceConfig[];
1856
1864
  declare function removeConfiguredWorkspace(id: string, path?: string): WorkspaceConfig[];
1857
1865
  /**
@@ -1930,7 +1938,8 @@ interface RepoPaths {
1930
1938
  }
1931
1939
  /**
1932
1940
  * Resolve absolute paths for personal, team, and organization repositories.
1933
- * Personal falls back to personal.workspace_dir if repo.personal is not set.
1941
+ * Personal falls back to the active machine-local workspace if repo.personal is
1942
+ * not set.
1934
1943
  */
1935
1944
  declare function getRepoPaths(db: Database): Promise<RepoPaths>;
1936
1945
  /**
@@ -1948,4 +1957,4 @@ declare function resolveAllBeliefPaths(db: Database): Promise<string[]>;
1948
1957
  */
1949
1958
  declare function resolveAllGoalPaths(db: Database): Promise<string[]>;
1950
1959
 
1951
- export { type ADOConfig, type ADOCredentials, type AgentSkill, type AnalysisResult, type ApplySessionSynthesisInput, type ApplySessionSynthesisResult, BUILT_IN_SENSITIVE_MATCHERS, type BloomLevel$1 as BloomLevel, type CaptureDecision, type CaptureDenialReason, type CaptureRequest, type Card, type CardDeletionImpact, type CardState$1 as CardState, type CascadeBlockResult, type CommandRecord, type CommandSequence, type ConnectionOptions, type CreateAgentSkillInput, type CreateGoalInput, type CreateReviewInput, type CreateSessionInput, type CreateTokenInput, type Credentials, DEFAULT_OBSERVER_POLICY, DEFAULT_REVIEW_CONTEXT_MAX_CHARS, type Database, type DatabaseProvider, type DatabaseTargetInfo, type DatabaseValue, type DeleteCardResult, type DeleteTokenResult, type DiscoveryOptions, type DomainCompetence, type EvaluateInput, type EvaluateResult, type ExecuteReviewActionInput, type ExecutionContext, type FSRSParameters, type Goal, type GoalFrontmatter, type GoalStatus, type GoalSummary, HOMEBREW_CASK, type ImportResult, type InstallChannel, type InstallConfig, type InstallMode, type InstallPlan, type InstallResult, type LocalLLMRunner, type LogStepInput, type MachineAiConfig, type MachineProviderRecord, type MachineRoleBinding, type MonitorEvent, type Neighborhood, type NeighborhoodToken, OBSERVER_POLICY_UNSET_HINT, OBSERVER_POLICY_VERSION, type ObservationRating, type ObserverConsent, type ObserverPolicy, type ObserverRetention, type ObserverScope, type ObserverSettingKey, type PrepareSessionSynthesisInput, type Prerequisite, type PrerequisiteWithToken, type PromptInput, type Rating, type RecallPrompt, type RemoteDatabaseOptions, type RepoPaths, type ResolvedCaptureTarget, type ResolvedReference, type ReviewActionResult, type ReviewActionType, type ReviewContext, type ReviewLog, type ReviewQueue, type ReviewQueueItem, type ReviewQueueOptions, type RunResult, SIDECAR_POLICY_FILE, SNAPSHOT_VERSION, type SchedulingCard, type Session, type SessionStep, type SessionSummary, type SessionSynthesisCandidate, type SessionSynthesisEvidence, type SessionSynthesisPreview, type SessionSynthesisRecord, type SidecarPrivacyPolicy, type SkillProposal, type SkillSource, type SnapshotManifest, type Statement, type SupportedLocale, type SymbiosisMode, type SynthesisConfidence, type SystemProfile, type Token, type TokenDeleteImpact, type TokenPattern, type TranslationKey, type TursoCredentials, UI_OBSERVATION_PROTOCOL_VERSION, type UiActionType, type UiApplicationContext, type UiCandidateToken, type UiEvidenceRef, type UiEvidenceType, type UiObservationKind, type UiObservationReport, type UiObservedAction, type UnblockResult, type UpdateActionKind, type UpdateCardInput, type UpdateDecision, type UpdateStep, type UpdateStepKind, type UpdateTokenInput, type UserSetting, type UserStats, WINGET_PACKAGE_ID, type WorkItem, type WorkspaceConfig, type WorkspaceKind, type WorkspaceSourceControl, addPrerequisite, analyzeObservation, appendUiObservationReport, applySessionSynthesis, buildReviewQueue, buildUiSynthesisCandidates, cascadeBlock, clearADOCredentials, clearProviderApiKey, clearTursoCredentials, compareVersions, createAgentSkill, createFSRS, createGoal, createToken, decidePostCapture, decidePreCapture, decideUpdate, deleteCardForUser, deleteSetting, deleteToken, deprecateToken, detectSyncProvider, detectSystemLocale, discoverSkills, distributeGlobalSkills, endSession, ensureCard, ensureMonitorDir, ensureUiObserverDir, evaluateRating, executeReviewAction, exportSnapshot, extractTasks, extractTokenRefs, fetchActiveWorkItems, findTokens, generateBashHooks, generateBashUnhooks, generateConceptFreeCue, generatePowerShellHooks, generatePowerShellUnhooks, generatePrompt, generateZshHooks, generateZshUnhooks, getADOCredentials, getAgentSkill, getAllSettings, getAllSettingsDetailed, getBlockedCards, getCard, getCardById, getCardDeletionImpact, getConfiguredWorkspaces, getDatabaseTargetInfo, getDefaultDbPath, getDependents, getDomainCompetence, getDueCards, getGoal, getGoalTree, getInstallChannel, getInstallMode, getMachineAiConfig, getMonitorDir, getMonitorLogStats, getMonitorPath, getPackageSkillPath, getPrerequisites, getProviderApiKey, getRepoPaths, getReviewsForCard, getReviewsForUser, getSessionSummary, getSessionSynthesisRecords, getSetting, getSystemProfile, getTokenById, getTokenBySlug, getTokenDeleteImpact, getTokenNeighborhood, getTursoCredentials, getUiObservationPath, getUiObserverDir, getUserStats, hasCommand, importSnapshot, injectShellHooks, installFastFlowLM, installOllama, installOpenCode, interleave, isObserverPolicyConfigured, isUiObservationReport, listAgentSkills, listGoals, listProviderApiKeyRefs, listTokens, loadADOConfig, loadCredentials, loadInstallConfig, logReview, logStep, matchBuiltInSensitive, matchDenylist, matchesFilePath, monitorLogExists, normalizeLocale, normalizePath, openDatabase, openDatabaseWithSync, openRemoteDatabase, pairCommands, parseGoalFile, parseMonitorLog, parseObserverList, parseObserverPolicy, parseSnapshot, parseUiObservationLog, planOpenCodeInstall, planUpdate, prepareLocalModel, prepareSessionSynthesis, readMonitorLog, readUiObservationLog, removeConfiguredWorkspace, resolveAllBeliefPaths, resolveAllGoalPaths, resolveObserverPolicy, resolveReference, resolveRepoPath, resolveReviewContext, saveConfiguredWorkspaces, saveCredentials, saveInstallConfig, saveMachineAiConfig, serializeGoal, setADOCredentials, setInstallChannel, setInstallMode, setProviderApiKey, setSetting, setTursoCredentials, startSession, syncObserverSidecarPolicy, t, toSidecarPrivacyPolicy, uiObservationLogExists, uiObservationTimeSpan, unblockReady, updateCard, updateGoalStatus, updateToken, upsertConfiguredWorkspace, verifySnapshot, wouldCreateCycle, writeMonitorEvent };
1960
+ export { type ADOConfig, type ADOCredentials, type AgentSkill, type AnalysisResult, type ApplySessionSynthesisInput, type ApplySessionSynthesisResult, BUILT_IN_SENSITIVE_MATCHERS, type BloomLevel$1 as BloomLevel, type CaptureDecision, type CaptureDenialReason, type CaptureRequest, type Card, type CardDeletionImpact, type CardState$1 as CardState, type CascadeBlockResult, type CommandRecord, type CommandSequence, type ConnectionOptions, type CreateAgentSkillInput, type CreateGoalInput, type CreateReviewInput, type CreateSessionInput, type CreateTokenInput, type Credentials, DEFAULT_OBSERVER_POLICY, DEFAULT_REVIEW_CONTEXT_MAX_CHARS, type Database, type DatabaseProvider, type DatabaseTargetInfo, type DatabaseValue, type DeleteCardResult, type DeleteTokenResult, type DiscoveryOptions, type DomainCompetence, type EvaluateInput, type EvaluateResult, type ExecuteReviewActionInput, type ExecutionContext, type FSRSParameters, type Goal, type GoalFrontmatter, type GoalStatus, type GoalSummary, HOMEBREW_CASK, type ImportResult, type InstallChannel, type InstallConfig, type InstallMode, type InstallPlan, type InstallResult, type LocalLLMRunner, type LogStepInput, type MachineAiConfig, type MachineProviderRecord, type MachineRoleBinding, type MonitorEvent, type Neighborhood, type NeighborhoodToken, OBSERVER_POLICY_UNSET_HINT, OBSERVER_POLICY_VERSION, type ObservationRating, type ObserverConsent, type ObserverPolicy, type ObserverRetention, type ObserverScope, type ObserverSettingKey, type PrepareSessionSynthesisInput, type Prerequisite, type PrerequisiteWithToken, type PromptInput, REVIEW_CONTEXT_CACHE_TTL_MS, type Rating, type RecallPrompt, type RemoteDatabaseOptions, type RepoPaths, type ResolvedCaptureTarget, type ResolvedReference, type ReviewActionResult, type ReviewActionType, type ReviewContext, type ReviewLog, type ReviewQueue, type ReviewQueueItem, type ReviewQueueOptions, type RunResult, SIDECAR_POLICY_FILE, SNAPSHOT_VERSION, type SchedulingCard, type Session, type SessionStep, type SessionSummary, type SessionSynthesisCandidate, type SessionSynthesisEvidence, type SessionSynthesisPreview, type SessionSynthesisRecord, type SidecarPrivacyPolicy, type SkillProposal, type SkillSource, type SnapshotManifest, type Statement, type SupportedLocale, type SymbiosisMode, type SynthesisConfidence, type SystemProfile, type Token, type TokenDeleteImpact, type TokenPattern, type TranslationKey, type TursoCredentials, UI_OBSERVATION_PROTOCOL_VERSION, type UiActionType, type UiApplicationContext, type UiCandidateToken, type UiEvidenceRef, type UiEvidenceType, type UiObservationKind, type UiObservationReport, type UiObservedAction, type UnblockResult, type UpdateActionKind, type UpdateCardInput, type UpdateDecision, type UpdateStep, type UpdateStepKind, type UpdateTokenInput, type UserSetting, type UserStats, WINGET_PACKAGE_ID, type WorkItem, type WorkspaceConfig, type WorkspaceKind, type WorkspaceSourceControl, addPrerequisite, analyzeObservation, appendUiObservationReport, applySessionSynthesis, buildReviewQueue, buildUiSynthesisCandidates, cascadeBlock, clearADOCredentials, clearProviderApiKey, clearReviewContextCache, clearTursoCredentials, compareVersions, createAgentSkill, createFSRS, createGoal, createToken, decidePostCapture, decidePreCapture, decideUpdate, deleteCardForUser, deleteSetting, deleteToken, deprecateToken, detectSyncProvider, detectSystemLocale, discoverSkills, distributeGlobalSkills, endSession, ensureCard, ensureMonitorDir, ensureUiObserverDir, evaluateRating, executeReviewAction, exportSnapshot, extractTasks, extractTokenRefs, fetchActiveWorkItems, findTokens, generateBashHooks, generateBashUnhooks, generateConceptFreeCue, generatePowerShellHooks, generatePowerShellUnhooks, generatePrompt, generateZshHooks, generateZshUnhooks, getADOCredentials, getActiveWorkspace, getActiveWorkspaceId, getAgentSkill, getAllSettings, getAllSettingsDetailed, getBlockedCards, getCard, getCardById, getCardDeletionImpact, getConfiguredWorkspaces, getDatabaseTargetInfo, getDefaultDbPath, getDependents, getDomainCompetence, getDueCards, getGoal, getGoalTree, getInstallChannel, getInstallMode, getMachineAiConfig, getMonitorDir, getMonitorLogStats, getMonitorPath, getPackageSkillPath, getPrerequisites, getProviderApiKey, getRepoPaths, getReviewsForCard, getReviewsForUser, getSessionSummary, getSessionSynthesisRecords, getSetting, getSystemProfile, getTokenById, getTokenBySlug, getTokenDeleteImpact, getTokenNeighborhood, getTursoCredentials, getUiObservationPath, getUiObserverDir, getUserStats, hasCommand, importSnapshot, injectShellHooks, installFastFlowLM, installOllama, installOpenCode, interleave, isObserverPolicyConfigured, isUiObservationReport, listAgentSkills, listGoals, listProviderApiKeyRefs, listTokens, loadADOConfig, loadCredentials, loadInstallConfig, logReview, logStep, matchBuiltInSensitive, matchDenylist, matchesFilePath, monitorLogExists, normalizeLocale, normalizePath, openDatabase, openDatabaseWithSync, openRemoteDatabase, pairCommands, parseGoalFile, parseMonitorLog, parseObserverList, parseObserverPolicy, parseSnapshot, parseUiObservationLog, planOpenCodeInstall, planUpdate, prepareLocalModel, prepareSessionSynthesis, readMonitorLog, readUiObservationLog, removeConfiguredWorkspace, resolveAllBeliefPaths, resolveAllGoalPaths, resolveObserverPolicy, resolveReference, resolveRepoPath, resolveReviewContext, saveConfiguredWorkspaces, saveCredentials, saveInstallConfig, saveMachineAiConfig, serializeGoal, setADOCredentials, setActiveWorkspaceId, setInstallChannel, setInstallMode, setProviderApiKey, setSetting, setTursoCredentials, startSession, syncObserverSidecarPolicy, t, toSidecarPrivacyPolicy, uiObservationLogExists, uiObservationTimeSpan, unblockReady, updateCard, updateGoalStatus, updateToken, upsertConfiguredWorkspace, verifySnapshot, wouldCreateCycle, writeMonitorEvent };
package/dist/index.js CHANGED
@@ -3674,6 +3674,14 @@ function generatePrompt(input) {
3674
3674
  import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
3675
3675
  import { dirname as dirname3, join as join7, resolve } from "path";
3676
3676
  var DEFAULT_REVIEW_CONTEXT_MAX_CHARS = 6e3;
3677
+ var REVIEW_CONTEXT_CACHE_TTL_MS = 5 * 60 * 1e3;
3678
+ var reviewContextCache = /* @__PURE__ */ new Map();
3679
+ function reviewContextCacheKey(sourceLink, maxChars) {
3680
+ return `${sourceLink}\0${maxChars}`;
3681
+ }
3682
+ function clearReviewContextCache() {
3683
+ reviewContextCache.clear();
3684
+ }
3677
3685
  function htmlToText(html) {
3678
3686
  let content = html;
3679
3687
  const bodyMatch = /<body[^>]*>([\s\S]*?)<\/body>/i.exec(html);
@@ -3816,6 +3824,11 @@ async function resolveReviewContext(sourceLink, opts = {}) {
3816
3824
  const cleaned = sourceLink?.trim();
3817
3825
  if (!cleaned) return null;
3818
3826
  const maxChars = opts.maxChars ?? DEFAULT_REVIEW_CONTEXT_MAX_CHARS;
3827
+ const cacheKey = reviewContextCacheKey(cleaned, maxChars);
3828
+ const cached = reviewContextCache.get(cacheKey);
3829
+ if (cached && cached.expiresAt > Date.now()) {
3830
+ return cached.context;
3831
+ }
3819
3832
  const resolved = await resolveReference(cleaned);
3820
3833
  let content = resolved.content;
3821
3834
  let truncated = false;
@@ -3823,7 +3836,7 @@ async function resolveReviewContext(sourceLink, opts = {}) {
3823
3836
  content = content.slice(0, maxChars);
3824
3837
  truncated = true;
3825
3838
  }
3826
- return {
3839
+ const context = {
3827
3840
  sourceLink: cleaned,
3828
3841
  sourceType: resolved.sourceType,
3829
3842
  content,
@@ -3831,6 +3844,11 @@ async function resolveReviewContext(sourceLink, opts = {}) {
3831
3844
  url: resolved.url,
3832
3845
  truncated
3833
3846
  };
3847
+ reviewContextCache.set(cacheKey, {
3848
+ context,
3849
+ expiresAt: Date.now() + REVIEW_CONTEXT_CACHE_TTL_MS
3850
+ });
3851
+ return context;
3834
3852
  }
3835
3853
  function normalizePath(p) {
3836
3854
  const base = p.split("#")[0].trim();
@@ -4515,22 +4533,49 @@ function getConfiguredWorkspaces(path = defaultConfigPath()) {
4515
4533
  function saveConfiguredWorkspaces(workspaces, path = defaultConfigPath()) {
4516
4534
  const config = loadInstallConfig(path);
4517
4535
  config.workspaces = workspaces;
4536
+ if (config.activeWorkspaceId && !workspaces.some((workspace) => workspace.id === config.activeWorkspaceId)) {
4537
+ config.activeWorkspaceId = workspaces[0]?.id;
4538
+ }
4518
4539
  saveInstallConfig(config, path);
4519
4540
  }
4541
+ function getActiveWorkspaceId(path = defaultConfigPath()) {
4542
+ return loadInstallConfig(path).activeWorkspaceId;
4543
+ }
4544
+ function setActiveWorkspaceId(id, path = defaultConfigPath()) {
4545
+ const config = loadInstallConfig(path);
4546
+ if (id) {
4547
+ config.activeWorkspaceId = id;
4548
+ } else {
4549
+ delete config.activeWorkspaceId;
4550
+ }
4551
+ saveInstallConfig(config, path);
4552
+ }
4553
+ function getActiveWorkspace(path = defaultConfigPath()) {
4554
+ const config = loadInstallConfig(path);
4555
+ const id = config.activeWorkspaceId;
4556
+ return id ? config.workspaces?.find((workspace) => workspace.id === id) : void 0;
4557
+ }
4520
4558
  function upsertConfiguredWorkspace(workspace, path = defaultConfigPath()) {
4521
- const current = getConfiguredWorkspaces(path);
4559
+ const config = loadInstallConfig(path);
4560
+ const current = config.workspaces ?? [];
4522
4561
  const next = [
4523
4562
  ...current.filter((candidate) => candidate.id !== workspace.id),
4524
4563
  workspace
4525
4564
  ];
4526
- saveConfiguredWorkspaces(next, path);
4565
+ config.workspaces = next;
4566
+ saveInstallConfig(config, path);
4527
4567
  return next;
4528
4568
  }
4529
4569
  function removeConfiguredWorkspace(id, path = defaultConfigPath()) {
4530
- const next = getConfiguredWorkspaces(path).filter(
4570
+ const config = loadInstallConfig(path);
4571
+ const next = (config.workspaces ?? []).filter(
4531
4572
  (workspace) => workspace.id !== id
4532
4573
  );
4533
- saveConfiguredWorkspaces(next, path);
4574
+ config.workspaces = next;
4575
+ if (config.activeWorkspaceId === id) {
4576
+ config.activeWorkspaceId = next[0]?.id;
4577
+ }
4578
+ saveInstallConfig(config, path);
4534
4579
  return next;
4535
4580
  }
4536
4581
  function detectSyncProvider(dir) {
@@ -4862,7 +4907,7 @@ function getSystemProfile() {
4862
4907
  import { existsSync as existsSync10 } from "fs";
4863
4908
  import { resolve as resolve2 } from "path";
4864
4909
  async function getRepoPaths(db) {
4865
- const personalSetting = await getSetting(db, "repo.personal") || await getSetting(db, "personal.workspace_dir");
4910
+ const personalSetting = await getSetting(db, "repo.personal") || getActiveWorkspace()?.path;
4866
4911
  const teamSetting = await getSetting(db, "repo.team");
4867
4912
  const orgSetting = await getSetting(db, "repo.org");
4868
4913
  return {
@@ -5032,6 +5077,7 @@ export {
5032
5077
  HOMEBREW_CASK,
5033
5078
  OBSERVER_POLICY_UNSET_HINT,
5034
5079
  OBSERVER_POLICY_VERSION,
5080
+ REVIEW_CONTEXT_CACHE_TTL_MS,
5035
5081
  SIDECAR_POLICY_FILE,
5036
5082
  SNAPSHOT_VERSION,
5037
5083
  UI_OBSERVATION_PROTOCOL_VERSION,
@@ -5045,6 +5091,7 @@ export {
5045
5091
  cascadeBlock,
5046
5092
  clearADOCredentials,
5047
5093
  clearProviderApiKey,
5094
+ clearReviewContextCache,
5048
5095
  clearTursoCredentials,
5049
5096
  compareVersions,
5050
5097
  createAgentSkill,
@@ -5082,6 +5129,8 @@ export {
5082
5129
  generateZshHooks,
5083
5130
  generateZshUnhooks,
5084
5131
  getADOCredentials,
5132
+ getActiveWorkspace,
5133
+ getActiveWorkspaceId,
5085
5134
  getAgentSkill,
5086
5135
  getAllSettings,
5087
5136
  getAllSettingsDetailed,
@@ -5174,6 +5223,7 @@ export {
5174
5223
  saveMachineAiConfig,
5175
5224
  serializeGoal,
5176
5225
  setADOCredentials,
5226
+ setActiveWorkspaceId,
5177
5227
  setInstallChannel,
5178
5228
  setInstallMode,
5179
5229
  setProviderApiKey,