@mcoda/codali 0.1.135-codali.4 → 0.1.135-codali.7

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 (39) hide show
  1. package/ORCHESTRATION.md +8 -0
  2. package/README.md +10 -1
  3. package/config/terminal-long-scenarios.v1.json +3 -2
  4. package/dist/cli/TerminalCommand.d.ts.map +1 -1
  5. package/dist/cli/TerminalCommand.js +4 -2
  6. package/dist/eval/TerminalWorkflowCorpus.d.ts +1 -1
  7. package/dist/eval/TerminalWorkflowCorpus.js +2 -2
  8. package/dist/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
  9. package/dist/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
  10. package/dist/eval/fixtures/MixedMediaRecoveryJourney.js +141 -0
  11. package/dist/providers/ConfiguredModelScope.d.ts +1 -0
  12. package/dist/providers/ConfiguredModelScope.d.ts.map +1 -1
  13. package/dist/providers/ConfiguredModelScope.js +4 -0
  14. package/dist/providers/ConfiguredProvider.d.ts +2 -0
  15. package/dist/providers/ConfiguredProvider.d.ts.map +1 -1
  16. package/dist/providers/ConfiguredProvider.js +16 -3
  17. package/dist/providers/ProviderTypes.d.ts +2 -0
  18. package/dist/providers/ProviderTypes.d.ts.map +1 -1
  19. package/dist/providers/RequestUsage.d.ts +11 -0
  20. package/dist/providers/RequestUsage.d.ts.map +1 -0
  21. package/dist/providers/RequestUsage.js +33 -0
  22. package/dist/runtime/ReviewSource.d.ts +3 -0
  23. package/dist/runtime/ReviewSource.d.ts.map +1 -1
  24. package/dist/runtime/ReviewSource.js +17 -1
  25. package/dist/runtime/SessionController.d.ts +2 -0
  26. package/dist/runtime/SessionController.d.ts.map +1 -1
  27. package/dist/runtime/SessionController.js +138 -24
  28. package/dist/runtime/TaskReview.d.ts +23 -0
  29. package/dist/runtime/TaskReview.d.ts.map +1 -0
  30. package/dist/runtime/TaskReview.js +66 -0
  31. package/dist/runtime/UsageReconciliation.d.ts +28 -0
  32. package/dist/runtime/UsageReconciliation.d.ts.map +1 -0
  33. package/dist/runtime/UsageReconciliation.js +68 -0
  34. package/dist/runtime/VerificationReceiptSelection.d.ts +15 -0
  35. package/dist/runtime/VerificationReceiptSelection.d.ts.map +1 -0
  36. package/dist/runtime/VerificationReceiptSelection.js +30 -0
  37. package/dist/session/SessionStoragePath.d.ts.map +1 -1
  38. package/dist/session/SessionStoragePath.js +28 -16
  39. package/package.json +3 -3
@@ -2,15 +2,23 @@ import { constants, promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  /** Existing state files must not alias another file or an external endpoint. */
4
4
  export async function assertRegularStateFile(file) {
5
- try {
6
- const stat = await fs.lstat(file);
7
- if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1)
8
- throw new Error(`Unsafe session state file: ${path.basename(file)}`);
9
- }
10
- catch (error) {
11
- if (error.code !== "ENOENT")
5
+ for (let attempt = 0; attempt < 8; attempt++) {
6
+ try {
7
+ const stat = await fs.lstat(file);
8
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink > 1)
9
+ throw new Error(`Unsafe session state file: ${path.basename(file)}`);
10
+ if (stat.nlink === 1)
11
+ return;
12
+ // An atomic rename may unlink the old inode while the asynchronous stat
13
+ // is completing. Validate the new named file; never accept the old one.
14
+ }
15
+ catch (error) {
16
+ if (error.code === "ENOENT")
17
+ return;
12
18
  throw error;
19
+ }
13
20
  }
21
+ throw new Error(`Session state file changed during validation: ${path.basename(file)}`);
14
22
  }
15
23
  /** Resolve trusted outer aliases (e.g. macOS /var) once, then reject symlinks
16
24
  * beneath the storage boundary. The terminal sandbox prevents model processes
@@ -76,14 +84,18 @@ export async function sessionStoragePath(options) {
76
84
  return resolved;
77
85
  }
78
86
  export async function readStateFile(file) {
79
- const handle = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW);
80
- try {
81
- const stat = await handle.stat();
82
- if (!stat.isFile() || stat.nlink !== 1)
83
- throw new Error("Unsafe session state file");
84
- return await handle.readFile("utf8");
85
- }
86
- finally {
87
- await handle.close();
87
+ for (let attempt = 0; attempt < 8; attempt++) {
88
+ const handle = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW);
89
+ try {
90
+ const stat = await handle.stat();
91
+ if (!stat.isFile() || stat.nlink > 1)
92
+ throw new Error("Unsafe session state file");
93
+ if (stat.nlink === 1)
94
+ return await handle.readFile("utf8");
95
+ }
96
+ finally {
97
+ await handle.close();
98
+ }
88
99
  }
100
+ throw new Error(`Session state file changed during validation: ${path.basename(file)}`);
89
101
  }
package/package.json CHANGED
@@ -8,8 +8,8 @@
8
8
  "url": "https://github.com/bekirdag/mcoda/issues"
9
9
  },
10
10
  "dependencies": {
11
- "@mcoda/db": "0.1.135-codali.4",
12
- "@mcoda/shared": "0.1.135-codali.4",
11
+ "@mcoda/db": "0.1.135-codali.7",
12
+ "@mcoda/shared": "0.1.135-codali.7",
13
13
  "@modelcontextprotocol/sdk": "1.30.0",
14
14
  "zod": "4.5.2"
15
15
  },
@@ -45,5 +45,5 @@
45
45
  },
46
46
  "type": "module",
47
47
  "types": "dist/index.d.ts",
48
- "version": "0.1.135-codali.4"
48
+ "version": "0.1.135-codali.7"
49
49
  }