Skip to content

fix(emergent): forged tool names are held to the name rule and skill exports write only inside their folder, and export follow-ups from the cold read of #332 - #338

Merged
jddunn merged 6 commits into
masterfrom
fix/skill-exporter-path
Oct 12, 2026

Conversation

@jddunn

@jddunn jddunn commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

The skill exporter names a forged tool's folder after the tool, and the forge took the name from the model's forge_tool call with only a non-empty check. The forge now holds a tool's name to a rule, and the exporter checks the name again and writes only inside its output folder. This pull request also carries the follow-ups from the cold read of #332 for the Markdown and Obsidian exporters.

  • Forged tool names. forge_tool and EmergentCapabilityEngine.forge hold a tool's name to two rules before anything is tested, judged or registered:

    • the shared rule for a file or folder name built from data (pathNameProblem in src/core/utils/pathName.ts, the rule the wiki and the memory exporters use), so a name the forge accepts is one the exporter accepts;
    • the identifier pattern ^[a-zA-Z][a-zA-Z0-9_-]*$, which the agent forge already held a synthesised role to. It is now one constant, IDENTIFIER_PATTERN in src/cognition/emergent/ToolName.ts, used by both. It is the form provider function names take, and it keeps a name to one ASCII word.

    A refused name fails forge_tool with details: { code: 'INVALID_TOOL_NAME', problem }, and a direct engine.forge with the same message. A missing or empty name keeps its name is required error. The name description in the tool's input schema states the rule.

  • Skill export. writeSkillFile and exportToolAsSkillPack build the tool's folder with resolveToolFolder. The name is checked against the shared name rule again, so a tool the forge did not check, such as one loaded from a stored row or one a host builds itself, is checked too. The folder must then resolve inside outputDir (resolveInsideFolder). Otherwise both reject with InvalidToolNameError (exported from @framers/agentos/emergent, with code and problem) before any folder is made or file written.

  • Links below the skills folder. The folder and file checks the Markdown exporter used move to src/core/utils/linkFreeWrite.ts, and both exporters write through them. The skill exporter makes the tool's folder one name at a time and refuses a link there, looks at each file's place before it opens any, and opens each file never through a link and never waiting, writing only into a regular file with one name. A symbolic link at the folder or at a file, a second name for a file, or anything but a regular file at a file's place rejects with SkillExportRefusedError (code: 'SKILL_EXPORT_REFUSED', problem: 'link' or 'special'), and nothing is written. The output folder itself may be a link.

  • Other joins. No other code in src builds a path to write from a tool, skill, agent or persona name. The other joins use names read from a folder listing, a sanitised provider id, or generated temporary names.

  • Markdown and Obsidian export follow-ups from the cold read of fix(memory): Markdown and Obsidian exports write only inside the export folder, and wiki follow-ups from the cold read of #323 #332:

    • A trace's file is opened with O_NONBLOCK where the platform has it, so a named pipe that no process reads fails the open at once. An open file that is not a regular file, or a folder at the file's place, is left out with a new problem, special, and nothing is written to it.
    • Each open file's device and inode are claimed in export order before any file is emptied. Of two traces whose names the file system makes one file in a way the case key does not foresee, such as a Windows short name, the older is written and the newer is left out as collision. The case key now folds each character through upper case when its upper case is one character, so it joins letters that lower-casing alone keeps apart but macOS and Windows treat as one (the long s and s, the final sigma and sigma, the micro sign and mu), and keeps apart names those systems keep apart (ß and ss).
    • Files are opened, checked and written 64 at a time (MAX_OPEN_TRACE_FILES), and the identity claims hold across batches, so a large export keeps a bounded number of files open. An error other than a refusal, such as a full disk or a failed close, rejects the export once every other trace has been tried.
  • describeRefusedName moves from WikiPageId.ts to pathName.ts, so a refused wiki page id and a refused tool name are described the same way in their errors.

Linked issues

None.

Type of change

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

How this was verified

CI on this branch: Test & Lint (build, lint, type check and the whole suite), Batch-1 gated tests, browser tests and the release dry run. New and changed tests:

  • src/cognition/emergent/__tests__/skill-export-paths.integration.test.ts, through a real tool orchestrator and engine and a temp skills folder with files one and two levels above it:
    • forge_tool refuses names that would leave the folder, a dot name and a name with a space, each with the typed details, before the judge runs, and registers nothing;
    • a direct engine.forge refuses the same kind of name;
    • a tool forged as double_it is written by both exporters to its own folder, and nothing else changes;
    • a tool loaded from a stored row whose name would leave the folder is refused by both exporters, and nothing is written inside the skills folder or above it;
    • a link at the tool's folder to a folder outside, a link at CAPABILITY.yaml to the file two levels up, and a second name at SKILL.md for the file one level up: each is refused with SkillExportRefusedError, no file is made, and the files outside keep their text.
  • src/cognition/emergent/__tests__/tool-name.test.ts: the forge's name rule and resolveToolFolder. Accepted names, the longest among them. Refused names, each with its problem: other types, empty, separators, a drive, a stream, control characters, dot names, edge spaces and dots, past the byte limit, and names that are safe folder names but no identifier. Each refusal checked with path.posix and path.win32, a folder the path functions place outside, and the error message.
  • src/cognition/memory/io/__tests__/exportTracePaths.integration.test.ts, through Memory.importFrom and Memory.export:
    • in Markdown and Obsidian form, the long s and s: the newer is left out as collision, and the older's file holds its own text; ß and ss are both written;
    • two names the file system makes one file, opened in the same batch and in a later batch (the open is redirected in the test, as a Windows short name would be): both newer traces are left out, and the oldest's file holds only its text;
    • a folder and two named pipes, one with a reader and one without, at traces' files: all three are left out as special, the export settles at once, and nothing is written into the pipe (skipped on Windows);
    • an exporter subclass whose paths lead out of the export folder, relative and absolute: those traces are left out as outside, and nothing is written outside.
  • src/api/__tests__/souledAgent.test.ts: the second start's boot index skips all five pages named after object members and indexes and removes none.

Migration notes

  • A forge request whose tool name is not an ASCII letter followed by ASCII letters, digits, underscores and hyphens, at most 200 characters, is refused. Tools already stored keep their names and still load. The skill exporters refuse only a name that is not a safe folder name.
  • writeSkillFile and exportToolAsSkillPack return absolute paths, also for a relative outputDir, reject with InvalidToolNameError for a refused name, and reject with SkillExportRefusedError when a link, a second name or anything but a regular file is at the tool's folder or files.
  • RefusedExportTrace.problem has a new value, special. A folder at a trace's file place is left out with it, where the export rejected with EISDIR.
  • A Markdown or Obsidian export that meets an error other than a refusal rejects once every other trace has been tried.

Checklist

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

…me, and write a skill export only inside its output folder
…ace's file without waiting, finds two names for one file by the open file, and holds a bounded number of files open
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 12, 2026 14:00
@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 13 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T14:30:48.055399Z d681264 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: cf7a8687-9ccc-4580-9d68-4c99e3d40891

📥 Commits

Reviewing files that changed from the base of the PR and between 1858602 and d681264.


📒 Files selected for processing (8)
  • docs/MEMORY_OPERATIONS.md
  • docs/architecture/EMERGENT_CAPABILITIES.md
  • src/cognition/emergent/SkillExporter.ts
  • src/cognition/emergent/__tests__/skill-export-paths.integration.test.ts
  • src/cognition/emergent/index.ts
  • src/cognition/memory/io/MarkdownExporter.ts
  • src/cognition/memory/io/__tests__/exportTracePaths.integration.test.ts
  • src/core/utils/linkFreeWrite.ts

🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/MEMORY_OPERATIONS.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.



📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The PR adds shared forged-tool name validation and safeguards for skill exports. It changes Markdown trace exports to refuse unsafe destinations and filename collisions. It also centralizes refused-name formatting and adds assertions for repeated agent startup.

Changes

Forged tool names and skill exports

Layer / File(s) Summary
Shared name rules and forge validation
src/cognition/emergent/ToolName.ts, src/cognition/emergent/EmergentCapabilityEngine.ts, src/cognition/emergent/ForgeToolMetaTool.ts, src/cognition/emergent/EmergentAgentForge.ts, src/cognition/emergent/index.ts, src/cognition/emergent/__tests__/tool-name.test.ts, docs/SELF_EXTENSION.md
Forge entry points use shared name rules and typed errors. Tests cover accepted and refused names. The documentation describes the accepted name format and refusal behavior.
Skill export folder and file safeguards
src/core/utils/linkFreeWrite.ts, src/cognition/emergent/SkillExporter.ts, src/cognition/emergent/index.ts, src/cognition/emergent/__tests__/skill-export-paths.integration.test.ts, docs/architecture/EMERGENT_CAPABILITIES.md
Both skill exporters resolve tool folders under the output directory and use checked file writes. Tests cover valid exports, invalid persisted names, symlinks, and hard links.

Markdown trace export safety

Layer / File(s) Summary
Shared link-free writes and bounded trace export
src/core/utils/linkFreeWrite.ts, src/cognition/memory/io/MarkdownExporter.ts, src/cognition/memory/io/facade/Memory.ts, src/cognition/memory/io/facade/types.ts, src/cognition/memory/io/__tests__/exportTracePaths.integration.test.ts, docs/MEMORY_OPERATIONS.md
The exporter processes traces in batches of up to 64. It refuses links, non-regular files, outside paths, and colliding destinations. It tries remaining traces before throwing the first non-refusal open, write, or close error. Tests cover collisions, special files, and outside paths.

Shared refused-name formatting

Layer / File(s) Summary
Shared refused-name formatting
src/core/utils/pathName.ts, src/cognition/substrate/memory/wiki/WikiPageId.ts
Wiki page ID errors use a shared formatter that describes non-string values and escapes or truncates strings.

Repeated agent-start indexing test

Layer / File(s) Summary
Repeated-start index assertions
src/api/__tests__/souledAgent.test.ts
The test checks that a second agent startup skips all five existing page names, with no pages indexed or removed.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to d6812

No actionable merge risk is established for the tool-name and export-safety changes; proceed with normal checks.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 16 files. (2 skipped: …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly describes the forged tool-name validation, skill export path protections, and Markdown/Obsidian export follow-ups. It is long but remains specific and related to the main changes.
Description check Passed The description includes all required sections, explains the changes, lists verification steps, documents migration notes, and provides a checklist. One checklist item remains unchecked, but the descr…

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR adds defense-in-depth for model- and storage-derived tool names, ensuring forged tools meet both path and identifier rules and skill exports write only within their output directory. It also hardens Markdown/Obsidian exports against special files and filesystem-level collisions while bounding open handles, and centralizes name-error formatting with related regression tests and documentation.

Sequence diagram for forged tool name validation

sequenceDiagram
    participant Caller
    participant ForgeToolMetaTool
    participant EmergentCapabilityEngine
    participant EmergentJudge
    participant EmergentToolRegistry

    Caller->>ForgeToolMetaTool: execute(args)
    ForgeToolMetaTool->>ForgeToolMetaTool: forgedToolNameProblem(args.name)
    alt invalid tool name
        ForgeToolMetaTool-->>Caller: INVALID_TOOL_NAME
    else valid tool name
        ForgeToolMetaTool->>EmergentCapabilityEngine: forge(request)
        EmergentCapabilityEngine->>EmergentCapabilityEngine: forgedToolNameProblem(request.name)
        EmergentCapabilityEngine->>EmergentJudge: judge(candidate)
        EmergentJudge-->>EmergentCapabilityEngine: approval
        EmergentCapabilityEngine->>EmergentToolRegistry: register(tool)
        EmergentCapabilityEngine-->>ForgeToolMetaTool: ForgeResult
        ForgeToolMetaTool-->>Caller: ForgeResult
    end
Loading

Sequence diagram for bounded trace export validation

sequenceDiagram
    participant Memory
    participant MarkdownExporter
    participant FileSystem

    Memory->>MarkdownExporter: export(outputDir)
    MarkdownExporter->>MarkdownExporter: Sort traces oldest first
    loop batches of MAX_OPEN_TRACE_FILES
        MarkdownExporter->>FileSystem: openTraceFile(path)
        FileSystem-->>MarkdownExporter: regular file and device/inode
        MarkdownExporter->>MarkdownExporter: Claim file identity
        alt link, special file, or collision
            MarkdownExporter-->>MarkdownExporter: Add refused trace
        else unique regular file
            MarkdownExporter->>FileSystem: truncate and write trace
        end
        MarkdownExporter->>FileSystem: close file handles
    end
    alt non-refusal error occurred
        MarkdownExporter-->>Memory: Reject after other traces are tried
    else export complete
        MarkdownExporter-->>Memory: ExportResult with refused traces
    end
Loading

Flow diagram for safe skill export paths

flowchart TD
    A[Tool name and outputDir] --> B[resolveToolFolder]
    B --> C{pathNameProblem}
    C -->|invalid| D[Throw InvalidToolNameError]
    C -->|valid| E[resolveInsideFolder]
    E --> F{Folder inside outputDir}
    F -->|no| D
    F -->|yes| G[Create tool folder]
    G --> H[Write SKILL.md or CAPABILITY.yaml]
Loading

File-Level Changes

Change Details Files
Constrain forged tool names consistently and prevent skill exports from escaping their destination.
  • Added shared identifier and path-name validation with typed INVALID_TOOL_NAME errors.
  • Applied validation before forge testing, judging, or registration, including direct engine calls.
  • Resolved skill folders safely inside outputDir and revalidated tools loaded from storage or constructed by hosts.
  • Exported the error type and documented the naming and path guarantees.
src/cognition/emergent/ToolName.ts
src/cognition/emergent/ForgeToolMetaTool.ts
src/cognition/emergent/EmergentCapabilityEngine.ts
src/cognition/emergent/EmergentAgentForge.ts
src/cognition/emergent/SkillExporter.ts
src/cognition/emergent/index.ts
src/cognition/emergent/__tests__/tool-name.test.ts
src/cognition/emergent/__tests__/skill-export-paths.integration.test.ts
docs/SELF_EXTENSION.md
docs/architecture/EMERGENT_CAPABILITIES.md
Harden Markdown and Obsidian trace exports against special files, filesystem aliases, and unbounded file descriptor usage.
  • Open trace files non-blocking, reject non-regular files as special, and avoid truncating refused files.
  • Claim device/inode identities in export order to detect collisions not captured by path keys.
  • Use broader Unicode-aware case folding and process files in batches of 64 while preserving oldest-trace precedence.
  • Continue attempting independent traces before surfacing non-refusal errors such as write failures.
  • Document the new special and collision behaviors and extend integration coverage.
src/cognition/memory/io/MarkdownExporter.ts
src/cognition/memory/io/facade/types.ts
src/cognition/memory/io/facade/Memory.ts
src/cognition/memory/io/__tests__/exportTracePaths.integration.test.ts
docs/MEMORY_OPERATIONS.md
Centralize refused-name formatting and verify boot indexing behavior for object-member-named wiki pages.
  • Moved shared refused-name description logic into pathName utilities and reused it for wiki page errors.
  • Expanded the souled-agent regression test to assert the second boot skips all existing pages without indexing or removing them.
src/core/utils/pathName.ts
src/cognition/substrate/memory/wiki/WikiPageId.ts
src/api/__tests__/souledAgent.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Validate forged tool names and harden skill and memory exports

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Reject unsafe forged tool names before testing or registration, and confine skill exports to their
 output folder.
• Refuse special files and colliding trace paths while keeping Markdown and Obsidian exports
 bounded.
• Add regression coverage and document the new validation and refusal behavior.
Diagram

graph TD
  Forge["forge_tool"] --> Engine["Forge engine"] --> Name["Tool name rules"] --> Skills["Skill exporter"] --> SkillFiles[("Skill files")]
  Paths["Shared path rules"] --> Name
  Paths --> Memory["Memory exporter"] --> TraceFiles[("Trace files")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Write trace files sequentially
  • ➕ Simpler file-handle and error handling
  • ➕ Only one trace file open at a time
  • ➖ Sacrifices parallel I/O on large exports
  • ➖ Still needs persistent inode claims to detect aliases across traces

Recommendation: Keep the bounded-batch approach: it retains parallel I/O while limiting open handles and detecting file-system aliases across batches. Retaining the exporter-side name check is important because persisted or host-built tools can bypass the forge.

Files changed (18) +791 / -81

Enhancement (1) +2 / -0
index.tsExpose typed tool-name refusals +2/-0

Expose typed tool-name refusals

• Exports InvalidToolNameError and ToolNameProblem from the emergent entry point for skill-export callers.

src/cognition/emergent/index.ts

Bug fix (6) +315 / -54
EmergentCapabilityEngine.tsValidate names on direct forge calls +11/-0

Validate names on direct forge calls

• Refuses invalid tool names before building, testing, judging, or registering a candidate, including when a host calls the engine directly.

src/cognition/emergent/EmergentCapabilityEngine.ts

ForgeToolMetaTool.tsRefuse invalid forge_tool names with typed details +19/-2

Refuse invalid forge_tool names with typed details

• Checks supplied names before invoking the engine and returns INVALID_TOOL_NAME details for refused names. The input description now states the accepted format.

src/cognition/emergent/ForgeToolMetaTool.ts

SkillExporter.tsConfine both skill-writing APIs to validated tool folders +19/-5

Confine both skill-writing APIs to validated tool folders

• Both exporters resolve and validate the tool folder before creating it or writing files. Returned paths are absolute, including when outputDir is relative.

src/cognition/emergent/SkillExporter.ts

ToolName.tsDefine forged-name validation and safe folder resolution +106/-0

Define forged-name validation and safe folder resolution

• Adds the shared identifier pattern, forge-name validation, InvalidToolNameError, and a resolver that checks names and output-folder containment.

src/cognition/emergent/ToolName.ts

MarkdownExporter.tsRefuse special files and detect trace-file aliases +150/-41

Refuse special files and detect trace-file aliases

• Opens trace files without blocking where supported, rejects non-regular files, and uses case-folded paths plus device/inode claims to detect collisions. Processes writes in batches of at most 64 open files and reports other I/O failures after trying the remaining traces.

src/cognition/memory/io/MarkdownExporter.ts

types.tsAdd special to trace-export refusal reasons +10/-6

Add special to trace-export refusal reasons

• Extends RefusedExportTrace.problem with special and documents non-regular-file and alias collision behavior.

src/cognition/memory/io/facade/types.ts

Refactor (3) +27 / -19
EmergentAgentForge.tsShare the identifier pattern with agent roles +5/-5

Share the identifier pattern with agent roles

• Replaces the local role-name expression with the shared identifier constant while preserving the role validation rule.

src/cognition/emergent/EmergentAgentForge.ts

WikiPageId.tsReuse shared refused-name formatting for wiki ids +2/-10

Reuse shared refused-name formatting for wiki ids

• Replaces the local refused-id formatter with the shared helper, preserving the wiki error's escaped, truncated value.

src/cognition/substrate/memory/wiki/WikiPageId.ts

pathName.tsShare refused-name formatting across path consumers +20/-4

Share refused-name formatting across path consumers

• Adds describeRefusedName for consistent, bounded error messages and documents skill export as another consumer of the shared path rules.

src/core/utils/pathName.ts

Tests (4) +440 / -4
souledAgent.test.tsAssert second-start wiki indexing skips existing pages +17/-3

Assert second-start wiki indexing skips existing pages

• Inspects the boot index result on the second start and verifies all five object-member-named pages are skipped without being indexed or removed.

src/api/tests/souledAgent.test.ts

skill-export-paths.integration.test.tsExercise forge and skill-export path boundaries +149/-0

Exercise forge and skill-export path boundaries

• Uses a real orchestrator and engine to verify early refusals, successful exports, and rejection of an unsafe name loaded from storage without writing outside the skills folder.

src/cognition/emergent/tests/skill-export-paths.integration.test.ts

tool-name.test.tsCover tool-name rules on POSIX and Windows paths +116/-0

Cover tool-name rules on POSIX and Windows paths

• Tests accepted and refused names, typed problems, containment checks under both path implementations, and escaped error messages.

src/cognition/emergent/tests/tool-name.test.ts

exportTracePaths.integration.test.tsTest memory-export collision and special-file handling +158/-1

Test memory-export collision and special-file handling

• Covers Unicode folds, simulated file aliases within and across batches, folders and named pipes, and subclass paths outside the export folder.

src/cognition/memory/io/tests/exportTracePaths.integration.test.ts

Documentation (4) +7 / -4
MEMORY_OPERATIONS.mdDocument special-file refusals and trace collisions +1/-1

Document special-file refusals and trace collisions

• Explains how Markdown and Obsidian exports refuse non-regular files and file-system aliases, including Unicode case folds. Documents delayed rejection for other I/O failures.

docs/MEMORY_OPERATIONS.md

SELF_EXTENSION.mdDocument forged tool name requirements +1/-1

Document forged tool name requirements

• States the ASCII identifier and length requirements and the error returned for a refused forge-tool name.

docs/SELF_EXTENSION.md

EMERGENT_CAPABILITIES.mdExplain skill-export folder validation +2/-0

Explain skill-export folder validation

• Describes the forge and exporter validation rules, output-folder containment, and typed refusal for unsafe names.

docs/architecture/EMERGENT_CAPABILITIES.md

Memory.tsClarify memory-export refusal behavior +3/-2

Clarify memory-export refusal behavior

• Updates the export API documentation to include non-regular files and file-system-detected collisions.

src/cognition/memory/io/facade/Memory.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Distinct traces disappear from exports ✓ Resolved
Description
caseFoldKey folds some distinct filenames to the same key, so the export refuses the later trace
before opening either file. For example, valid trace IDs ß and ss name separate files on a
case-sensitive filesystem, but the new upper-then-lower conversion treats them as a collision in
both Markdown and Obsidian exports.
Code

src/cognition/memory/io/MarkdownExporter.ts[R388-390]

+function caseFoldKey(place: string): string {
+  return place.normalize('NFC').toLowerCase().toUpperCase().toLowerCase().normalize('NFC');
+}
Evidence
The placement loop refuses repeated keys before opening files; the new key folds ß and ss
together, although the shared name rule accepts both. Obsidian inherits this export loop.

src/cognition/memory/io/MarkdownExporter.ts[173-180]
src/cognition/memory/io/MarkdownExporter.ts[379-390]
src/core/utils/pathName.ts[75-93]
src/cognition/memory/io/ObsidianExporter.ts[57-90]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new case-fold key can classify distinct, valid filenames as collisions before the exporter opens them.
## Fix Focus Areas
- src/cognition/memory/io/MarkdownExporter.ts[173-180]
- src/cognition/memory/io/MarkdownExporter.ts[210-243]
- src/cognition/memory/io/MarkdownExporter.ts[388-390]
## Recommended Fix
Allow names that match only through an overbroad fold to reach the open-file identity check. Refuse a collision when the opened files actually resolve to the same file, while retaining an appropriate fallback where file identity is unavailable.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Exports can hide file-close failures ✓ Resolved
Description
The batched cleanup calls Promise.allSettled on every file close but discards rejected results.
When a handle's close() rejects after writing, no failure is recorded, so the Markdown or Obsidian
export can report success instead of propagating the error as the previous directly awaited close
did.
Code

src/cognition/memory/io/MarkdownExporter.ts[R247-249]

+      } finally {
+        await Promise.allSettled(handles.map((handle) => handle.close()));
+      }
Evidence
The new cleanup ignores all close settlements, while the final throw considers only errors recorded
during opens and writes. The public memory facade returns the exporter's result directly.

src/cognition/memory/io/MarkdownExporter.ts[212-253]
src/cognition/memory/io/facade/Memory.ts[1310-1317]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new cleanup waits for all file closes but ignores close failures, allowing an export to succeed despite a failed close.
## Fix Focus Areas
- src/cognition/memory/io/MarkdownExporter.ts[244-253]
## Recommended Fix
Inspect the close settlement results and record the first rejection in `failure`, while still attempting every close and continuing the remaining batches. Reject the export after all traces have been tried.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Skill export still writes through a planted link ✓ Resolved
Description
resolveToolFolder checks only that the folder path, as written, sits inside outputDir
(resolveInsideFolder compares resolved strings and follows no link). After that, writeSkillFile
and exportToolAsSkillPack call fs.mkdir and write SKILL.md/CAPABILITY.yaml through whatever
is already at /. If a symbolic link sits at that folder or at either file, the overwrite lands
outside the skills folder, which the Markdown exporter in this same PR explicitly prevents.
Code

src/cognition/emergent/SkillExporter.ts[R394-395]

+  const skillDir = resolveToolFolder(outputDir, tool.name);
await fs.mkdir(skillDir, { recursive: true });
Evidence
The docstring of resolveInsideFolder says 'The check is on the path as written: a link inside the
folder is not followed.' resolveToolFolder returns that lexical result, and the exporters then
mkdir and write files with plain fs calls, with no lstat or O_NOFOLLOW. The PR description,
though, says skill exports 'write only inside their folder'.

src/core/utils/pathName.ts[95-116]
src/cognition/emergent/ToolName.ts[95-106]
src/cognition/emergent/SkillExporter.ts[351-400]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The skill exporters check the tool folder only by its path string, then write SKILL.md and CAPABILITY.yaml through any symbolic link already at `<outputDir>/<name>` or at those files. The write can then land outside the output folder.
## Fix Focus Areas
- src/cognition/emergent/SkillExporter.ts[351-400]
- src/cognition/emergent/ToolName.ts[95-106]
## Recommended Fix
After `fs.mkdir`, lstat the tool folder and refuse it if it is a symbolic link, using `InvalidToolNameError('outside')` or a link-specific error. Open each file with `O_WRONLY|O_CREAT|O_NOFOLLOW` where the platform has the flag, and check `nlink === 1` before truncating, as `openTraceFile` in MarkdownExporter does. Otherwise, narrow the docs so they promise only a lexical check.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/cognition/emergent/SkillExporter.ts Resolved
…se file does not close, and write a skill's files through no link below its folder
@jddunn

jddunn commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: d681264397

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jddunn
jddunn merged commit ff8e6c5 into master Oct 12, 2026
10 checks passed
@jddunn
jddunn deleted the fix/skill-exporter-path branch October 12, 2026 14:41
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
## [0.13.66](v0.13.65...v0.13.66) (2026-10-12)

### fix

* **emergent:** forged tool names are held to the name rule and skill exports write only inside their folder, and export follow-ups from the cold read of #332 (#338) ([ff8e6c5](ff8e6c5))

### docs

* name the late calls charged to a later turn on the GMI study page (#339) ([b2957fa](b2957fa))
jddunn added a commit that referenced this pull request Oct 13, 2026
… agent workspace folders stay inside the base folder, and follow-ups from the cold read of #338 (#392)
github-actions Bot pushed a commit that referenced this pull request Oct 13, 2026
## [0.13.92](v0.13.91...v0.13.92) (2026-10-13)

### fix

* **discovery:** a capability's files are read only inside its folder, agent workspace folders stay inside the base folder, and follow-ups from the cold read of #338 (#392) ([5c6539b](5c6539b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant