singularity-forge/packages/native/src/index.ts
Copilot ce7bde14f3 Fix execute-task loop detection: adaptive reconciliation instead of hard stop (#342)
* Initial plan

* Add adaptive reconciliation, concrete remediation steps, and xxHash32 JS fallback

- auto.ts: final reconciliation pass before halting on loop detection
  (runs skipExecuteTask to write blocker artifacts and advance pipeline)
- auto.ts: adaptive retry on prevCount>=2: write stub summary when still
  missing after two agent sessions, so the agent has a recovery context
- auto.ts: buildLoopRemediationSteps() helper with concrete manual steps
  when automatic reconciliation cannot resolve the unit
- xxhash/index.ts: pure-JS xxHash32 fallback when native addon does not
  export xxHash32 (prevents 'native.xxHash32 is not a function' crash)
- idle-recovery.test.ts: tests for buildLoopRemediationSteps and loop-recovery
  path in skipExecuteTask

Co-authored-by: glittercowboy <186001655+glittercowboy@users.noreply.github.com>

* Address code review feedback

- xxhash/index.ts: extract accumulate() helper to remove duplicate lane
  processing lines in the 16-byte loop
- auto.ts: replace magic number 2 with named constant STUB_RECOVERY_THRESHOLD
- idle-recovery.test.ts: add comment explaining the 3 (== MAX_UNIT_DISPATCHES)
  used in the loop-recovery test

Co-authored-by: glittercowboy <186001655+glittercowboy@users.noreply.github.com>

* Address PR review: verify post-state, fix stub wording, fix checkbox syntax, add fallback test

- auto.ts (MAX branch): check verifyExpectedArtifact() after skipExecuteTask()
  before advancing; annotate both conditions explaining what each validates
- auto.ts (self-repair branch): guard advance with verifyExpectedArtifact() so
  regex mismatches in the slice plan don't silently re-dispatch
- auto.ts (stub-recovery): write stub summary directly with "PARTIAL RECOVERY"
  wording instead of using skipExecuteTask (which would claim "exhausted N attempts")
- auto.ts (remediation): fix checkbox example to "- [x] **${tid}:" (no trailing **)
- xxhash/index.ts: export xxHash32Fallback so CI can test JS path independently
- native/src/index.ts: re-export xxHash32Fallback
- xxhash.test.mjs: add "xxHash32Fallback (pure-JS path)" describe block that
  validates the JS implementation against the reference on all test cases

Co-authored-by: glittercowboy <186001655+glittercowboy@users.noreply.github.com>

* chore: retrigger CI

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: glittercowboy <186001655+glittercowboy@users.noreply.github.com>
Co-authored-by: CI Trigger <noreply@github.com>
2026-03-14 07:26:10 -06:00

128 lines
3.3 KiB
TypeScript

/**
* @gsd/native — High-performance Rust modules exposed via N-API.
*
* Modules:
* - clipboard: native clipboard access (text + image)
* - grep: ripgrep-backed regex search (content + filesystem)
* - ps: cross-platform process tree management
* - glob: gitignore-respecting filesystem discovery with scan caching
* - highlight: syntect-based syntax highlighting
* - html: HTML to Markdown conversion
* - text: ANSI-aware text measurement and slicing
* - fd: fuzzy file path discovery
* - image: decode, encode, and resize images
for autocomplete and @-mention resolution
*/
export {
copyToClipboard,
readTextFromClipboard,
readImageFromClipboard,
} from "./clipboard/index.js";
export type { ClipboardImage } from "./clipboard/index.js";
export {
highlightCode,
supportsLanguage,
getSupportedLanguages,
} from "./highlight/index.js";
export type { HighlightColors } from "./highlight/index.js";
export { searchContent, grep } from "./grep/index.js";
export type {
ContextLine,
GrepMatch,
GrepOptions,
GrepResult,
SearchMatch,
SearchOptions,
SearchResult,
} from "./grep/index.js";
export {
killTree,
listDescendants,
processGroupId,
killProcessGroup,
} from "./ps/index.js";
export { glob, invalidateFsScanCache } from "./glob/index.js";
export type {
FileType,
GlobMatch,
GlobOptions,
GlobResult,
} from "./glob/index.js";
export { astGrep, astEdit } from "./ast/index.js";
export type {
AstFindMatch, AstFindOptions, AstFindResult,
AstReplaceChange, AstReplaceFileChange, AstReplaceOptions, AstReplaceResult,
} from "./ast/index.js";
export { htmlToMarkdown } from "./html/index.js";
export type { HtmlToMarkdownOptions } from "./html/index.js";
export {
wrapTextWithAnsi,
truncateToWidth,
sliceWithWidth,
extractSegments,
sanitizeText,
visibleWidth,
EllipsisKind,
} from "./text/index.js";
export type { SliceResult, ExtractSegmentsResult } from "./text/index.js";
export {
normalizeForFuzzyMatch,
fuzzyFindText,
generateDiff,
} from "./diff/index.js";
export type { FuzzyMatchResult, DiffResult } from "./diff/index.js";
export { fuzzyFind } from "./fd/index.js";
export type {
FuzzyFindMatch,
FuzzyFindOptions,
FuzzyFindResult,
} from "./fd/index.js";
export { parseImage, ImageFormat, SamplingFilter } from "./image/index.js";
export type { NativeImageHandle } from "./image/index.js";
export { xxHash32, xxHash32Fallback } from "./xxhash/index.js";
export { ttsrCompileRules, ttsrCheckBuffer, ttsrFreeRules } from "./ttsr/index.js";
export type { TtsrHandle, TtsrRuleInput } from "./ttsr/index.js";
export {
parseJson,
parsePartialJson,
parseStreamingJson,
} from "./json-parse/index.js";
export {
processStreamChunk,
stripAnsiNative,
sanitizeBinaryOutputNative,
} from "./stream-process/index.js";
export type { StreamState, StreamChunkResult } from "./stream-process/index.js";
export {
parseFrontmatter,
extractSection as nativeExtractSection,
extractAllSections,
batchParseGsdFiles,
parseRoadmapFile,
} from "./gsd-parser/index.js";
export type {
BatchParseResult,
FrontmatterResult,
NativeBoundaryMapEntry,
NativeRoadmap,
NativeRoadmapSlice,
ParsedGsdFile,
SectionResult,
} from "./gsd-parser/index.js";
export { truncateTail, truncateHead, truncateOutput } from "./truncate/index.js";
export type { TruncateResult, TruncateOutputResult } from "./truncate/index.js";