pi-harness-runtime 1.1.512 → 1.1.514

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 (225) hide show
  1. package/AGENTS.md +23 -0
  2. package/CHANGELOG.md +183 -0
  3. package/footer-status.ts +112 -43
  4. package/harness/cookie-import-refresh.ts +60 -0
  5. package/harness/exploration-guard-runtime.ts +316 -0
  6. package/harness/plan-handoff-bridge.ts +247 -0
  7. package/harness/plan-handoff-delivery.ts +193 -0
  8. package/harness/plan-handoff-recipient-selection.ts +205 -0
  9. package/harness/plan-handoff-registration.ts +169 -0
  10. package/harness/quota-credential-choice.ts +67 -0
  11. package/harness/quota-refresh-coordinator.ts +129 -0
  12. package/index.ts +633 -115
  13. package/package.json +7 -1
  14. package/packages/agent-policy/package.json +1 -1
  15. package/packages/auth/package.json +1 -1
  16. package/packages/autonomous-runtime/package.json +1 -1
  17. package/packages/checkpoint/package.json +1 -1
  18. package/packages/clipboard/package.json +1 -1
  19. package/packages/codex-watcher/package.json +1 -1
  20. package/packages/config-capture/package.json +1 -1
  21. package/packages/contracts/package.json +1 -1
  22. package/packages/cookie-sanitizer/dist/detect-format.d.ts +26 -12
  23. package/packages/cookie-sanitizer/dist/detect-format.d.ts.map +1 -1
  24. package/packages/cookie-sanitizer/dist/detect-format.js +54 -39
  25. package/packages/cookie-sanitizer/dist/detect-format.js.map +1 -1
  26. package/packages/cookie-sanitizer/dist/index.d.ts +9 -3
  27. package/packages/cookie-sanitizer/dist/index.d.ts.map +1 -1
  28. package/packages/cookie-sanitizer/dist/index.js +5 -3
  29. package/packages/cookie-sanitizer/dist/index.js.map +1 -1
  30. package/packages/cookie-sanitizer/dist/parse-netscape-space.d.ts +73 -0
  31. package/packages/cookie-sanitizer/dist/parse-netscape-space.d.ts.map +1 -0
  32. package/packages/cookie-sanitizer/dist/parse-netscape-space.js +154 -0
  33. package/packages/cookie-sanitizer/dist/parse-netscape-space.js.map +1 -0
  34. package/packages/cookie-sanitizer/dist/parse-netscape.d.ts +28 -1
  35. package/packages/cookie-sanitizer/dist/parse-netscape.d.ts.map +1 -1
  36. package/packages/cookie-sanitizer/dist/parse-netscape.js +50 -13
  37. package/packages/cookie-sanitizer/dist/parse-netscape.js.map +1 -1
  38. package/packages/cookie-sanitizer/dist/source-state.d.ts +56 -0
  39. package/packages/cookie-sanitizer/dist/source-state.d.ts.map +1 -0
  40. package/packages/cookie-sanitizer/dist/source-state.js +61 -0
  41. package/packages/cookie-sanitizer/dist/source-state.js.map +1 -0
  42. package/packages/cookie-sanitizer/dist/sync.d.ts +9 -0
  43. package/packages/cookie-sanitizer/dist/sync.d.ts.map +1 -1
  44. package/packages/cookie-sanitizer/dist/sync.js +47 -16
  45. package/packages/cookie-sanitizer/dist/sync.js.map +1 -1
  46. package/packages/cookie-sanitizer/dist/types.d.ts +1 -1
  47. package/packages/cookie-sanitizer/dist/types.d.ts.map +1 -1
  48. package/packages/cookie-sanitizer/package.json +1 -1
  49. package/packages/cookie-sanitizer/src/detect-format.ts +78 -41
  50. package/packages/cookie-sanitizer/src/index.ts +34 -1
  51. package/packages/cookie-sanitizer/src/parse-netscape-space.ts +188 -0
  52. package/packages/cookie-sanitizer/src/parse-netscape.ts +81 -13
  53. package/packages/cookie-sanitizer/src/source-state.ts +95 -0
  54. package/packages/cookie-sanitizer/src/sync.ts +59 -16
  55. package/packages/cookie-sanitizer/src/types.ts +4 -1
  56. package/packages/evaluation-engine/package.json +1 -1
  57. package/packages/event-bus/package.json +1 -1
  58. package/packages/event-store/package.json +1 -1
  59. package/packages/experience-replay/package.json +1 -1
  60. package/packages/exploration-guard/dist/budget.d.ts +105 -0
  61. package/packages/exploration-guard/dist/budget.d.ts.map +1 -0
  62. package/packages/exploration-guard/dist/budget.js +199 -0
  63. package/packages/exploration-guard/dist/budget.js.map +1 -0
  64. package/packages/exploration-guard/dist/checkpoint.d.ts +140 -0
  65. package/packages/exploration-guard/dist/checkpoint.d.ts.map +1 -0
  66. package/packages/exploration-guard/dist/checkpoint.js +201 -0
  67. package/packages/exploration-guard/dist/checkpoint.js.map +1 -0
  68. package/packages/exploration-guard/dist/index.d.ts +19 -0
  69. package/packages/exploration-guard/dist/index.d.ts.map +1 -0
  70. package/packages/exploration-guard/dist/index.js +18 -0
  71. package/packages/exploration-guard/dist/index.js.map +1 -0
  72. package/packages/exploration-guard/dist/observation.d.ts +82 -0
  73. package/packages/exploration-guard/dist/observation.d.ts.map +1 -0
  74. package/packages/exploration-guard/dist/observation.js +239 -0
  75. package/packages/exploration-guard/dist/observation.js.map +1 -0
  76. package/packages/exploration-guard/dist/state.d.ts +107 -0
  77. package/packages/exploration-guard/dist/state.d.ts.map +1 -0
  78. package/packages/exploration-guard/dist/state.js +300 -0
  79. package/packages/exploration-guard/dist/state.js.map +1 -0
  80. package/packages/exploration-guard/dist/status.d.ts +56 -0
  81. package/packages/exploration-guard/dist/status.d.ts.map +1 -0
  82. package/packages/exploration-guard/dist/status.js +79 -0
  83. package/packages/exploration-guard/dist/status.js.map +1 -0
  84. package/packages/exploration-guard/dist/tracker.d.ts +115 -0
  85. package/packages/exploration-guard/dist/tracker.d.ts.map +1 -0
  86. package/packages/exploration-guard/dist/tracker.js +207 -0
  87. package/packages/exploration-guard/dist/tracker.js.map +1 -0
  88. package/packages/exploration-guard/dist/types.d.ts +254 -0
  89. package/packages/exploration-guard/dist/types.d.ts.map +1 -0
  90. package/packages/exploration-guard/dist/types.js +14 -0
  91. package/packages/exploration-guard/dist/types.js.map +1 -0
  92. package/packages/exploration-guard/package.json +16 -0
  93. package/packages/exploration-guard/src/budget.ts +275 -0
  94. package/packages/exploration-guard/src/checkpoint.ts +297 -0
  95. package/packages/exploration-guard/src/index.ts +97 -0
  96. package/packages/exploration-guard/src/observation.ts +342 -0
  97. package/packages/exploration-guard/src/state.ts +357 -0
  98. package/packages/exploration-guard/src/status.ts +120 -0
  99. package/packages/exploration-guard/src/tracker.ts +291 -0
  100. package/packages/exploration-guard/src/types.ts +276 -0
  101. package/packages/file-copy-helper/package.json +1 -1
  102. package/packages/intent-analyzer/package.json +1 -1
  103. package/packages/jev-judge/dist/continuation-controller.d.ts +27 -2
  104. package/packages/jev-judge/dist/continuation-controller.d.ts.map +1 -1
  105. package/packages/jev-judge/dist/continuation-controller.js +87 -11
  106. package/packages/jev-judge/dist/continuation-controller.js.map +1 -1
  107. package/packages/jev-judge/dist/index.d.ts +2 -0
  108. package/packages/jev-judge/dist/index.d.ts.map +1 -1
  109. package/packages/jev-judge/dist/index.js +2 -0
  110. package/packages/jev-judge/dist/index.js.map +1 -1
  111. package/packages/jev-judge/dist/todo-provider.d.ts.map +1 -1
  112. package/packages/jev-judge/dist/todo-provider.js +93 -18
  113. package/packages/jev-judge/dist/todo-provider.js.map +1 -1
  114. package/packages/jev-judge/dist/todo-reconciliation.d.ts +50 -0
  115. package/packages/jev-judge/dist/todo-reconciliation.d.ts.map +1 -0
  116. package/packages/jev-judge/dist/todo-reconciliation.js +96 -0
  117. package/packages/jev-judge/dist/todo-reconciliation.js.map +1 -0
  118. package/packages/jev-judge/package.json +1 -1
  119. package/packages/jev-judge/src/continuation-controller.ts +90 -12
  120. package/packages/jev-judge/src/index.ts +8 -0
  121. package/packages/jev-judge/src/todo-provider.ts +117 -25
  122. package/packages/jev-judge/src/todo-reconciliation.ts +121 -0
  123. package/packages/knowledge-retrieval/package.json +1 -1
  124. package/packages/learning-engine/package.json +1 -1
  125. package/packages/logging/package.json +1 -1
  126. package/packages/memory-engine/package.json +1 -1
  127. package/packages/notification/dist/adapters/email-adapter.d.ts.map +1 -1
  128. package/packages/notification/dist/adapters/email-adapter.js +1 -0
  129. package/packages/notification/dist/adapters/email-adapter.js.map +1 -1
  130. package/packages/notification/dist/adapters/line-adapter.d.ts.map +1 -1
  131. package/packages/notification/dist/adapters/line-adapter.js +1 -0
  132. package/packages/notification/dist/adapters/line-adapter.js.map +1 -1
  133. package/packages/notification/dist/adapters/ntfy-adapter.d.ts.map +1 -1
  134. package/packages/notification/dist/adapters/ntfy-adapter.js +1 -0
  135. package/packages/notification/dist/adapters/ntfy-adapter.js.map +1 -1
  136. package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
  137. package/packages/notification/dist/adapters/telegram-adapter.js +1 -0
  138. package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
  139. package/packages/notification/dist/notification-center.d.ts.map +1 -1
  140. package/packages/notification/dist/notification-center.js +7 -0
  141. package/packages/notification/dist/notification-center.js.map +1 -1
  142. package/packages/notification/dist/notification-policy.d.ts.map +1 -1
  143. package/packages/notification/dist/notification-policy.js +3 -0
  144. package/packages/notification/dist/notification-policy.js.map +1 -1
  145. package/packages/notification/dist/telegram-webhook-handler.d.ts +8 -0
  146. package/packages/notification/dist/telegram-webhook-handler.d.ts.map +1 -1
  147. package/packages/notification/dist/telegram-webhook-handler.js +8 -0
  148. package/packages/notification/dist/telegram-webhook-handler.js.map +1 -1
  149. package/packages/notification/dist/types.d.ts +8 -1
  150. package/packages/notification/dist/types.d.ts.map +1 -1
  151. package/packages/notification/package.json +1 -1
  152. package/packages/notification/src/adapters/email-adapter.ts +1 -0
  153. package/packages/notification/src/adapters/line-adapter.ts +1 -0
  154. package/packages/notification/src/adapters/ntfy-adapter.ts +1 -0
  155. package/packages/notification/src/adapters/telegram-adapter.ts +1 -0
  156. package/packages/notification/src/notification-center.ts +7 -0
  157. package/packages/notification/src/notification-policy.ts +3 -0
  158. package/packages/notification/src/telegram-webhook-handler.ts +8 -0
  159. package/packages/notification/src/types.ts +7 -0
  160. package/packages/paperclip-integration/package.json +1 -1
  161. package/packages/performance-optimizer/package.json +1 -1
  162. package/packages/plan-handoff/dist/index.d.ts +31 -0
  163. package/packages/plan-handoff/dist/index.d.ts.map +1 -0
  164. package/packages/plan-handoff/dist/index.js +23 -0
  165. package/packages/plan-handoff/dist/index.js.map +1 -0
  166. package/packages/plan-handoff/dist/mailbox.d.ts +134 -0
  167. package/packages/plan-handoff/dist/mailbox.d.ts.map +1 -0
  168. package/packages/plan-handoff/dist/mailbox.js +243 -0
  169. package/packages/plan-handoff/dist/mailbox.js.map +1 -0
  170. package/packages/plan-handoff/dist/message.d.ts +152 -0
  171. package/packages/plan-handoff/dist/message.d.ts.map +1 -0
  172. package/packages/plan-handoff/dist/message.js +157 -0
  173. package/packages/plan-handoff/dist/message.js.map +1 -0
  174. package/packages/plan-handoff/dist/pairing.d.ts +51 -0
  175. package/packages/plan-handoff/dist/pairing.d.ts.map +1 -0
  176. package/packages/plan-handoff/dist/pairing.js +88 -0
  177. package/packages/plan-handoff/dist/pairing.js.map +1 -0
  178. package/packages/plan-handoff/dist/publish.d.ts +96 -0
  179. package/packages/plan-handoff/dist/publish.d.ts.map +1 -0
  180. package/packages/plan-handoff/dist/publish.js +97 -0
  181. package/packages/plan-handoff/dist/publish.js.map +1 -0
  182. package/packages/plan-handoff/dist/registry.d.ts +95 -0
  183. package/packages/plan-handoff/dist/registry.d.ts.map +1 -0
  184. package/packages/plan-handoff/dist/registry.js +122 -0
  185. package/packages/plan-handoff/dist/registry.js.map +1 -0
  186. package/packages/plan-handoff/dist/retention.d.ts +101 -0
  187. package/packages/plan-handoff/dist/retention.d.ts.map +1 -0
  188. package/packages/plan-handoff/dist/retention.js +178 -0
  189. package/packages/plan-handoff/dist/retention.js.map +1 -0
  190. package/packages/plan-handoff/dist/routing.d.ts +69 -0
  191. package/packages/plan-handoff/dist/routing.d.ts.map +1 -0
  192. package/packages/plan-handoff/dist/routing.js +75 -0
  193. package/packages/plan-handoff/dist/routing.js.map +1 -0
  194. package/packages/plan-handoff/dist/workspace.d.ts +59 -0
  195. package/packages/plan-handoff/dist/workspace.d.ts.map +1 -0
  196. package/packages/plan-handoff/dist/workspace.js +78 -0
  197. package/packages/plan-handoff/dist/workspace.js.map +1 -0
  198. package/packages/plan-handoff/package.json +16 -0
  199. package/packages/plan-handoff/src/index.ts +75 -0
  200. package/packages/plan-handoff/src/mailbox.ts +306 -0
  201. package/packages/plan-handoff/src/message.ts +286 -0
  202. package/packages/plan-handoff/src/pairing.ts +120 -0
  203. package/packages/plan-handoff/src/publish.ts +186 -0
  204. package/packages/plan-handoff/src/registry.ts +174 -0
  205. package/packages/plan-handoff/src/retention.ts +237 -0
  206. package/packages/plan-handoff/src/routing.ts +134 -0
  207. package/packages/plan-handoff/src/workspace.ts +89 -0
  208. package/packages/privilege-broker/package.json +1 -1
  209. package/packages/prompt-compiler/package.json +1 -1
  210. package/packages/providers/package.json +1 -1
  211. package/packages/qdrant-skills/package.json +1 -1
  212. package/packages/quota-manager/package.json +1 -1
  213. package/packages/relay/package.json +1 -1
  214. package/packages/skill-mcp-client/package.json +1 -1
  215. package/packages/skills/package.json +1 -1
  216. package/packages/todo-bd-sync/package.json +1 -1
  217. package/packages/token-estimation/package.json +1 -1
  218. package/packages/tooling-preference/package.json +1 -1
  219. package/packages/trajectory/package.json +1 -1
  220. package/packages/tui/package.json +1 -1
  221. package/packages/two-phase-review/package.json +1 -1
  222. package/packages/types/package.json +1 -1
  223. package/packages/webmcp-tester/package.json +1 -1
  224. package/packages/wiki/package.json +1 -1
  225. package/packages/write-review/package.json +1 -1
@@ -29,20 +29,34 @@
29
29
  * ```
30
30
  */
31
31
 
32
+ export {
33
+ inspectCookieSource,
34
+ hasCookieSourceState,
35
+ } from "./source-state.js";
36
+
32
37
  export {
33
38
  sync,
34
39
  hasAnyCookieSource,
35
40
  inferCachePath,
36
41
  enumerateDropFiles,
37
42
  readInputFile,
43
+ formatRejectionReason,
38
44
  DEFAULT_DROP_DIR,
39
45
  } from "./sync.js";
40
46
 
41
47
  export {
42
48
  parseNetscape,
49
+ parseNetscapeDetailed,
43
50
  serializeNetscape,
44
51
  } from "./parse-netscape.js";
45
52
 
53
+ export {
54
+ parseNetscapeSpace,
55
+ parseCompatibleRow,
56
+ hasCompatibleRow,
57
+ looksSpaceSeparated,
58
+ } from "./parse-netscape-space.js";
59
+
46
60
  export { parseEditThisCookieJson } from "./parse-json.js";
47
61
 
48
62
  export {
@@ -60,9 +74,9 @@ export {
60
74
 
61
75
  export {
62
76
  detectFormat,
77
+ diagnoseFormat,
63
78
  buildDetectedFile,
64
79
  safeBasename,
65
- safePreview,
66
80
  } from "./detect-format.js";
67
81
 
68
82
  export {
@@ -86,4 +100,23 @@ export type {
86
100
  WatcherEvent,
87
101
  } from "./types.js";
88
102
 
103
+ export type { FormatDiagnosis, FormatRejection } from "./detect-format.js";
104
+
105
+ export type {
106
+ CookieSourceStage,
107
+ CookieSourceState,
108
+ InspectCookieSourceOptions,
109
+ } from "./source-state.js";
110
+
111
+ export type {
112
+ CompatibleParseResult,
113
+ CompatibleRowOutcome,
114
+ CompatibleRowRejection,
115
+ } from "./parse-netscape-space.js";
116
+
117
+ export type {
118
+ ParseNetscapeOptions,
119
+ ParseNetscapeResult,
120
+ } from "./parse-netscape.js";
121
+
89
122
  export type { CookieWatcherConfig } from "./watcher.js";
@@ -0,0 +1,188 @@
1
+ /**
2
+ * The compatible parser for a space-delimited cookie export.
3
+ *
4
+ * The sanitizer promised forgiving input from its first commit: "any
5
+ * cookie file (any name, any format)". The strict parser splits a row on
6
+ * tabs only, so an export whose rows are separated by spaces was
7
+ * rejected — even though its rows carry exactly the fields of the
8
+ * Netscape format. The promise and the implementation disagreed, and the
9
+ * implementation won until now.
10
+ *
11
+ * The variant that this parser accepts:
12
+ *
13
+ * <domain> <flag> <path> <secure> <expiry> <name> <value…>
14
+ *
15
+ * The first six fields are single tokens; the value is the rest of the
16
+ * line, so a value may contain spaces. A row is accepted only when every
17
+ * field validates. An ambiguous row is rejected, never guessed: a wrong
18
+ * guess would publish a cookie that the account never had.
19
+ *
20
+ * SEC-001: values live in memory only. Nothing in this module logs a
21
+ * value, a cookie name, or a raw line.
22
+ */
23
+
24
+ import type { CanonicalCookie } from "./types.js";
25
+
26
+ /** The six leading fields and the value that follows them. */
27
+ const ROW_RE =
28
+ /^(\S+)[ \t]+(\S+)[ \t]+(\S+)[ \t]+(\S+)[ \t]+(\S+)[ \t]+(\S+)(?:[ \t](.*))?$/;
29
+
30
+ /** A hostname, optionally with a leading dot for the sub-domains. */
31
+ const DOMAIN_RE =
32
+ /^\.?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/i;
33
+
34
+ /** The Netscape flag and the secure marker are TRUE or FALSE. */
35
+ const BOOLEAN_RE = /^(TRUE|FALSE)$/i;
36
+
37
+ /** The expiry is a whole number of seconds since the epoch. */
38
+ const EXPIRY_RE = /^\d+$/;
39
+
40
+ /** The outcome of a single row. */
41
+ export type CompatibleRowOutcome =
42
+ | { kind: "accepted"; cookie: CanonicalCookie }
43
+ | { kind: "rejected"; reason: CompatibleRowRejection };
44
+
45
+ /** Why a row was rejected. A reason code, never the row itself. */
46
+ export type CompatibleRowRejection =
47
+ | "not-a-row"
48
+ | "invalid-domain"
49
+ | "invalid-flag"
50
+ | "invalid-path"
51
+ | "invalid-secure"
52
+ | "invalid-expiry"
53
+ | "missing-value";
54
+
55
+ /** The result of a whole file. */
56
+ export interface CompatibleParseResult {
57
+ cookies: CanonicalCookie[];
58
+ /** Rows that were read. */
59
+ accepted: number;
60
+ /** Rows that looked like a row but did not validate. */
61
+ rejected: number;
62
+ /** Why the rows were rejected, counted per reason. */
63
+ rejections: Record<CompatibleRowRejection, number>;
64
+ }
65
+
66
+ /**
67
+ * Parse one line of a space-delimited export.
68
+ *
69
+ * Returns `null` when the line is not a row at all (an empty line or a
70
+ * comment). A row that is not valid returns a rejection with its reason.
71
+ */
72
+ export function parseCompatibleRow(
73
+ line: string,
74
+ ): CompatibleRowOutcome | null {
75
+ let text = line;
76
+ let httpOnly = false;
77
+
78
+ if (text.startsWith("#HttpOnly_")) {
79
+ httpOnly = true;
80
+ text = text.slice("#HttpOnly_".length);
81
+ } else if (text.startsWith("#")) {
82
+ // A comment of the Netscape format (including the header).
83
+ return null;
84
+ }
85
+
86
+ if (!text.trim()) return null;
87
+
88
+ const match = ROW_RE.exec(text);
89
+ if (!match) return { kind: "rejected", reason: "not-a-row" };
90
+
91
+ const [, domain, flag, cookiePath, secure, expires, name, value] = match;
92
+
93
+ if (!DOMAIN_RE.test(domain)) return { kind: "rejected", reason: "invalid-domain" };
94
+ if (!BOOLEAN_RE.test(flag)) return { kind: "rejected", reason: "invalid-flag" };
95
+ if (!cookiePath.startsWith("/")) return { kind: "rejected", reason: "invalid-path" };
96
+ if (!BOOLEAN_RE.test(secure)) return { kind: "rejected", reason: "invalid-secure" };
97
+ if (!EXPIRY_RE.test(expires)) return { kind: "rejected", reason: "invalid-expiry" };
98
+ // The value is the rest of the line. A row without one carries nothing.
99
+ if (value === undefined || value.length === 0) {
100
+ return { kind: "rejected", reason: "missing-value" };
101
+ }
102
+
103
+ const expiry = Number.parseInt(expires, 10);
104
+
105
+ return {
106
+ kind: "accepted",
107
+ cookie: {
108
+ name,
109
+ value,
110
+ domain,
111
+ path: cookiePath,
112
+ expires: expiry === 0 ? undefined : expiry,
113
+ secure: secure.toUpperCase() === "TRUE",
114
+ httpOnly,
115
+ },
116
+ };
117
+ }
118
+
119
+ /**
120
+ * Parse a whole space-delimited export.
121
+ *
122
+ * Never throws. Returns the cookies and the counts of the rows that were
123
+ * read and of the rows that were rejected, so a diagnostic can report the
124
+ * counts without the content.
125
+ */
126
+ export function parseNetscapeSpace(text: string): CompatibleParseResult {
127
+ const result: CompatibleParseResult = {
128
+ cookies: [],
129
+ accepted: 0,
130
+ rejected: 0,
131
+ rejections: {
132
+ "not-a-row": 0,
133
+ "invalid-domain": 0,
134
+ "invalid-flag": 0,
135
+ "invalid-path": 0,
136
+ "invalid-secure": 0,
137
+ "invalid-expiry": 0,
138
+ "missing-value": 0,
139
+ },
140
+ };
141
+
142
+ if (typeof text !== "string" || text.length === 0) return result;
143
+
144
+ for (const raw of text.split(/\r?\n/)) {
145
+ const outcome = parseCompatibleRow(raw);
146
+ if (!outcome) continue;
147
+ if (outcome.kind === "accepted") {
148
+ result.cookies.push(outcome.cookie);
149
+ result.accepted++;
150
+ continue;
151
+ }
152
+ result.rejected++;
153
+ result.rejections[outcome.reason]++;
154
+ }
155
+
156
+ return result;
157
+ }
158
+
159
+ /**
160
+ * Does the text hold a row that the compatible parser accepts?
161
+ *
162
+ * Used by the detection: a file whose rows are space-separated is a
163
+ * supported format, even when its header wording is unusual.
164
+ */
165
+ export function hasCompatibleRow(text: string): boolean {
166
+ if (typeof text !== "string" || text.length === 0) return false;
167
+ for (const raw of text.split(/\r?\n/)) {
168
+ const outcome = parseCompatibleRow(raw);
169
+ if (outcome?.kind === "accepted") return true;
170
+ }
171
+ return false;
172
+ }
173
+
174
+ /**
175
+ * Does the text hold a row that looks space-separated, valid or not?
176
+ *
177
+ * The diagnostic needs to tell "the rows use spaces" from "the file holds
178
+ * no rows at all", and it may say so without naming a cookie.
179
+ */
180
+ export function looksSpaceSeparated(text: string): boolean {
181
+ if (typeof text !== "string" || text.length === 0) return false;
182
+ for (const raw of text.split(/\r?\n/)) {
183
+ if (!raw || raw.startsWith("#")) continue;
184
+ if (raw.includes("\t")) continue;
185
+ return true;
186
+ }
187
+ return false;
188
+ }
@@ -19,6 +19,7 @@
19
19
  */
20
20
 
21
21
  import type { CanonicalCookie } from "./types.js";
22
+ import { parseCompatibleRow } from "./parse-netscape-space.js";
22
23
 
23
24
  /** Raw row as parsed from a Netscape file. */
24
25
  interface NetscapeRow {
@@ -31,6 +32,28 @@ interface NetscapeRow {
31
32
  value: string;
32
33
  }
33
34
 
35
+ /** The options of the Netscape parser. */
36
+ export interface ParseNetscapeOptions {
37
+ /**
38
+ * Read a row that the tab split rejects with the compatible parser.
39
+ *
40
+ * A file may hold both kinds of rows: an export that a tool wrote with
41
+ * tabs and rows that a human typed with spaces. The fallback reads the
42
+ * second kind instead of dropping it. It stays off by default, so the
43
+ * strict parser keeps its documented behaviour.
44
+ */
45
+ compatibleFallback?: boolean;
46
+ }
47
+
48
+ /** The outcome of a parse: the cookies and the counts of the rows. */
49
+ export interface ParseNetscapeResult {
50
+ cookies: CanonicalCookie[];
51
+ /** Rows that were read. */
52
+ accepted: number;
53
+ /** Rows that looked like a row but did not validate. */
54
+ rejected: number;
55
+ }
56
+
34
57
  /**
35
58
  * Parse a Netscape-format cookie string into canonical records.
36
59
  *
@@ -41,8 +64,29 @@ interface NetscapeRow {
41
64
  *
42
65
  * Never throws; returns empty array if input is invalid.
43
66
  */
44
- export function parseNetscape(text: string): CanonicalCookie[] {
45
- if (typeof text !== "string" || text.length === 0) return [];
67
+ export function parseNetscape(
68
+ text: string,
69
+ options: ParseNetscapeOptions = {},
70
+ ): CanonicalCookie[] {
71
+ return parseNetscapeDetailed(text, options).cookies;
72
+ }
73
+
74
+ /**
75
+ * Parse a Netscape-format cookie string and report the counts of the rows.
76
+ *
77
+ * The counts are what a diagnostic may show. The rows themselves stay in
78
+ * memory and never reach a log line.
79
+ */
80
+ export function parseNetscapeDetailed(
81
+ text: string,
82
+ options: ParseNetscapeOptions = {},
83
+ ): ParseNetscapeResult {
84
+ const result: ParseNetscapeResult = {
85
+ cookies: [],
86
+ accepted: 0,
87
+ rejected: 0,
88
+ };
89
+ if (typeof text !== "string" || text.length === 0) return result;
46
90
 
47
91
  const rows: NetscapeRow[] = [];
48
92
  const lines = text.split(/\r?\n/);
@@ -61,10 +105,30 @@ export function parseNetscape(text: string): CanonicalCookie[] {
61
105
  }
62
106
 
63
107
  const cols = line.split("\t");
64
- if (cols.length < 7) continue;
108
+ if (cols.length < 7) {
109
+ const compatible = options.compatibleFallback
110
+ ? parseCompatibleRow(raw)
111
+ : null;
112
+ if (compatible?.kind === "accepted") {
113
+ result.cookies.push(compatible.cookie);
114
+ result.accepted++;
115
+ continue;
116
+ }
117
+ if (compatible?.kind === "rejected") {
118
+ result.rejected++;
119
+ continue;
120
+ }
121
+ // The strict parser skips a row it cannot read. The count is
122
+ // what a diagnostic may show; the row itself stays unread.
123
+ result.rejected++;
124
+ continue;
125
+ }
65
126
 
66
127
  const [domain, _flag, cookiePath, secure, expires, name, value] = cols;
67
- if (!name || !value) continue;
128
+ if (!name || !value) {
129
+ result.rejected++;
130
+ continue;
131
+ }
68
132
 
69
133
  rows.push({
70
134
  domain: (domain ?? "").trim(),
@@ -78,15 +142,19 @@ export function parseNetscape(text: string): CanonicalCookie[] {
78
142
  }
79
143
 
80
144
  // Map to CanonicalCookie shape.
81
- return rows.map((r) => ({
82
- name: r.name,
83
- value: r.value,
84
- domain: r.domain,
85
- path: r.path,
86
- expires: r.expires === 0 ? undefined : r.expires,
87
- secure: r.secure,
88
- httpOnly: r.httpOnly,
89
- }));
145
+ for (const r of rows) {
146
+ result.cookies.push({
147
+ name: r.name,
148
+ value: r.value,
149
+ domain: r.domain,
150
+ path: r.path,
151
+ expires: r.expires === 0 ? undefined : r.expires,
152
+ secure: r.secure,
153
+ httpOnly: r.httpOnly,
154
+ });
155
+ result.accepted++;
156
+ }
157
+ return result;
90
158
  }
91
159
 
92
160
  /**
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The state of the cookie source.
3
+ *
4
+ * Three facts are different and were conflated:
5
+ *
6
+ * - discovery: a file exists in the drop folder.
7
+ * - import: the canonical cache exists, which only happens after a
8
+ * successful validation and normalization of a drop file.
9
+ * - authentication: the provider accepted the credential.
10
+ *
11
+ * The first two are facts about this machine and are cheap to read. The
12
+ * third is a fact about the provider and only a fetch can establish it.
13
+ * This module reports the first two; the runtime reports the third.
14
+ *
15
+ * Nothing here reads a cookie value: the state is a stage and a count.
16
+ */
17
+
18
+ import { existsSync } from "node:fs";
19
+ import { enumerateDropFiles } from "./sync.js";
20
+
21
+ /**
22
+ * How far the cookie source got.
23
+ *
24
+ * - `none`: nothing was found.
25
+ * - `discovered`: a file was found in the drop folder; it was not imported.
26
+ * - `imported`: the canonical cache exists, so an import succeeded.
27
+ */
28
+ export type CookieSourceStage = "none" | "discovered" | "imported";
29
+
30
+ /** The state of the cookie source. */
31
+ export interface CookieSourceState {
32
+ /** The stage the source reached. */
33
+ stage: CookieSourceStage;
34
+ /** The files that the drop folder holds. */
35
+ dropFileCount: number;
36
+ /** Whether the canonical cache exists. */
37
+ cacheExists: boolean;
38
+ /** The canonical cache path, when it is known. */
39
+ cachePath: string | null;
40
+ }
41
+
42
+ /** The options of the inspection. */
43
+ export interface InspectCookieSourceOptions {
44
+ /** The drop folder. */
45
+ dropDir: string;
46
+ /** The canonical cache path. */
47
+ cachePath?: string;
48
+ }
49
+
50
+ /**
51
+ * Report the state of the cookie source.
52
+ *
53
+ * Never throws: an unreadable folder is a folder with no files.
54
+ */
55
+ export function inspectCookieSource(
56
+ options: InspectCookieSourceOptions,
57
+ ): CookieSourceState {
58
+ const dropDir = options.dropDir;
59
+ const cachePath = options.cachePath ?? null;
60
+
61
+ let dropFileCount = 0;
62
+ try {
63
+ dropFileCount = enumerateDropFiles(dropDir).length;
64
+ } catch {
65
+ dropFileCount = 0;
66
+ }
67
+
68
+ let cacheExists = false;
69
+ if (cachePath) {
70
+ try {
71
+ cacheExists = existsSync(cachePath);
72
+ } catch {
73
+ cacheExists = false;
74
+ }
75
+ }
76
+
77
+ let stage: CookieSourceStage = "none";
78
+ if (cacheExists) {
79
+ stage = "imported";
80
+ } else if (dropFileCount > 0) {
81
+ stage = "discovered";
82
+ }
83
+
84
+ return { stage, dropFileCount, cacheExists, cachePath };
85
+ }
86
+
87
+ /**
88
+ * Whether a source exists at all.
89
+ *
90
+ * The name says "exists", so it answers the discovery question and never
91
+ * the authentication question.
92
+ */
93
+ export function hasCookieSourceState(state: CookieSourceState): boolean {
94
+ return state.stage !== "none";
95
+ }
@@ -24,8 +24,17 @@ import {
24
24
  } from "node:fs";
25
25
  import { join } from "node:path";
26
26
  import type { CanonicalCookie, SyncOptions, SyncResult } from "./types.js";
27
- import { buildDetectedFile, safePreview } from "./detect-format.js";
28
- import { parseNetscape, serializeNetscape } from "./parse-netscape.js";
27
+ import {
28
+ buildDetectedFile,
29
+ diagnoseFormat,
30
+ type FormatRejection,
31
+ } from "./detect-format.js";
32
+ import {
33
+ parseNetscape,
34
+ parseNetscapeDetailed,
35
+ serializeNetscape,
36
+ } from "./parse-netscape.js";
37
+ import { parseNetscapeSpace } from "./parse-netscape-space.js";
29
38
  import { parseEditThisCookieJson } from "./parse-json.js";
30
39
  import { normalize } from "./normalize.js";
31
40
  import { inferProvider } from "./infer-provider.js";
@@ -127,6 +136,29 @@ export function readInputFile(filePath: string): {
127
136
  }
128
137
  }
129
138
 
139
+ /**
140
+ * The reason a file was not imported, in words a user can act on.
141
+ *
142
+ * The sentence names the file by its basename and says what to do. It
143
+ * never repeats a line, a header, a cookie name, or a cookie value: the
144
+ * content of a credential file never reaches a log line.
145
+ */
146
+ export function formatRejectionReason(
147
+ basename: string,
148
+ reason: FormatRejection | undefined,
149
+ ): string {
150
+ switch (reason) {
151
+ case "space-rows-not-valid":
152
+ return `${basename} found, but its Netscape rows use spaces and did not validate; export Netscape TSV or EditThisCookie JSON`;
153
+ case "no-rows":
154
+ return `${basename} found, but it holds no cookie rows; export Netscape TSV or EditThisCookie JSON`;
155
+ case "tab-rows-not-valid":
156
+ return `${basename} found, but its rows did not validate; export Netscape TSV or EditThisCookie JSON`;
157
+ default:
158
+ return `${basename} found, but its format was not recognized; export Netscape TSV or EditThisCookie JSON`;
159
+ }
160
+ }
161
+
130
162
  /**
131
163
  * Run the full sync pipeline.
132
164
  *
@@ -175,30 +207,41 @@ export function sync(opts: SyncOptions = {}): SyncResult {
175
207
 
176
208
  const det = buildDetectedFile(filePath, text);
177
209
  if (det.format == null) {
178
- const preview = safePreview(text);
179
- tmpResult.skippedFiles.push({
180
- basename: det.basename,
181
- reason: `unrecognised format (preview: ${preview})`,
182
- });
183
- tmpResult.errors.push({
184
- basename: det.basename,
185
- message: "unrecognised format",
186
- });
210
+ const diagnosis = diagnoseFormat(text);
211
+ const reason = formatRejectionReason(det.basename, diagnosis.reason);
212
+ tmpResult.skippedFiles.push({ basename: det.basename, reason });
213
+ tmpResult.errors.push({ basename: det.basename, message: reason });
187
214
  continue;
188
215
  }
189
216
 
190
217
  let cookies: CanonicalCookie[] = [];
218
+ let accepted = 0;
219
+ let rejected = 0;
191
220
  if (det.format === "netscape") {
192
- cookies = parseNetscape(text);
221
+ // A file may hold both kinds of rows. The fallback reads the
222
+ // rows that the tab split rejects with the compatible parser.
223
+ const parsed = parseNetscapeDetailed(text, { compatibleFallback: true });
224
+ cookies = parsed.cookies;
225
+ accepted = parsed.accepted;
226
+ rejected = parsed.rejected;
227
+ } else if (det.format === "netscape-space") {
228
+ const parsed = parseNetscapeSpace(text);
229
+ cookies = parsed.cookies;
230
+ accepted = parsed.accepted;
231
+ rejected = parsed.rejected;
193
232
  } else if (det.format === "edit-this-cookie-json") {
194
233
  cookies = parseEditThisCookieJson(text);
234
+ accepted = cookies.length;
195
235
  }
196
236
 
197
237
  if (cookies.length === 0) {
198
- tmpResult.skippedFiles.push({
199
- basename: det.basename,
200
- reason: `${det.format} parsed but yielded 0 cookies`,
201
- });
238
+ const counts =
239
+ det.format === "edit-this-cookie-json"
240
+ ? "0 cookies"
241
+ : `${accepted} rows read, ${rejected} rows rejected`;
242
+ const reason = `${det.basename} parsed as ${det.format} but yielded 0 cookies (${counts})`;
243
+ tmpResult.skippedFiles.push({ basename: det.basename, reason });
244
+ tmpResult.errors.push({ basename: det.basename, message: reason });
202
245
  continue;
203
246
  }
204
247
 
@@ -20,7 +20,10 @@ export type ProviderId =
20
20
  | string;
21
21
 
22
22
  /** Input file format. */
23
- export type CookieFileFormat = "netscape" | "edit-this-cookie-json";
23
+ export type CookieFileFormat =
24
+ | "netscape"
25
+ | "netscape-space"
26
+ | "edit-this-cookie-json";
24
27
 
25
28
  /** A single cookie in canonical (post-normalize) form. */
26
29
  export interface CanonicalCookie {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/evaluation-engine",
3
- "version": "1.1.512",
3
+ "version": "1.1.514",
4
4
  "description": "Evaluation engine for pi-harness runtime (RFC-0057)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/event-bus",
3
- "version": "1.1.512",
3
+ "version": "1.1.514",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/event-store",
3
- "version": "1.1.512",
3
+ "version": "1.1.514",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/experience-replay",
3
- "version": "1.1.512",
3
+ "version": "1.1.514",
4
4
  "description": "Experience replay for debugging and reproducibility (RFC-0059)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",