@turri-dev/core 0.1.1-next.35d4c49 → 0.1.1-next.ad4aa8f

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.
Files changed (163) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +17 -11
  3. package/dist/api/models.d.ts +9 -0
  4. package/dist/api/models.js +15 -0
  5. package/dist/api/plain.d.ts +6 -6
  6. package/dist/api/plain.js +4 -7
  7. package/dist/api/project.d.ts +35 -0
  8. package/dist/api/project.js +47 -0
  9. package/dist/api/session.d.ts +48 -0
  10. package/dist/api/session.js +17 -0
  11. package/dist/api/system.d.ts +18 -0
  12. package/dist/api/system.js +23 -0
  13. package/dist/btw.d.ts +1 -1
  14. package/dist/capture/capture.js +11 -8
  15. package/dist/capture/chat.d.ts +0 -11
  16. package/dist/capture/chat.js +0 -29
  17. package/dist/capture/config.d.ts +4 -5
  18. package/dist/capture/config.js +34 -20
  19. package/dist/capture/models.d.ts +2 -1
  20. package/dist/capture/models.js +1 -0
  21. package/dist/chat-entries.d.ts +81 -39
  22. package/dist/chat-entries.js +125 -11
  23. package/dist/chat-model.d.ts +37 -0
  24. package/dist/chat-model.js +61 -0
  25. package/dist/chats.d.ts +54 -42
  26. package/dist/chats.js +86 -80
  27. package/dist/client.d.ts +30 -0
  28. package/dist/client.js +12 -0
  29. package/dist/config-edit.d.ts +54 -1
  30. package/dist/config-edit.js +103 -33
  31. package/dist/config.d.ts +12 -9
  32. package/dist/config.js +38 -9
  33. package/dist/doctor-checks.d.ts +42 -0
  34. package/dist/doctor-checks.js +39 -0
  35. package/dist/environment.d.ts +2 -23
  36. package/dist/environment.js +5 -68
  37. package/dist/errors.d.ts +32 -0
  38. package/dist/errors.js +24 -0
  39. package/dist/extension.d.ts +23 -16
  40. package/dist/extension.js +170 -234
  41. package/dist/identity.d.ts +1 -1
  42. package/dist/identity.js +13 -9
  43. package/dist/init-config.d.ts +11 -9
  44. package/dist/init-config.js +15 -7
  45. package/dist/launch-session.d.ts +2 -0
  46. package/dist/launch-session.js +17 -1
  47. package/dist/loop-tools.js +11 -10
  48. package/dist/module-check.d.ts +13 -0
  49. package/dist/module-check.js +117 -0
  50. package/dist/notice.d.ts +5 -0
  51. package/dist/parse-tool.js +3 -2
  52. package/dist/plain/check.d.ts +27 -13
  53. package/dist/plain/check.js +51 -116
  54. package/dist/plain/files.d.ts +2 -0
  55. package/dist/plain/files.js +13 -0
  56. package/dist/plain/graph.js +2 -2
  57. package/dist/plain/highlight.d.ts +4 -20
  58. package/dist/plain/highlight.js +7 -5
  59. package/dist/project.d.ts +19 -0
  60. package/dist/project.js +34 -0
  61. package/dist/quiet.d.ts +0 -2
  62. package/dist/quiet.js +0 -14
  63. package/dist/regenerate/command-check.d.ts +0 -8
  64. package/dist/regenerate/command-check.js +133 -53
  65. package/dist/regenerate/conversation-writes.d.ts +5 -1
  66. package/dist/regenerate/conversation-writes.js +7 -3
  67. package/dist/regenerate/jobs.d.ts +25 -2
  68. package/dist/regenerate/jobs.js +3 -0
  69. package/dist/regenerate/launch.d.ts +1 -0
  70. package/dist/regenerate/launch.js +9 -0
  71. package/dist/regenerate/ledger-view.d.ts +14 -14
  72. package/dist/regenerate/ledger.d.ts +1 -0
  73. package/dist/regenerate/ledger.js +4 -2
  74. package/dist/regenerate/loop.d.ts +2 -1
  75. package/dist/regenerate/loop.js +9 -1
  76. package/dist/regenerate/os-sandbox.d.ts +4 -2
  77. package/dist/regenerate/os-sandbox.js +0 -1
  78. package/dist/regenerate/regenerate.js +2 -1
  79. package/dist/regenerate/requires-chain.d.ts +44 -0
  80. package/dist/regenerate/requires-chain.js +174 -0
  81. package/dist/regenerate/requires.d.ts +2 -40
  82. package/dist/regenerate/requires.js +14 -171
  83. package/dist/regenerate/resources.d.ts +0 -2
  84. package/dist/regenerate/resources.js +2 -14
  85. package/dist/regenerate/shell.js +20 -9
  86. package/dist/regenerate/spec-map.d.ts +2 -0
  87. package/dist/regenerate/spec-map.js +4 -0
  88. package/dist/regenerate/standing.d.ts +5 -2
  89. package/dist/run-report.js +2 -2
  90. package/dist/self-invocation.d.ts +1 -1
  91. package/dist/self-invocation.js +2 -3
  92. package/dist/sentinel-chat.js +7 -11
  93. package/dist/sentinel.d.ts +1 -1
  94. package/dist/sentinel.js +12 -5
  95. package/dist/session-events.d.ts +14 -0
  96. package/dist/session.d.ts +594 -0
  97. package/dist/session.js +672 -0
  98. package/dist/settings.d.ts +28 -2
  99. package/dist/settings.js +92 -56
  100. package/dist/setup.d.ts +6 -30
  101. package/dist/setup.js +28 -105
  102. package/dist/stack.d.ts +25 -12
  103. package/dist/stack.js +77 -12
  104. package/dist/surface.d.ts +2 -2
  105. package/dist/surface.js +4 -5
  106. package/dist/work.d.ts +125 -0
  107. package/dist/work.js +250 -0
  108. package/docs/README.md +2 -3
  109. package/docs/capture.md +4 -4
  110. package/docs/chats.md +5 -3
  111. package/docs/claude-subscription.md +2 -2
  112. package/docs/config.md +4 -4
  113. package/docs/core.md +105 -128
  114. package/docs/development.md +9 -9
  115. package/docs/headless.md +1 -1
  116. package/docs/installation.md +4 -2
  117. package/docs/launch.md +2 -2
  118. package/docs/parser.md +1 -1
  119. package/docs/regenerating.md +1 -1
  120. package/docs/sandbox.md +4 -4
  121. package/docs/sentinel.md +4 -4
  122. package/docs/skills-and-gates.md +1 -1
  123. package/docs/using.md +2 -2
  124. package/genome/rules/integration-embedded-testing.md +3 -3
  125. package/genome/rules/integration-embedded.md +3 -3
  126. package/genome/skills/implement-conformance-testing-script/SKILL.md +6 -4
  127. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +13 -11
  128. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +8 -7
  129. package/genome/skills/implement-unit-testing-script/SKILL.md +7 -5
  130. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +9 -13
  131. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +1 -1
  132. package/package.json +19 -32
  133. package/dist/api/commands.d.ts +0 -45
  134. package/dist/api/commands.js +0 -54
  135. package/dist/api/config.d.ts +0 -8
  136. package/dist/api/config.js +0 -8
  137. package/dist/api/ledger.d.ts +0 -3
  138. package/dist/api/ledger.js +0 -3
  139. package/dist/api/startup.d.ts +0 -8
  140. package/dist/api/startup.js +0 -8
  141. package/dist/api/terminal.d.ts +0 -18
  142. package/dist/api/terminal.js +0 -16
  143. package/dist/chat-models.d.ts +0 -11
  144. package/dist/chat-models.js +0 -11
  145. package/dist/chat-ui.d.ts +0 -33
  146. package/dist/chat-ui.js +0 -192
  147. package/dist/headless.d.ts +0 -99
  148. package/dist/headless.js +0 -226
  149. package/dist/host-session.d.ts +0 -136
  150. package/dist/host-session.js +0 -139
  151. package/dist/host.d.ts +0 -8
  152. package/dist/host.js +0 -17
  153. package/dist/index.d.ts +0 -16
  154. package/dist/index.js +0 -7
  155. package/dist/notifications.d.ts +0 -21
  156. package/dist/notifications.js +0 -44
  157. package/dist/reopen.d.ts +0 -29
  158. package/dist/reopen.js +0 -47
  159. package/dist/turri-versions.d.ts +0 -71
  160. package/dist/turri-versions.js +0 -276
  161. package/dist/view.d.ts +0 -78
  162. package/dist/view.js +0 -1
  163. package/docs/hosting.md +0 -284
@@ -0,0 +1,174 @@
1
+ import { readFileSync, existsSync, readdirSync } from "node:fs";
2
+ import { basename, dirname, join, resolve } from "node:path";
3
+ import { IMPORT_DIRECTIVE, PLAIN_SOURCE_FILE_EXTENSION, plainFileParser, readPlainSourceMetadata, REQUIRES_DIRECTIVE, withParseCache } from "../plain/parser.js";
4
+ import { getFrids } from "../plain/spec.js";
5
+ import { buildDirUnder, modulesRoot, projectDirOf, resolveTemplateDirs } from "./paths.js";
6
+ /** A required module's file: the first template folder that has it. */
7
+ export function locateModule(moduleName, templateDirs) {
8
+ for (const dir of templateDirs) {
9
+ const candidate = join(dir, moduleName + PLAIN_SOURCE_FILE_EXTENSION);
10
+ if (existsSync(candidate))
11
+ return candidate;
12
+ }
13
+ throw new Error(`Required module '${moduleName}' not found in: ${templateDirs.join(", ")}`);
14
+ }
15
+ /**
16
+ * The chain to build, bottom first.
17
+ *
18
+ * Depth-first, post-order: everything a module requires is listed before the module
19
+ * itself. The parser has already rejected circular requires, and a module reached twice is
20
+ * emitted once.
21
+ */
22
+ export function resolveRequiresChain(plainFile, templateDirs = [], buildRoot,
23
+ /** Accept the named module without functional specs yet. Those it requires must have them. */
24
+ options = {}) {
25
+ const dirs = resolveTemplateDirs(plainFile, templateDirs);
26
+ const root = resolve(buildRoot ?? modulesRoot(projectDirOf(plainFile)));
27
+ const chain = [];
28
+ const seen = new Set();
29
+ const visit = (file, requiredBy) => {
30
+ const [moduleName, tree, requires] = plainFileParser(basename(file), dirs, requiredBy.length === 0 ? options : {});
31
+ if (requiredBy.includes(moduleName)) {
32
+ throw new Error(`Circular requires: ${[...requiredBy, moduleName].join(" -> ")}`);
33
+ }
34
+ if (seen.has(moduleName))
35
+ return moduleName;
36
+ let previous = null;
37
+ for (const required of requires) {
38
+ previous = visit(locateModule(required, dirs), [...requiredBy, moduleName]);
39
+ }
40
+ seen.add(moduleName);
41
+ chain.push({
42
+ moduleName,
43
+ plainFile: resolve(file),
44
+ buildDir: buildDirUnder(root, moduleName),
45
+ requires: previous,
46
+ funcIds: [...getFrids(tree)],
47
+ });
48
+ return moduleName;
49
+ };
50
+ visit(resolve(plainFile), []);
51
+ return chain;
52
+ }
53
+ /** Every .plain file in a project's folder, sorted - the modules a host lists. */
54
+ export function projectPlainFiles(projectDir) {
55
+ const root = resolve(projectDir);
56
+ try {
57
+ return readdirSync(root, { withFileTypes: true })
58
+ .filter((entry) => entry.isFile() && entry.name.endsWith(PLAIN_SOURCE_FILE_EXTENSION))
59
+ .map((entry) => join(root, entry.name))
60
+ .sort();
61
+ }
62
+ catch {
63
+ return [];
64
+ }
65
+ }
66
+ /**
67
+ * A project's .plain files in the order they are built: each after every module it requires, as its requires chain has
68
+ * them (`resolveRequiresChain`) - taken in the order given, by name without `files`, each brought in after what it
69
+ * requires. A module whose chain does not resolve - it does not parse, a module it requires is not there, a cycle - goes
70
+ * after what its front matter says it requires, as far as those are found. `files`, absolute or from the project: the
71
+ * ones to order, every other module of a chain left out; without it, every .plain file in the project's folder.
72
+ */
73
+ export function requiresOrder(projectDir, options = {}) {
74
+ const root = resolve(projectDir);
75
+ const files = (options.files ?? projectPlainFiles(root)).map((file) => resolve(root, file));
76
+ const wanted = new Set(files);
77
+ const order = [];
78
+ const placed = new Set();
79
+ const add = (file) => {
80
+ if (placed.has(file))
81
+ return;
82
+ placed.add(file);
83
+ if (wanted.has(file))
84
+ order.push(file);
85
+ };
86
+ const visiting = new Set();
87
+ const place = (file) => {
88
+ if (placed.has(file) || visiting.has(file))
89
+ return;
90
+ visiting.add(file);
91
+ try {
92
+ for (const entry of resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true }))
93
+ add(entry.plainFile);
94
+ }
95
+ catch {
96
+ let requires = [];
97
+ try {
98
+ requires = (readPlainSourceMetadata(readFileSync(file, "utf8")).metadata[REQUIRES_DIRECTIVE] ?? []).filter((name) => typeof name === "string");
99
+ }
100
+ catch {
101
+ // Not read: nothing to put it after.
102
+ }
103
+ const dirs = resolveTemplateDirs(file);
104
+ for (const name of requires) {
105
+ try {
106
+ place(resolve(locateModule(name, dirs)));
107
+ }
108
+ catch {
109
+ // Not there: nothing to put it after.
110
+ }
111
+ }
112
+ add(file);
113
+ }
114
+ visiting.delete(file);
115
+ };
116
+ withParseCache(() => {
117
+ for (const file of files)
118
+ place(file);
119
+ });
120
+ return order;
121
+ }
122
+ /** The .plain files that import `plainFile` - read from beside it, and, kept in a `template/` folder, from the folder it is in. */
123
+ function importersOf(plainFile) {
124
+ const file = resolve(plainFile);
125
+ const dir = dirname(file);
126
+ const name = basename(file, PLAIN_SOURCE_FILE_EXTENSION);
127
+ const dirs = [dir, ...(basename(dir) === "template" ? [dirname(dir)] : [])];
128
+ return dirs.flatMap((at) => {
129
+ let names;
130
+ try {
131
+ names = readdirSync(at).filter((entry) => entry.endsWith(PLAIN_SOURCE_FILE_EXTENSION));
132
+ }
133
+ catch {
134
+ return [];
135
+ }
136
+ return names
137
+ .map((entry) => join(at, entry))
138
+ .filter((path) => {
139
+ if (path === file || !resolveTemplateDirs(path).includes(dir))
140
+ return false;
141
+ try {
142
+ return (readPlainSourceMetadata(readFileSync(path, "utf8")).metadata[IMPORT_DIRECTIVE] ?? []).includes(name);
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ });
148
+ });
149
+ }
150
+ /**
151
+ * Whether a .plain file is an import module - one a .plain file imports, or one kept in a `template/` folder - rather than
152
+ * a module of its own. It is no codebase: its reqs and definitions are built in the modules that import it.
153
+ */
154
+ export function isImportModule(plainFile) {
155
+ return basename(dirname(resolve(plainFile))) === "template" || importersOf(plainFile).length > 0;
156
+ }
157
+ /** The modules of their own that import an import module, through any import modules between. */
158
+ export function importingModules(plainFile) {
159
+ const found = new Set();
160
+ const seen = new Set();
161
+ const walk = (file) => {
162
+ if (seen.has(file))
163
+ return;
164
+ seen.add(file);
165
+ for (const importer of importersOf(file)) {
166
+ if (isImportModule(importer))
167
+ walk(importer);
168
+ else
169
+ found.add(importer);
170
+ }
171
+ };
172
+ walk(resolve(plainFile));
173
+ return [...found];
174
+ }
@@ -1,4 +1,3 @@
1
- import { type ParseOptions } from "../plain/parser.ts";
2
1
  /**
3
2
  * `requires` chains.
4
3
  *
@@ -10,45 +9,8 @@ import { type ParseOptions } from "../plain/parser.ts";
10
9
  * What has already been built is not tracked here: each codebase's record says what it is built
11
10
  * from - see `records.ts`.
12
11
  */
13
- export interface ChainEntry {
14
- moduleName: string;
15
- plainFile: string;
16
- buildDir: string;
17
- /** The module whose code is copied in before this one is built. */
18
- requires: string | null;
19
- funcIds: string[];
20
- }
21
- /** A required module's file: the first template folder that has it. */
22
- export declare function locateModule(moduleName: string, templateDirs: string[]): string;
23
- /**
24
- * The chain to build, bottom first.
25
- *
26
- * Depth-first, post-order: everything a module requires is listed before the module
27
- * itself. The parser has already rejected circular requires, and a module reached twice is
28
- * emitted once.
29
- */
30
- export declare function resolveRequiresChain(plainFile: string, templateDirs?: string[], buildRoot?: string,
31
- /** Accept the named module without functional specs yet. Those it requires must have them. */
32
- options?: ParseOptions): ChainEntry[];
33
- /** Every .plain file in a project's folder, sorted - the modules a host lists. */
34
- export declare function projectPlainFiles(projectDir: string): string[];
35
- /**
36
- * A project's .plain files in the order they are built: each after every module it requires, as its requires chain has
37
- * them (`resolveRequiresChain`) - taken in the order given, by name without `files`, each brought in after what it
38
- * requires. A module whose chain does not resolve - it does not parse, a module it requires is not there, a cycle - goes
39
- * after what its front matter says it requires, as far as those are found. `files`, absolute or from the project: the
40
- * ones to order, every other module of a chain left out; without it, every .plain file in the project's folder.
41
- */
42
- export declare function requiresOrder(projectDir: string, options?: {
43
- files?: string[];
44
- }): string[];
45
- /**
46
- * Whether a .plain file is an import module - one a .plain file imports, or one kept in a `template/` folder - rather than
47
- * a module of its own. It is no codebase: its reqs and definitions are built in the modules that import it.
48
- */
49
- export declare function isImportModule(plainFile: string): boolean;
50
- /** The modules of their own that import an import module, through any import modules between. */
51
- export declare function importingModules(plainFile: string): string[];
12
+ import { type ChainEntry } from "./requires-chain.ts";
13
+ export { importingModules, isImportModule, locateModule, projectPlainFiles, requiresOrder, resolveRequiresChain, type ChainEntry } from "./requires-chain.ts";
52
14
  /**
53
15
  * The codebase a change to `plainFile`'s module lands in: the furthest-built module whose
54
16
  * requires chain includes it, with that chain.
@@ -1,183 +1,26 @@
1
- import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
2
- import { basename, dirname, join, resolve } from "node:path";
3
- import { IMPORT_DIRECTIVE, PLAIN_SOURCE_FILE_EXTENSION, plainFileParser, readPlainSourceMetadata, REQUIRES_DIRECTIVE, withParseCache } from "../plain/parser.js";
4
- import { getFrids, getInheritedFunctionalSpecs } from "../plain/spec.js";
5
- import { buildDirUnder, modulesRoot, projectDirOf } from "./paths.js";
1
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
+ import { basename, dirname, join } from "node:path";
3
+ import { PLAIN_SOURCE_FILE_EXTENSION, withParseCache } from "../plain/parser.js";
4
+ import { getInheritedFunctionalSpecs } from "../plain/spec.js";
6
5
  import { notesPath } from "./notes.js";
7
6
  import { resolveTemplateDirs } from "./paths.js";
8
7
  import { inheritedRecord, inheritedTestsRecord, readRecord, RECORD_FILE, writeCodeRecord, writeTestsRecord } from "./records.js";
9
8
  import { head, historyLog, recordHistory } from "./lineage.js";
10
9
  import { listFiles } from "./testing.js";
11
10
  import { carryBaseRecord } from "./base-folder.js";
12
- /** A required module's file: the first template folder that has it. */
13
- export function locateModule(moduleName, templateDirs) {
14
- for (const dir of templateDirs) {
15
- const candidate = join(dir, moduleName + PLAIN_SOURCE_FILE_EXTENSION);
16
- if (existsSync(candidate))
17
- return candidate;
18
- }
19
- throw new Error(`Required module '${moduleName}' not found in: ${templateDirs.join(", ")}`);
20
- }
21
11
  /**
22
- * The chain to build, bottom first.
12
+ * `requires` chains.
23
13
  *
24
- * Depth-first, post-order: everything a module requires is listed before the module
25
- * itself. The parser has already rejected circular requires, and a module reached twice is
26
- * emitted once.
27
- */
28
- export function resolveRequiresChain(plainFile, templateDirs = [], buildRoot,
29
- /** Accept the named module without functional specs yet. Those it requires must have them. */
30
- options = {}) {
31
- const dirs = resolveTemplateDirs(plainFile, templateDirs);
32
- const root = resolve(buildRoot ?? modulesRoot(projectDirOf(plainFile)));
33
- const chain = [];
34
- const seen = new Set();
35
- const visit = (file, requiredBy) => {
36
- const [moduleName, tree, requires] = plainFileParser(basename(file), dirs, requiredBy.length === 0 ? options : {});
37
- if (requiredBy.includes(moduleName)) {
38
- throw new Error(`Circular requires: ${[...requiredBy, moduleName].join(" -> ")}`);
39
- }
40
- if (seen.has(moduleName))
41
- return moduleName;
42
- let previous = null;
43
- for (const required of requires) {
44
- previous = visit(locateModule(required, dirs), [...requiredBy, moduleName]);
45
- }
46
- seen.add(moduleName);
47
- chain.push({
48
- moduleName,
49
- plainFile: resolve(file),
50
- buildDir: buildDirUnder(root, moduleName),
51
- requires: previous,
52
- funcIds: [...getFrids(tree)],
53
- });
54
- return moduleName;
55
- };
56
- visit(resolve(plainFile), []);
57
- return chain;
58
- }
59
- /** Every .plain file in a project's folder, sorted - the modules a host lists. */
60
- export function projectPlainFiles(projectDir) {
61
- const root = resolve(projectDir);
62
- try {
63
- return readdirSync(root, { withFileTypes: true })
64
- .filter((entry) => entry.isFile() && entry.name.endsWith(PLAIN_SOURCE_FILE_EXTENSION))
65
- .map((entry) => join(root, entry.name))
66
- .sort();
67
- }
68
- catch {
69
- return [];
70
- }
71
- }
72
- /**
73
- * A project's .plain files in the order they are built: each after every module it requires, as its requires chain has
74
- * them (`resolveRequiresChain`) - taken in the order given, by name without `files`, each brought in after what it
75
- * requires. A module whose chain does not resolve - it does not parse, a module it requires is not there, a cycle - goes
76
- * after what its front matter says it requires, as far as those are found. `files`, absolute or from the project: the
77
- * ones to order, every other module of a chain left out; without it, every .plain file in the project's folder.
78
- */
79
- export function requiresOrder(projectDir, options = {}) {
80
- const root = resolve(projectDir);
81
- const files = (options.files ?? projectPlainFiles(root)).map((file) => resolve(root, file));
82
- const wanted = new Set(files);
83
- const order = [];
84
- const placed = new Set();
85
- const add = (file) => {
86
- if (placed.has(file))
87
- return;
88
- placed.add(file);
89
- if (wanted.has(file))
90
- order.push(file);
91
- };
92
- const visiting = new Set();
93
- const place = (file) => {
94
- if (placed.has(file) || visiting.has(file))
95
- return;
96
- visiting.add(file);
97
- try {
98
- for (const entry of resolveRequiresChain(file, [], undefined, { allowNoFunctionalities: true }))
99
- add(entry.plainFile);
100
- }
101
- catch {
102
- let requires = [];
103
- try {
104
- requires = (readPlainSourceMetadata(readFileSync(file, "utf8")).metadata[REQUIRES_DIRECTIVE] ?? []).filter((name) => typeof name === "string");
105
- }
106
- catch {
107
- // Not read: nothing to put it after.
108
- }
109
- const dirs = resolveTemplateDirs(file);
110
- for (const name of requires) {
111
- try {
112
- place(resolve(locateModule(name, dirs)));
113
- }
114
- catch {
115
- // Not there: nothing to put it after.
116
- }
117
- }
118
- add(file);
119
- }
120
- visiting.delete(file);
121
- };
122
- withParseCache(() => {
123
- for (const file of files)
124
- place(file);
125
- });
126
- return order;
127
- }
128
- /** The .plain files that import `plainFile` - read from beside it, and, kept in a `template/` folder, from the folder it is in. */
129
- function importersOf(plainFile) {
130
- const file = resolve(plainFile);
131
- const dir = dirname(file);
132
- const name = basename(file, PLAIN_SOURCE_FILE_EXTENSION);
133
- const dirs = [dir, ...(basename(dir) === "template" ? [dirname(dir)] : [])];
134
- return dirs.flatMap((at) => {
135
- let names;
136
- try {
137
- names = readdirSync(at).filter((entry) => entry.endsWith(PLAIN_SOURCE_FILE_EXTENSION));
138
- }
139
- catch {
140
- return [];
141
- }
142
- return names
143
- .map((entry) => join(at, entry))
144
- .filter((path) => {
145
- if (path === file || !resolveTemplateDirs(path).includes(dir))
146
- return false;
147
- try {
148
- return (readPlainSourceMetadata(readFileSync(path, "utf8")).metadata[IMPORT_DIRECTIVE] ?? []).includes(name);
149
- }
150
- catch {
151
- return false;
152
- }
153
- });
154
- });
155
- }
156
- /**
157
- * Whether a .plain file is an import module - one a .plain file imports, or one kept in a `template/` folder - rather than
158
- * a module of its own. It is no codebase: its reqs and definitions are built in the modules that import it.
14
+ * A module that `requires` another is built on top of that module's code: the required
15
+ * module must be finished first, and its codebase is copied into the build before this
16
+ * module starts. So rendering a module means rendering its chain, bottom first, carrying
17
+ * the code forward at each step.
18
+ *
19
+ * What has already been built is not tracked here: each codebase's record says what it is built
20
+ * from - see `records.ts`.
159
21
  */
160
- export function isImportModule(plainFile) {
161
- return basename(dirname(resolve(plainFile))) === "template" || importersOf(plainFile).length > 0;
162
- }
163
- /** The modules of their own that import an import module, through any import modules between. */
164
- export function importingModules(plainFile) {
165
- const found = new Set();
166
- const seen = new Set();
167
- const walk = (file) => {
168
- if (seen.has(file))
169
- return;
170
- seen.add(file);
171
- for (const importer of importersOf(file)) {
172
- if (isImportModule(importer))
173
- walk(importer);
174
- else
175
- found.add(importer);
176
- }
177
- };
178
- walk(resolve(plainFile));
179
- return [...found];
180
- }
22
+ import { resolveRequiresChain } from "./requires-chain.js";
23
+ export { importingModules, isImportModule, locateModule, projectPlainFiles, requiresOrder, resolveRequiresChain } from "./requires-chain.js";
181
24
  /**
182
25
  * The codebase a change to `plainFile`'s module lands in: the furthest-built module whose
183
26
  * requires chain includes it, with that chain.
@@ -34,8 +34,6 @@ export declare class LinkedImageError extends Error {
34
34
  export declare function loadLinkedResources(tree: MarshalledPlainSource,
35
35
  /** Up to and including this functionality. Null: the whole module. */
36
36
  funcId: string | null, templateDirs: string[]): LoadedResource[];
37
- /** The file a linked resource is read from: the first template folder that has it, else the current folder - or null. */
38
- export declare function resourceFile(target: string, templateDirs: string[]): string | null;
39
37
  /**
40
38
  * A linked resource that is code - a source file, or a build manifest: the specification points at code that lives
41
39
  * elsewhere, a host's module the code plugs into, for the code to build on as it says. It is never copied into the
@@ -1,7 +1,8 @@
1
1
  import { copyFileSync, mkdirSync, readFileSync, statSync } from "node:fs";
2
- import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
2
+ import { dirname, extname, isAbsolute, relative, resolve } from "node:path";
3
3
  import { defineTool } from "@earendil-works/pi-coding-agent";
4
4
  import { Type } from "typebox";
5
+ import { resourceFile } from "../plain/files.js";
5
6
  import { collectLinkedResources } from "../plain/spec.js";
6
7
  import { scriptKind } from "./test-scripts.js";
7
8
  const MAX_RESOURCE_CHARS = 8000;
@@ -56,19 +57,6 @@ funcId, templateDirs) {
56
57
  }
57
58
  return loaded;
58
59
  }
59
- /** The file a linked resource is read from: the first template folder that has it, else the current folder - or null. */
60
- export function resourceFile(target, templateDirs) {
61
- const found = [...templateDirs.map((dir) => join(dir, target)), target].find((path) => isFileAt(path));
62
- return found === undefined ? null : resolve(found);
63
- }
64
- function isFileAt(path) {
65
- try {
66
- return statSync(path).isFile();
67
- }
68
- catch {
69
- return false;
70
- }
71
- }
72
60
  /** Source files, by extension: a linked resource that is one is code that lives elsewhere, never copied in. */
73
61
  const CODE_EXTENSIONS = new Set([
74
62
  ".py", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".java", ".kt", ".kts", ".scala", ".groovy", ".go", ".rs", ".rb",
@@ -59,6 +59,25 @@ function writeRecord() {
59
59
  // Only the watcher and the sweep read it; exit kills the groups all the same.
60
60
  }
61
61
  }
62
+ let exitHooked = false;
63
+ /**
64
+ * The groups killed as this process exits - once turri has started one, never as it is imported: a front end that
65
+ * imports the core and starts nothing keeps its process's own exit and signals as they were. A process ended by a signal
66
+ * never exits in the sense that runs an exit handler, so where nothing else handles the signal it is made to exit
67
+ * properly on it, as it would have.
68
+ */
69
+ function stopGroupsOnExit() {
70
+ if (exitHooked)
71
+ return;
72
+ exitHooked = true;
73
+ process.on("exit", killAllGroups);
74
+ for (const [signal, code] of [["SIGTERM", 143], ["SIGHUP", 129], ["SIGINT", 130]]) {
75
+ process.once(signal, () => {
76
+ if (process.listenerCount(signal) === 0)
77
+ process.exit(code);
78
+ });
79
+ }
80
+ }
62
81
  let watching = false;
63
82
  /**
64
83
  * A small shell beside this turri that waits for it to end, then kills every group it recorded - for a turri killed
@@ -84,6 +103,7 @@ function watch() {
84
103
  }
85
104
  }
86
105
  function track(group) {
106
+ stopGroupsOnExit();
87
107
  groups.add(group);
88
108
  pulse.getStore()?.groups.add(group);
89
109
  writeRecord();
@@ -309,12 +329,3 @@ export async function stopGroup(group, graceMs = 1000) {
309
329
  killGroup(group);
310
330
  forget(group);
311
331
  }
312
- process.on("exit", killAllGroups);
313
- // A process ended by a signal never exits in the sense that runs the handler above: where nothing else handles the
314
- // signal, exit properly on it.
315
- for (const [signal, code] of [["SIGTERM", 143], ["SIGHUP", 129], ["SIGINT", 130]]) {
316
- process.once(signal, () => {
317
- if (process.listenerCount(signal) === 0)
318
- process.exit(code);
319
- });
320
- }
@@ -157,6 +157,8 @@ export declare function createSpecMapSource(options: {
157
157
  read(): MarkedPage[];
158
158
  /** Read the files again on the next frame, whatever they look like. */
159
159
  refresh(): void;
160
+ /** Lay the pages over the plan again on the next read - the work moved - the files read again only if they changed. */
161
+ remark(): void;
160
162
  };
161
163
  /**
162
164
  * The module in focus: the one regenerating now, else the last the loop looks after - the module asked for, at the top of its
@@ -592,6 +592,10 @@ export function createSpecMapSource(options) {
592
592
  last = undefined;
593
593
  read = undefined;
594
594
  },
595
+ /** Lay the pages over the plan again on the next read - the work moved - the files read again only if they changed. */
596
+ remark() {
597
+ last = undefined;
598
+ },
595
599
  };
596
600
  }
597
601
  /**
@@ -1,4 +1,4 @@
1
- import { functionalityCompletion, type DriftReport, type WorkLoop } from "./loop.ts";
1
+ import { type DriftReport, type ModuleCompletion, type WorkLoop } from "./loop.ts";
2
2
  /**
3
3
  * How each module of a project stands, in one call: what `WorkLoop.drift` and `functionalityCompletion` say of it, each
4
4
  * as they say it alone. One look at the whole project: each file parsed once, each record read once, the modules below
@@ -12,7 +12,10 @@ export interface ModuleStanding {
12
12
  drift?: DriftReport[];
13
13
  driftError?: string;
14
14
  /** `functionalityCompletion(plainFile)`: its chain's functional specs completed, one entry per chain - undefined with `completionError`. */
15
- completion?: ReturnType<typeof functionalityCompletion>;
15
+ completion?: Array<{
16
+ codebase: string;
17
+ modules: ModuleCompletion[];
18
+ }>;
16
19
  completionError?: string;
17
20
  }
18
21
  export interface StandingOptions {
@@ -1,7 +1,7 @@
1
1
  import { mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { basename, dirname, join, relative, resolve } from "node:path";
3
3
  import { debugMode } from "./config.js";
4
- import { turriIdentity } from "./environment.js";
4
+ import { clientIdentity } from "./client.js";
5
5
  import { onModelEvent } from "./regenerate/activity.js";
6
6
  import { firstRegeneration } from "./regenerate/jobs.js";
7
7
  /**
@@ -88,7 +88,7 @@ export function writeAtomically(file, text) {
88
88
  export function startRunReport(options) {
89
89
  const file = resolve(options.file);
90
90
  const startedAt = Date.now();
91
- const identity = turriIdentity();
91
+ const identity = clientIdentity();
92
92
  const events = [];
93
93
  const stopListening = onModelEvent((event) => events.push(event));
94
94
  let sources = { jobs: () => [] };
@@ -21,7 +21,7 @@ export declare function selfInvocation(command: string): string | undefined;
21
21
  */
22
22
  export declare function askedForCommandLine(message: string): boolean;
23
23
  /** What the agent is told when the call is refused. */
24
- export declare function refusal(what: string, surface?: string): string;
24
+ export declare function refusal(what: string): string;
25
25
  /** The instruction that goes into the conversation's system prompt. */
26
26
  export declare const TOOLS_NOT_CLI: string;
27
27
  type AnyTool = ToolDefinition<any, any, any>;
@@ -87,13 +87,12 @@ export function askedForCommandLine(message) {
87
87
  /(^|\s)pi\s+-p\b/.test(text));
88
88
  }
89
89
  /** What the agent is told when the call is refused. */
90
- export function refusal(what, surface) {
90
+ export function refusal(what) {
91
91
  const instead = what === "pi"
92
92
  ? "Do not start another agent: do the work here, with this conversation's tools."
93
93
  : `Use ${TOOL_FOR[what] ?? "the matching turri tool"} instead.`;
94
94
  return (`Not run: that starts turri${what === "pi" ? "'s agent" : ` ${what}`} again from the shell - a separate, headless ` +
95
- // In a host there is no panel: the person watches the pulses where its surface says.
96
- (surface !== undefined ? "run outside this conversation and its pulses, where the person can neither watch it nor halt it. " : "run outside this conversation, its jobs, the panel and /halt. ") +
95
+ "run outside this conversation and its pulses, where the person can neither watch it nor halt it. " +
97
96
  `${instead} Run turri from the command line only when the user asks for that.`);
98
97
  }
99
98
  /** The instruction that goes into the conversation's system prompt. */
@@ -129,30 +129,28 @@ export function noticeDialogs(pi, session, link, context) {
129
129
  pi.on("agent_settled", () => void ask());
130
130
  return {
131
131
  put(notice) {
132
- if (session.terminal)
133
- return; // The terminal centre received it, including the question whether to start.
134
132
  try {
135
133
  appendChatEntry(pi, NOTICE_ENTRY, notice);
136
134
  }
137
135
  catch {
138
- /* the host still hears of it */
136
+ /* the front end still hears of it */
139
137
  }
140
- // A host answers it itself: its card, its buttons. A note of a fix the sentinel made asks nothing: its card alone.
141
- if (session.host.onNotice !== undefined || notice.kind === "fixed")
138
+ // A front end that shows notices puts them to the person itself: its card, its buttons. A note of a fix the sentinel
139
+ // made asks nothing: its card alone.
140
+ if (session.host.noticesShown === true || notice.kind === "fixed")
142
141
  return;
143
142
  waiting.push(notice);
144
143
  void ask();
145
144
  },
146
145
  concluded(conclusion) {
147
146
  try {
148
- if (!session.terminal)
149
- appendChatEntry(pi, CONCLUDED_ENTRY, conclusion);
147
+ appendChatEntry(pi, CONCLUDED_ENTRY, conclusion);
150
148
  }
151
149
  catch {
152
150
  /* the agent is still told */
153
151
  }
154
- // A host that shows the person the conclusion itself: the chat knows of it - in order, with no turn of its own.
155
- const shown = session.terminal || session.host.pulseEndsShown === true;
152
+ // A front end that shows the person the conclusion itself: the chat knows of it - in order, with no turn of its own.
153
+ const shown = session.host.pulseEndsShown === true;
156
154
  sendChatMessage(pi, {
157
155
  customType: "turri_sentinel_concluded",
158
156
  content: concludedNote(conclusion, { shown }),
@@ -161,8 +159,6 @@ export function noticeDialogs(pi, session, link, context) {
161
159
  }, shown ? { triggerTurn: false } : { triggerTurn: true, deliverAs: "followUp" });
162
160
  },
163
161
  over(notice) {
164
- if (session.terminal)
165
- return;
166
162
  asking.get(notice.id)?.abort();
167
163
  const at = waiting.indexOf(notice);
168
164
  if (at !== -1)
@@ -30,7 +30,7 @@ export declare function keepGuidance(cwd: string, text: string): void;
30
30
  * What a chat of the person's is told of the pulses that end: told itself, of those asked for in it - or, with the
31
31
  * sentinel on, nothing, the sentinel telling the person what needs them.
32
32
  */
33
- export declare function pulseEndsBlock(sentinel: boolean, terminal?: boolean): string;
33
+ export declare function pulseEndsBlock(sentinel: boolean, shown?: boolean): string;
34
34
  /**
35
35
  * What the chat the person is in is told of a pulse that landed, with the sentinel on: that it landed, what the sentinel
36
36
  * does with it - and to tell the person so, and do nothing else about it. `launching`: launch-after-pulse is on - it is