`tcm add` imports what the code uses and doesn't import, as `tcm patch` does: a default import the codebase's code makes (`os`), and a name a module the code imports from already exports (`join`, from `node:path`), though the codebase has a page by that name.
Removing a method from a class (`Store`) and its use in another (`Codebase`) in one scratch file, when what the file imports is typed with the first (an interface of what's needed, a function taking it): those are re-derived against the new class and saved with the file, rather than the file checked against them as they were (its `Codebase` no longer their old `Core`).
`tcm check` imports what a scratch file uses and doesn't import, as saving it would, and writes them into it: a codebase name, a name a module it imports from already exports (`join`), an alias the codebase's code imports by (`path_basename`), a Node builtin (`randomUUID`). An import nothing uses it leaves (code using it may be still to be written), saying saving takes it out.
A change that puts a scratch file's definition in a cycle brings the cycle's other members along, written as they're stored (`withCycle`); a function's or class's name is part of its hash, so it isn't saved if one of them would have to be written with another name: two functions called `find` from two namespaces (one would be `find_1`), or a `find` the file itself declares. Nothing is saved then, and saying so names which and why, not the checker's errors of a file declaring `find` twice.
A constant added to a scratch file (`tcm edit`) whose code uses it, as its value: written before what uses it, so the file typechecks, and the file's import of it goes.
A function's or class's name is part of its hash: `tcm edit` won't write two declared alike in one file (one would have to be renamed, and so be another definition), nor add one to a file declaring its name; and a scratch file declaring one as `find_1` where the codebase has `find` isn't saved.
Definitions edited in one scratch file are each saved as they read alone: an import the file had to number (`join_1`, as another is `join`) is stored as `join`; one added to a file that means something else by a name is written with another (`limit_1`), not taken to mean the file's.
An import from outside the codebase renamed in a scratch file (`join_1`, as an older tcm stored it from a file that had another `join`, made `join`) is saved as the text it is, as a comment changed is: the definition reads so, its hash the same.
A scratch file whose constant uses one it imports, which uses a type the file changes: the import is re-derived against the new type and saved with it, though written after what uses it (rather than refused as "used before its declaration"); and a type error in the file's own code is said as one, not as something it imports that can't be saved with it.
What needs fixing is what's broken now: a change a dependent can't follow leaves it to fix, and going back to before the change (`tcm reset`) leaves nothing, though the record of it stays.
`tcm patch` adds imports it's given (`--imports`, or `imports` in `--patches`), for names importing what the code uses can't find: an alias, say. They're shown with the change, and go if the code doesn't use them; a file kept as written has none to add to.
Where `tcm patch` says a problem is (the checker's error, the line nearest an edit it can't find), it's the line as `tcm view` numbers the definition, the edits made: with imports above it, a doc, its first line edited, an import it added, or (`--patches`) written with definitions from another namespace, which puts a `// tcm: path` line among its own.
`tcm patch --patches` of a constant and another whose value uses it, the user given first: written in the order that typechecks, rather than refused as "used before its declaration".
`tcm patch --patches` of definitions that, written together, read with another name (`session_1`: another has a local `session`, so the constant they use is given another): what an edit writes takes it only where it's the name, declared or referred to, not where the word is in a comment, a string, a regular expression, a template or a property's name; a shorthand keeps its key, and is saved as one.
Inside a template literal, `tcm patch` takes an `old` with its escapes taken the other way (a line break for the source's `\n`, a bare backtick for its `` \` ``, as JSON makes easy to write) when that finds it once, writes `new` the same way, and says so; a `new` that would end or split the literal (a bare backtick or `${`) changes nothing, and says which and how to escape it.
Saving a scratch file takes out the imports nothing in it uses, as `tcm patch` does: one the code stopped using, and one of a name the codebase doesn't have any more (which would stop it typechecking). What a comment's `{@link}` names stays.
Code that doesn't parse is said by its first syntax error alone, with the lines around it: no type errors that follow from reading it wrong, no imports worked out from it. By `tcm patch` (where the definition's view has it), `tcm check` and `tcm update`.
A definition in todo is edited against what replaced the versions it used, imported by name, even where that's a version from before (a change undone: `Ctx` given `jobs`, then not, so `Tool` hashes as it first did): `tcm edit` and `tcm patch` say so, and a scratch file in a directory of its own (a session's) checks. A version imported by its hash from a module that isn't there is said plainly, without what follows from it.