flow-comet 1.5.1 → 1.6.0

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.
@@ -35,7 +35,12 @@ export function workflowPathInside(root, target) {
35
35
  );
36
36
  }
37
37
 
38
- export async function inspectWorkflowProtectedPath(
38
+ // 路径段扫描(单一权威):target 词法必须在 projectRoot 内;root 必须是真实目录;自 root 起
39
+ // 对 target 的每个已存在段逐段 lstat——任一段为 symlink/junction、非末段非目录、末段类型不符
40
+ // expected、或某段 realpath 逃出物理 root → 抛错(fail-closed);最近已存在祖先之后不存在
41
+ // → 返回 { exists: false }(不是错误:写资格判定允许目标尚未创建)。调用方负责 runRoot 的
42
+ // realpath 归一(写入侧传 realpath 后的 root)。受保护读取与写路径资格共用本段扫描,禁止副本。
43
+ export async function inspectWorkflowPathSegments(
39
44
  projectRoot,
40
45
  target,
41
46
  label,
@@ -93,7 +98,22 @@ export async function inspectWorkflowProtectedPath(
93
98
  return { target: lexicalTarget, exists: true };
94
99
  }
95
100
 
96
- function workflowFileObjectIdentity(stat) {
101
+ // 兼容既有消费方(readWorkflowProtectedFile / comet-hook-guard):受保护读取使用同一段
102
+ // 扫描权威;这里是委托而非第二份实现(L-067 单一权威)。
103
+ export async function inspectWorkflowProtectedPath(
104
+ projectRoot,
105
+ target,
106
+ label,
107
+ expected = 'any',
108
+ ) {
109
+ return inspectWorkflowPathSegments(projectRoot, target, label, expected);
110
+ }
111
+
112
+ // 文件身份比较判据(workflowFileObjectIdentity / workflowSameFileObject / workflowSameFileStat)
113
+ // 与受保护读取 readWorkflowProtectedFile 的单一权威在本模块:workflow-guard 与 comet-hook-guard
114
+ // 均 import 复用,不再各自保留逐字节副本(同一判据两份实现会静默分叉——注释互指同源不是同步机制)。
115
+ // workflowHasIdentity 仅被本模块 workflowSameFileObject 消费,保持私有(无外部消费方不导出)。
116
+ export function workflowFileObjectIdentity(stat) {
97
117
  return {
98
118
  dev: stat.dev,
99
119
  ino: stat.ino,
@@ -105,7 +125,7 @@ function workflowHasIdentity(value) {
105
125
  return value !== 0 && value !== 0n && value !== '0';
106
126
  }
107
127
 
108
- function workflowSameFileObject(left, right) {
128
+ export function workflowSameFileObject(left, right) {
109
129
  const comparableDevice = workflowHasIdentity(left.dev) && workflowHasIdentity(right.dev);
110
130
  const comparableInode = workflowHasIdentity(left.ino) && workflowHasIdentity(right.ino);
111
131
  if (comparableDevice && left.dev !== right.dev) return false;
@@ -114,7 +134,7 @@ function workflowSameFileObject(left, right) {
114
134
  return left.birthtime === right.birthtime;
115
135
  }
116
136
 
117
- function workflowSameFileStat(left, right) {
137
+ export function workflowSameFileStat(left, right) {
118
138
  return (
119
139
  workflowSameFileObject(
120
140
  workflowFileObjectIdentity(left),