Skip to content

refactor(core): tighten pty, plugin, question, and snapshot types and checks - #57889

Merged
rekram1-node merged 2 commits into
devfrom
core-form-pty-plugin-snapshot
Oct 21, 2026
Merged

rekram1-node merged 2 commits into
devfrom
core-form-pty-plugin-snapshot

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Several core services (pty, plugin, question, and snapshot) carried redundant runtime checks, unnecessary mutable type wrappers, or duplicate path/ID branding on already-typed values.

Change

Tighten the domain types and runtime checks across those modules:

 packages/core/src/
 ├── tool/plugin/question.ts  # narrow Form.Value with Array.isArray instead of typeof === "object"
 ├── pty.ts                   # drop DeepMutable on read-only inputs and redundant typeof check
 ├── plugin.ts                # preserve branded Plugin.ID on Slot["plugin"] instead of re-branding
 └── snapshot.ts              # short-circuit empty file/diff lists and brand RelativePath once per diff
 Snapshot.files(input)
   changed = git.tree.files(...)
+  if changed is empty -> return []
   skipped = ignored(changed)
   return changed without skipped

 Snapshot.diff(input)
   diffs = git.tree.diff(...)
+  if diffs is empty -> return []
+  paths = diffs.map(d => RelativePath.make(d.file))
-  skipped = ignored(diffs.map(d => RelativePath.make(d.file)))
-  return diffs.filter(d => !skipped.has(RelativePath.make(d.file)))
+  skipped = ignored(paths)
+  return diffs.filter((_, i) => !skipped.has(paths[i]))

Out of scope

  • Changing Form.validateAnswer (isStringArray is retained to guard untrusted plugin answers at runtime).
  • Changing McpClient.ElicitationResult or TypeScript's Array.isArray narrowing behavior in the false branch of mcp/index.ts.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pty, plugin, snapshot and question changes are sound: type-check passes and the core tests for form, snapshot, plugin, question and pty pass. Public API unchanged.

One concern, inline: dropping isStringArray removes the check on multiselect items in Form.validateAnswer, which is the only runtime check on answers from plugins.

Comment thread packages/core/src/form.ts Resolved
@rekram1-node rekram1-node changed the title refactor(core): tighten form, pty, plugin, and snapshot types and checks refactor(core): tighten pty, plugin, question, and snapshot types and checks Oct 21, 2026
@rekram1-node
rekram1-node merged commit 2e5a4de into dev Oct 21, 2026
14 checks passed
@rekram1-node
rekram1-node deleted the core-form-pty-plugin-snapshot branch October 21, 2026 20:47
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