@ai-matrx/alchemy 0.8.33 → 0.8.36

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.36
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/alchemy/v0.8.35..npm/alchemy/v0.8.36 -- apps/shared/alchemy`).
7
+ No source changes intended and no consumer action required.
8
+
9
+ ## 0.8.35
10
+
11
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
12
+ `git diff npm/alchemy/v0.8.33..npm/alchemy/v0.8.35 -- apps/shared/alchemy`).
13
+ No source changes intended and no consumer action required.
14
+
15
+ ## 0.8.34
16
+ ### Unreleased
17
+
18
+ - **Type-to-filter reaches every row** (clone 2026-10-01): the right-click `command` filter and `ActionPalette` open each lazy submenu while searching, so a library row ("Patient reminder card" under AI Actions ▸ My Personal) is found by typing, not only after drilling in. While rows are still opening the empty state reads "Searching…", never "No action matches". Guard: `src/react/filter-reaches-library-rows.test.tsx`. Consumer action: none.
19
+ - **The `[stubbed — N chars]` / `[truncated — N chars]` markers group through kit's `formatCount` pinned to en-US** (package-twins drain, 2026-09-30): same bytes as before (`12,345`), now from the one count formatter. Consumer action: none.
20
+
3
21
  ## 0.8.33
4
22
 
5
23
  Automatic changed-only republish (docs/metadata drift since the last tag — see
package/dist/core.cjs CHANGED
@@ -24,7 +24,7 @@ ${summary}<data format="${dataFormat}">
24
24
  `;)i++;spans.push({path,start,end:i});let last=index===paths.length-1,expected=last?`
25
25
  `:delimiter;if(!(last&&i===text.length)){if(text[i]!==expected)throw spanError(`Expected ${last?"a line break":"a delimiter"} at character ${i}.`);last||i++}}),linePath!==null&&(spans[lineSlot].end=i),i<text.length&&i++};readLine(columns.map(c=>`/columns/${pointerSegment(c.id)}`),null);for(let row=0;row<rowCount;row++)readLine(columns.map(c=>`/rows/${row}${c.path}`),`/rows/${row}`);if(i<text.length)throw spanError(`Text continues after the last row at character ${i}.`);return spans}function markdownTableSpans(text,columns,rowCount){let spans=[],lines=[],at2=0;for(let line of text.split(`
26
26
  `))lines.push({start:at2,end:at2+line.length}),at2+=line.length+1;if(lines.length!==rowCount+2)throw spanError(`A Markdown table of ${rowCount} rows has ${lines.length} lines.`);let cells=(line,paths)=>{let i=line.start;if(text.slice(i,i+2)!=="| ")throw spanError(`A table line must open with "| " at character ${i}.`);if(i+=2,paths.forEach(path=>{let start=i;for(;i<line.end&&text[i]!=="|";)i+=text[i]==="\\"?2:1;if(text[i]!=="|"||text[i-1]!==" ")throw spanError(`A table cell must close with " |" at character ${i}.`);spans.push({path,start,end:i-1}),i+=2}),i-1!==line.end)throw spanError(`A table line has more cells than columns at character ${i}.`)};cells(lines[0],columns.map(c=>`/columns/${pointerSegment(c.id)}`));for(let row=0;row<rowCount;row++){let line=lines[row+2];spans.push({path:`/rows/${row}`,start:line.start,end:line.end}),cells(line,columns.map(c=>`/rows/${row}${c.path}`))}return spans}function spanMap(draft,artifact){if(artifact.snapshotId!==draft.snapshotId||artifact.draftRevision!==draft.revision)throw spanError("This artifact was built from a different draft, so its spans cannot be read from this one. Seal the current draft again.");let text=artifact.plainText,payload=draft.payload,format=artifact.format;if(format==="json"||format==="compact-json")return jsonTextSpans(text,payload.kind==="rows"?"/rows":"");if(format==="csv"||format==="tsv"){if(payload.kind!=="rows")throw spanError(`${format.toUpperCase()} requires tabular data`);return delimitedSpans(text,format==="csv"?",":" ",exportedColumns(payload.columns),payload.rows.length)}if(format!=="plain"&&format!=="markdown"&&format!=="html")throw spanError(`The ${format} format has no text span map; spans cover plain, Markdown, JSON, CSV and TSV text.`);if(payload.kind==="rows"){let columns=exportedColumns(payload.columns);return format==="markdown"?markdownTableSpans(text,columns,payload.rows.length):delimitedSpans(text," ",columns,payload.rows.length)}if(payload.kind==="json"||payload.kind==="registered")return jsonTextSpans(text);if(payload.kind==="text"&&payload.language&&format==="markdown"){if(fencedCodeBlock(payload.text,payload.language)!==text)throw spanError("The Markdown code block does not hold this draft's text.");let start=text.indexOf(`
27
- `)+1;return[{path:"",start,end:start+payload.text.length}]}return[{path:"",start:0,end:text.length}]}function offsetSpans(spans,offset){return spans.map(s=>({path:s.path,start:s.start+offset,end:s.end+offset}))}function agentPayloadWithSpans(input,environment={}){let{text,body,bodyOffset}=assembleAgentPayload(input,environment);return(input.dataFormat??"json")!=="json"?{text,spans:[{path:"",start:bodyOffset,end:bodyOffset+body.length}]}:{text,spans:jsonTextSpans(body,"",bodyOffset)}}init_core();var EMPTY_STRUCTURE=Object.freeze({exclude:Object.freeze([]),limits:Object.freeze({})}),encode=segment=>segment.replace(/~/g,"~0").replace(/\//g,"~1"),decode=segment=>segment.replace(/~1/g,"/").replace(/~0/g,"~");function pointerSegments(pointer){if(pointer==="")return[];if(!pointer.startsWith("/"))throw new ContentTransferError("invalid-pointer",`"${pointer}" is not a JSON Pointer (it must start with "/").`);return pointer.slice(1).split("/").map(decode)}function joinPointer(segments){return segments.map(segment=>`/${encode(segment)}`).join("")}function patternMatches(pattern,pointer){let p=pointerSegments(pattern),s=pointerSegments(pointer);return p.length===s.length&&p.every((segment,index)=>segment==="*"||segment===s[index])}function patternCovers(pattern,pointer){let p=pointerSegments(pattern),s=pointerSegments(pointer);return p.length<=s.length&&p.every((segment,index)=>segment==="*"||segment===s[index])}function patternBelow(pattern,pointer){let p=pointerSegments(pattern),s=pointerSegments(pointer);return p.length>s.length&&s.every((segment,index)=>p[index]==="*"||p[index]===segment)}function displayPath(pointer,root="data"){let out=root;for(let segment of pointerSegments(pointer))segment==="*"||/^(0|[1-9]\d*)$/.test(segment)?out+=`[${segment}]`:/^[A-Za-z_$][\w$]*$/.test(segment)?out+=`${out?".":""}${segment}`:out+=`[${JSON.stringify(segment)}]`;return out}var sizes=new WeakMap;function jsonSize(value){if(value===null)return 4;if(typeof value=="string")return JSON.stringify(value).length;if(typeof value=="number")return(JSON.stringify(value)??"null").length;if(typeof value=="boolean")return value?4:5;let cached=sizes.get(value);if(cached!==void 0)return cached;let total=2;if(Array.isArray(value))value.forEach((item,index)=>{total+=jsonSize(item)+(index?1:0)});else{let index=0;for(let[key,item]of Object.entries(value))total+=JSON.stringify(key).length+1+jsonSize(item)+(index++?1:0)}return sizes.set(value,total),total}function nodeChars(value){return typeof value=="string"?value.length:jsonSize(value)}var n=value=>value.toLocaleString("en-US");function stubText(value){let chars=n(nodeChars(value));if(typeof value=="string"){let first=(value.split(`
27
+ `)+1;return[{path:"",start,end:start+payload.text.length}]}return[{path:"",start:0,end:text.length}]}function offsetSpans(spans,offset){return spans.map(s=>({path:s.path,start:s.start+offset,end:s.end+offset}))}function agentPayloadWithSpans(input,environment={}){let{text,body,bodyOffset}=assembleAgentPayload(input,environment);return(input.dataFormat??"json")!=="json"?{text,spans:[{path:"",start:bodyOffset,end:bodyOffset+body.length}]}:{text,spans:jsonTextSpans(body,"",bodyOffset)}}var import_format=require("@ai-matrx/kit/format");init_core();var EMPTY_STRUCTURE=Object.freeze({exclude:Object.freeze([]),limits:Object.freeze({})}),encode=segment=>segment.replace(/~/g,"~0").replace(/\//g,"~1"),decode=segment=>segment.replace(/~1/g,"/").replace(/~0/g,"~");function pointerSegments(pointer){if(pointer==="")return[];if(!pointer.startsWith("/"))throw new ContentTransferError("invalid-pointer",`"${pointer}" is not a JSON Pointer (it must start with "/").`);return pointer.slice(1).split("/").map(decode)}function joinPointer(segments){return segments.map(segment=>`/${encode(segment)}`).join("")}function patternMatches(pattern,pointer){let p=pointerSegments(pattern),s=pointerSegments(pointer);return p.length===s.length&&p.every((segment,index)=>segment==="*"||segment===s[index])}function patternCovers(pattern,pointer){let p=pointerSegments(pattern),s=pointerSegments(pointer);return p.length<=s.length&&p.every((segment,index)=>segment==="*"||segment===s[index])}function patternBelow(pattern,pointer){let p=pointerSegments(pattern),s=pointerSegments(pointer);return p.length>s.length&&s.every((segment,index)=>p[index]==="*"||p[index]===segment)}function displayPath(pointer,root="data"){let out=root;for(let segment of pointerSegments(pointer))segment==="*"||/^(0|[1-9]\d*)$/.test(segment)?out+=`[${segment}]`:/^[A-Za-z_$][\w$]*$/.test(segment)?out+=`${out?".":""}${segment}`:out+=`[${JSON.stringify(segment)}]`;return out}var sizes=new WeakMap;function jsonSize(value){if(value===null)return 4;if(typeof value=="string")return JSON.stringify(value).length;if(typeof value=="number")return(JSON.stringify(value)??"null").length;if(typeof value=="boolean")return value?4:5;let cached=sizes.get(value);if(cached!==void 0)return cached;let total=2;if(Array.isArray(value))value.forEach((item,index)=>{total+=jsonSize(item)+(index?1:0)});else{let index=0;for(let[key,item]of Object.entries(value))total+=JSON.stringify(key).length+1+jsonSize(item)+(index++?1:0)}return sizes.set(value,total),total}function nodeChars(value){return typeof value=="string"?value.length:jsonSize(value)}var n=value=>(0,import_format.formatCount)(value,{locale:"en-US"});function stubText(value){let chars=n(nodeChars(value));if(typeof value=="string"){let first=(value.split(`
28
28
  `,1)[0]??"").trim(),head=first.length>120?`${first.slice(0,120)}\u2026`:first;return`${head?`${head} `:""}[stubbed \u2014 ${chars} chars]`}if(Array.isArray(value))return`[stubbed \u2014 ${n(value.length)} items, ${chars} chars]`;if(value&&typeof value=="object"){let header=Object.entries(value).filter(([,item])=>typeof item=="string"&&item.length<=60&&!item.includes(`
29
29
  `)||typeof item=="number"||typeof item=="boolean").slice(0,4).map(([key,item])=>`${key}: ${String(item)}`);return`[stubbed \u2014 ${header.length?`${header.join(", ")} \u2014 `:""}${n(Object.keys(value).length)} keys, ${chars} chars]`}return`[stubbed \u2014 ${chars} chars]`}function truncateText(text,max){return text.length>max?`${text.slice(0,max)} \u2026 [truncated \u2014 ${n(text.length)} chars]`:text}function assertLimit2(limit,pattern){if(limit.kind!=="stub"&&(!Number.isSafeInteger(limit.value)||limit.value<0))throw new ContentTransferError("invalid-limit",`The limit on ${displayPath(pattern)} must be a whole number of 0 or more.`)}function concretePointers(value,pattern){let want=pointerSegments(pattern),out=[],walk=(node,depth,at2)=>{if(depth===want.length){out.push(joinPointer(at2));return}if(node===null||typeof node!="object")return;let segment=want[depth],entries=Array.isArray(node)?node.map((item,index)=>[String(index),item]):Object.entries(node);for(let[key,child]of entries)(segment==="*"||segment===key)&&walk(child,depth+1,[...at2,key])};return walk(value,0,[]),out}function applyStructureToJson(value,recipe,labels={}){recipe.exclude.forEach(pattern=>pointerSegments(pattern));let limitEntries=Object.entries(recipe.limits);limitEntries.forEach(([pattern,limit])=>{pointerSegments(pattern),assertLimit2(limit,pattern)});let excluded=new Map,limited=new Map,tally=(map,pattern,chars)=>{let current=map.get(pattern)??{count:0,chars:0};map.set(pattern,{count:current.count+1,chars:current.chars+chars})},walk=(node,segments,cap)=>{let pointer=joinPointer(segments),exclusion=segments.length?recipe.exclude.find(pattern=>patternMatches(pattern,pointer)):void 0;if(exclusion!==void 0){tally(excluded,exclusion,nodeChars(node));return}let limitEntry=limitEntries.find(([pattern])=>patternMatches(pattern,pointer)),limit=limitEntry?.[1];if(limitEntry&&limit?.kind==="stub")return tally(limited,limitEntry[0],nodeChars(node)),stubText(node);let nextCap=limitEntry&&limit?.kind==="maxChars"?{pattern:limitEntry[0],max:limit.value}:cap;if(typeof node=="string")return nextCap&&node.length>nextCap.max?(tally(limited,nextCap.pattern,node.length),truncateText(node,nextCap.max)):node;if(node===null||typeof node!="object")return node;if(Array.isArray(node)){let items=node.map((item,index)=>walk(item,[...segments,String(index)],nextCap)).filter(item=>item!==void 0);return limitEntry&&limit?.kind==="maxItems"&&items.length>limit.value&&(tally(limited,limitEntry[0],items.length-limit.value),items=[...items.slice(0,limit.value),`[\u2026 ${n(items.length-limit.value)} more items]`]),items}let out={};for(let[key,item]of Object.entries(node)){let kept=walk(item,[...segments,key],nextCap);kept!==void 0&&(out[key]=kept)}return out},next=walk(value,[],null)??null,omissions=[];for(let[pattern,{count,chars}]of excluded)omissions.push({path:pattern,reason:"excluded",count,label:labels[pattern]??`${displayPath(pattern)} \u2014 ${n(chars)} chars`});for(let[pattern,{count,chars}]of limited){let limit=recipe.limits[pattern],what=limit.kind==="stub"?`stubbed (${n(chars)} chars)`:limit.kind==="maxChars"?`cut to ${n(limit.value)} chars`:`kept the first ${n(limit.value)} items`;omissions.push({path:pattern,reason:"truncated",count,label:`${labels[pattern]??displayPath(pattern)} \u2014 ${what}`})}return{value:next,omissions}}function applyJsonStructure(draft,recipe,labels={}){let payload=draft.payload;if(payload.kind!=="json"&&payload.kind!=="registered"||!recipe.exclude.length&&!Object.keys(recipe.limits).length)return draft;let{value,omissions}=applyStructureToJson(payload.value,recipe,labels);return deriveDraft(draft,{...payload,value},omissions,"Structure choices")}function outputPointer(value,recipe,pointer){let segments=pointerSegments(pointer),out=[],node=value;for(let depth=0;depth<=segments.length;depth++){let here=joinPointer(segments.slice(0,depth));if(depth>0&&recipe.exclude.some(pattern=>patternMatches(pattern,here)))return null;let limitEntry=Object.entries(recipe.limits).find(([pattern])=>patternMatches(pattern,here));if(limitEntry?.[1].kind==="stub"||depth===segments.length)return joinPointer(out);let segment=segments[depth];if(node===null||typeof node!="object"||node===void 0)return null;if(Array.isArray(node)){let index=Number(segment);if(!Number.isSafeInteger(index)||index>=node.length)return null;let shifted=index;for(let j=0;j<index;j++)recipe.exclude.some(pattern=>patternMatches(pattern,`${here}/${j}`))&&shifted--;if(limitEntry?.[1].kind==="maxItems"&&shifted>=limitEntry[1].value)return null;out.push(String(shifted)),node=node[index]}else{if(!Object.prototype.hasOwnProperty.call(node,segment))return null;out.push(segment),node=node[segment]}}return joinPointer(out)}var RANGE=/^\/text\/(\d+)-(\d+)$/;function isProseSection(section){return RANGE.test(section.path)}function sectionLayout(text,sections,included,limits={}){let keep=new Set(included),parsed=sections.map(section=>{let m=RANGE.exec(section.path),start=m?Number(m[1]):NaN,end=m?Number(m[2]):NaN;if(!m||start>end||end>text.length)throw new ContentTransferError("invalid-section",`Section "${section.path}" is not a range of this text. Declare a prose section as /text/<start>-<end> within the text.`);let limit=limits[section.id];return limit&&assertLimit2(limit,section.path),{section,start,end,limit}}).sort((a,b)=>a.start-b.start),out="",at2=0,omissions=[],ranges={};for(let{section,start,end,limit}of parsed){if(start<at2)throw new ContentTransferError("invalid-section",`Section "${section.label}" overlaps the section before it.`);out+=text.slice(at2,start),at2=end;let body=text.slice(start,end);if(!keep.has(section.id)){omissions.push({path:section.path,reason:"excluded",label:`${section.label} \u2014 ${n(body.length)} chars`});continue}let trailing=/\s*$/.exec(body)?.[0]??"",written=body;limit?.kind==="stub"?(written=`${stubText(body.slice(0,body.length-trailing.length))}${trailing}`,omissions.push({path:section.path,reason:"truncated",label:`${section.label} \u2014 stubbed (${n(body.length)} chars)`})):limit?.kind==="maxChars"&&body.length-trailing.length>limit.value&&(written=`${truncateText(body.slice(0,body.length-trailing.length),limit.value)}${trailing}`,omissions.push({path:section.path,reason:"truncated",label:`${section.label} \u2014 cut to ${n(limit.value)} chars`})),ranges[section.id]={start:out.length,end:out.length+written.length-trailing.length},out+=written}return out+=text.slice(at2),{text:out,omissions,ranges}}function applySectionStructure(draft,sections,included,limits={}){let payload=draft.payload;if(payload.kind==="text"||payload.kind==="markdown"){let layout=sectionLayout(payload.text,sections,included,limits);return deriveDraft(draft,{...payload,text:layout.text},layout.omissions,"Selected sections")}if(payload.kind==="json"||payload.kind==="registered"){let keep=new Set(included),labels=Object.fromEntries(sections.map(section=>[section.path,section.label])),recipe={exclude:sections.filter(section=>!keep.has(section.id)).map(section=>section.path),limits:Object.fromEntries(sections.filter(section=>keep.has(section.id)&&limits[section.id]).map(section=>[section.path,limits[section.id]]))},{value,omissions}=applyStructureToJson(payload.value,recipe,labels);return deriveDraft(draft,{...payload,value},omissions,"Selected sections")}return draft}init_core();var TRANSFER_DEFAULT_RECIPE_SETTING="alchemy.transfer.default_recipe",KEY=/^[a-z0-9][a-z0-9._:-]{0,127}$/;function recipeKey(sourceKind){if(!KEY.test(sourceKind))throw new ContentTransferError("invalid-recipe-key",`"${sourceKind}" is not a source-kind id (lowercase letters, digits and . _ : -, up to 128 characters).`);return sourceKind}var isRecord=v=>v!==null&&typeof v=="object"&&!Array.isArray(v);async function resolveDefaultRecipe(ports,sourceKind,organizationId){let key=recipeKey(sourceKind),notices=[],skip=(error,sentence,remedy)=>{notices.push({sentence,remedy}),ports.diagnostics.capture(error,{area:"operate",detail:{recipeKey:key,sentence}})};if(ports.persistence)try{let own=await ports.persistence.readSetting(TRANSFER_DEFAULT_RECIPE_SETTING);if(own!==null){if(!isRecord(own))skip(new Error("person default recipes are not a map"),"Your saved default recipes could not be read (they are not a list of recipes), so they were skipped.","Save your default recipe for this source again.");else if(own[key]!==void 0){let recipe=own[key];if(isRecord(recipe))return{recipe,from:"person",notices};skip(new Error("person default recipe is not an object"),"Your default recipe for this source is not a recipe, so it was skipped.","Save your default recipe for this source again.")}}}catch(error){skip(error,"Your own default recipe could not be read, so the organization's default applies.","Reopen the workspace to try again.")}if(ports.transferKnobs)try{let org=await ports.transferKnobs.defaultRecipe(key,organizationId);if(org!==null){if(isRecord(org))return{recipe:org,from:"organization",notices};skip(new Error("organization default recipe is not an object"),"Your organization's default recipe for this source is not a recipe, so it was skipped.","Ask an organization admin to set the default recipe again.")}}catch(error){skip(error,"Your organization's default recipe could not be read, so the workspace opens on Full.","Reopen the workspace to try again.")}return{recipe:null,from:"built-in",notices}}async function setPersonDefaultRecipe(ports,sourceKind,recipe){let key=recipeKey(sourceKind),persistence=ports.persistence;if(!persistence)throw new ContentTransferError("capability-absent","This app cannot save your own settings, so a personal default recipe is not available here.");let current;try{current=await persistence.readSetting(TRANSFER_DEFAULT_RECIPE_SETTING)}catch(error){let reason=error instanceof Error?error.message:String(error);throw new ContentTransferError("read-failed",`Nothing was saved: your other default recipes could not be read (${reason}), and saving now would have replaced all of them. Try again in a moment.`)}if(current!==null&&!isRecord(current))throw new ContentTransferError("invalid-setting","Nothing was saved: your saved default recipes are not a list of recipes, so one cannot be changed without replacing them all.");let map={...current??{}};if(recipe===null){if(!(key in map))return;delete map[key]}else map[key]=recipe;await persistence.writeSetting(TRANSFER_DEFAULT_RECIPE_SETTING,Object.keys(map).length===0?null:map)}
30
30
  //# sourceMappingURL=core.cjs.map