@tedbrain/vlink 0.0.0-dpv2.pdkadapt.plugin.0.1.1.r1 → 0.0.0-dpv2.pdkadapt.plugin.0.1.2.r2

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.
package/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  这是独立 Python distribution,当前提供安装器、REST 控制面和客户端候选。源码与 DPV1 同仓,运行时不导入旧 cli/MCP;没有改动 DPV1 的入口、服务器或客户端。
4
4
 
5
- **尚未具备完整适配能力。** 真实工作站绑定、独立 SDK/EDA worker、旧 check/source-* 动作和四平台实际验收仍属 I01618。不要手工写 admitted=true 绕过未完成的 worker 准入。未配置准入时,业务提交明确返回 503;健康检查通过不表示可执行适配。
5
+ **尚未具备完整适配能力。** 真实工作站绑定、独立 SDK/EDA worker 和四平台实际验收仍属 I01618。不要手工写 admitted=true 绕过未完成的 worker 准入。未配置准入时,业务提交明确返回 503;健康检查通过不表示可执行适配。
6
+
7
+ 旧动作面映射(2026-11-29):`--action check` 映射 `POST /checks`,只查询不启动适配;复用判定只来自本账号自身的 DPV2 交付历史(服务器端跨主体复用保持关闭)。REUSED 必须携带与交付 tree 摘要一致的 `--use-client-revision`;有交付未确认时返回 `CLIENT_CONFIRMATION_REQUIRED`,无历史时按旧语义返回 `ADAPTATION_REQUIRED`/`REUSE_DISABLED`,check 恒以退出码 0 结束。`source-preview/confirm/install/publish` 保留旧参数校验(--vendor-dir、64 位 --options-hash/--revision、--token、--confirmed、--reason、--alias/--run-id),映射 `POST /sources/{previews,confirmations,installations,publications}`;DPV2 未提供公共工艺源复用通道,服务端以结构化 `SOURCE_REUSE_UNAVAILABLE` 应答(退出码 1),不伪造成功也不静默忽略。
6
8
 
7
9
  ## 本地安装与验证
8
10
 
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@tedbrain/vlink", "private": false, "version": "0.0.0-dpv2.pdkadapt.plugin.0.1.1.r1"}
1
+ {"name": "@tedbrain/vlink", "private": false, "version": "0.0.0-dpv2.pdkadapt.plugin.0.1.2.r2"}
@@ -4,11 +4,13 @@ import getpass
4
4
  import json
5
5
  import os
6
6
  from pathlib import Path
7
+ import re
7
8
  import secrets
8
9
  import subprocess
9
10
  import sys
10
11
  import tempfile
11
12
  import time
13
+ import unicodedata
12
14
  from .installer import ContractError, atomic, canonical, loads
13
15
  from .service import PREFIX
14
16
 
@@ -43,6 +45,55 @@ def show(code,envelope):
43
45
  return code
44
46
 
45
47
 
48
+ SOURCE_ROUTES={'source-preview':'previews','source-confirm':'confirmations',
49
+ 'source-install':'installations','source-publish':'publications'}
50
+
51
+
52
+ def post_request(root,key,path,body):
53
+ """Persist every authenticated POST intent before invoking private vlink."""
54
+ journal=root/'requests';journal.mkdir(parents=True,exist_ok=True,mode=0o700)
55
+ record=journal/(key+'.json');intent={'path':path,'body':body,'request_id':key}
56
+ # Exclusive creation makes a reused key with different input fail before send.
57
+ try:
58
+ descriptor=os.open(record,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
59
+ except FileExistsError:
60
+ if loads(record.read_bytes())!=intent:raise ContractError('request ID belongs to different input')
61
+ else:
62
+ with os.fdopen(descriptor,'wb') as stream:
63
+ stream.write(canonical(intent));stream.flush();os.fsync(stream.fileno())
64
+ code,envelope=transport('POST',path,body,key)
65
+ print(json.dumps({'request_id':key,'request_record':str(record)},ensure_ascii=False),file=sys.stderr)
66
+ return code,envelope
67
+
68
+
69
+ def source_action(args,root,key):
70
+ """Old source-reuse face: DPV1 parameter validation, then the DPV2 REST answer.
71
+
72
+ The shared source channel stays closed on DPV2 (server-side reuse
73
+ boundary), so the service returns the defined structured status; the CLI
74
+ keeps DPV1's exit code for it instead of silently succeeding.
75
+ """
76
+ vendor=args.vendor_dir
77
+ if not vendor:raise ContractError('必须提供厂商 PDK 的绝对目录 --vendor-dir。')
78
+ if args.action=='source-publish':
79
+ reason=args.reason.strip()
80
+ if not 1<=len(reason)<=500 or any(unicodedata.category(char)=='Cc' for char in reason):
81
+ raise ContractError('请提供 1–500 字符的明确任务理由,说明本次源归档上传的用途,不得包含控制字符。')
82
+ if args.action in ('source-confirm','source-install'):
83
+ if not re.fullmatch('[0-9a-f]{64}',args.options_hash) or not re.fullmatch('[0-9a-f]{64}',args.revision) or not args.token:
84
+ raise ContractError('source-confirm/source-install 需要预览回执中的 --options-hash、--revision 和 --token。')
85
+ if not args.confirmed:
86
+ raise ContractError('公共工艺复用必须显式确认:请附加 --confirmed 表示用户已确认该配置。')
87
+ if args.action=='source-install' and (not args.alias or not args.run_id):
88
+ raise ContractError('source-install 需要交付目标 --alias 和本次复用作业的 --run-id。')
89
+ code,envelope=post_request(root,key,PREFIX+'/sources/'+SOURCE_ROUTES[args.action],
90
+ {'action':args.action,'vendor_dir':vendor})
91
+ if not code:
92
+ value=envelope.get('body') if envelope.get('outcome')=='response' else envelope
93
+ if isinstance(value,dict) and value.get('ok') is False:return show(1,envelope)
94
+ return show(code,envelope)
95
+
96
+
46
97
  def main(argv=None):
47
98
  argv=list(sys.argv[1:] if argv is None else argv)
48
99
  root=Path(os.environ.get('DPV2_PLUGIN_ROOT',str(Path.home()/'.ted/tedbrain/plugins/pdkadapt')))
@@ -123,6 +174,12 @@ def main(argv=None):
123
174
  if not __import__('re').fullmatch(r'[A-Za-z0-9._-]{1,128}',key):p.error('invalid --request-id')
124
175
  fields=['action','mode','vendor_dir','alias','foundry','arch','cells','run_id','from_step','layer_decision','layer_rule_decision','source_package','use_client_revision']
125
176
  request={name:getattr(args,name) for name in fields}
177
+ if args.action=='check':
178
+ # Old check face: pure reuse/prerequisite query; DPV1 answers it with
179
+ # exit 0 regardless of the reuse verdict, and so does DPV2.
180
+ code,envelope=post_request(root,key,PREFIX+'/checks',request)
181
+ return show(0 if not code else code,envelope)
182
+ if args.action in SOURCE_ROUTES:return source_action(args,root,key)
126
183
  if args.action=='start':
127
184
  if not args.workstation_id:p.error('start requires --workstation-id')
128
185
  path=PREFIX+'/jobs';body={'workstation_id':args.workstation_id,'request':request}
@@ -133,19 +190,8 @@ def main(argv=None):
133
190
  if not args.run_id:p.error('cancel requires --run-id')
134
191
  path=PREFIX+'/jobs/'+args.run_id+'/cancellations';body={}
135
192
  else:
136
- raise ContractError('This action has not been admitted on DPV2; it will not run through DPV1')
137
- journal=root/'requests';journal.mkdir(parents=True,exist_ok=True,mode=0o700)
138
- record=journal/(key+'.json');intent={'path':path,'body':body,'request_id':key}
139
- # Exclusive creation makes a reused key with different input fail before send.
140
- try:
141
- descriptor=os.open(record,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
142
- except FileExistsError:
143
- if loads(record.read_bytes())!=intent:raise ContractError('request ID belongs to different input')
144
- else:
145
- with os.fdopen(descriptor,'wb') as stream:
146
- stream.write(canonical(intent));stream.flush();os.fsync(stream.fileno())
147
- code,envelope=transport('POST',path,body,key)
148
- print(json.dumps({'request_id':key,'request_record':str(record)},ensure_ascii=False),file=sys.stderr)
193
+ raise ContractError('unsupported action for this request path')
194
+ code,envelope=post_request(root,key,path,body)
149
195
  if code or not args.wait:return show(code,envelope)
150
196
  body=envelope['body'];job=body['job_id']
151
197
  print(json.dumps(body,ensure_ascii=False),flush=True)
@@ -197,3 +197,20 @@ class Jobs:
197
197
  row=db.execute('SELECT job,attempt FROM requests WHERE subject=? AND key=?',(subject,key)).fetchone()
198
198
  if row is None:raise NotFound('request not found')
199
199
  return dict(self.get(subject,row['job']),submission_attempt=row['attempt'])
200
+
201
+ def latest_delivery(self,subject,alias):
202
+ """Latest confirmed INSTALLED delivery this subject owns for the alias.
203
+
204
+ The old check action needs a reuse answer. DPV2 keeps server-side
205
+ cross-subject reuse closed, so the only honest reusable asset is this
206
+ subject's own completed adaptation history.
207
+ """
208
+ with self.connection() as db:
209
+ rows=db.execute("SELECT * FROM jobs WHERE subject=? AND state='SUCCEEDED' ORDER BY updated DESC",(subject,)).fetchall()
210
+ for row in rows:
211
+ if json.loads(row['request']).get('alias')!=alias:continue
212
+ result=json.loads(row['result']) if row['result'] else None
213
+ delivery=(result or {}).get('delivery') or {}
214
+ if delivery.get('status')=='INSTALLED':
215
+ return dict(self.public(row),delivery=delivery)
216
+ return None
@@ -7,6 +7,14 @@ from pathlib import Path
7
7
  import tarfile
8
8
  from .installer import ContractError, relative, package_identity
9
9
 
10
+ # 1980-01-01T00:00:00Z: a fixed deterministic epoch above tar's plausibility
11
+ # threshold. Epoch-zero member stamps made GNU tar emit hundreds of
12
+ # "implausibly old time stamp" warnings during cold installs (I01728) while
13
+ # extraction itself succeeded; this constant keeps the bytes reproducible and
14
+ # stays within ustar/bsdtar/Windows-tar support. Already published npm
15
+ # versions are immutable and are never rebuilt with the new constant.
16
+ ARCHIVE_EPOCH = 315532800
17
+
10
18
 
11
19
  def pack(directory, output, package, version, registry='https://registry.npmjs.org'):
12
20
  directory=Path(directory);output=Path(output)
@@ -32,10 +40,10 @@ def pack(directory, output, package, version, registry='https://registry.npmjs.o
32
40
  output.parent.mkdir(parents=True,exist_ok=True)
33
41
  # Fixed tar/gzip timestamps make the artifact content reproducible.
34
42
  import gzip
35
- with output.open('wb') as stream, gzip.GzipFile(fileobj=stream,mode='wb',mtime=0,filename='') as zipped:
43
+ with output.open('wb') as stream, gzip.GzipFile(fileobj=stream,mode='wb',mtime=ARCHIVE_EPOCH,filename='') as zipped:
36
44
  with tarfile.open(fileobj=zipped,mode='w|') as tar:
37
45
  for name,data in sorted(payload.items()):
38
- member=tarfile.TarInfo('package/'+name);member.size=len(data);member.mtime=0
46
+ member=tarfile.TarInfo('package/'+name);member.size=len(data);member.mtime=ARCHIVE_EPOCH
39
47
  member.mode=0o755 if name in executables else 0o644
40
48
  tar.addfile(member,io.BytesIO(data))
41
49
  raw=output.read_bytes()
@@ -99,6 +99,39 @@ class Application:
99
99
  def workstation(self,subject,identifier):
100
100
  return self.workstations.get(subject,identifier)
101
101
 
102
+ def check(self,subject,request):
103
+ """Old check face over DPV2's own durable history; never starts work.
104
+
105
+ DPV1 semantics kept where the state exists: REUSED needs the caller to
106
+ confirm the installed delivery digest via use_client_revision, because
107
+ DPV2 has no client back-channel to compare the vendor content itself.
108
+ """
109
+ alias=request['alias'];mode=request['mode'];vendor=request.get('vendor_dir','')
110
+ found=self.jobs.latest_delivery(subject,alias)
111
+ if found is None:
112
+ if vendor:
113
+ return {'ok':False,'status':'ADAPTATION_REQUIRED','pdk_id':alias,'mode':mode,
114
+ 'reuse_available':False,'adaptation_started':False,'next_action':'start_adaptation',
115
+ 'message':'没有可复用的既有交付;请以提供的原始 PDK 目录发起新适配。'}
116
+ return {'ok':False,'status':'REUSE_DISABLED','pdk_id':alias,'mode':mode,'reuse_enabled':False,
117
+ 'reuse_available':False,'adaptation_started':False,'next_action':'provide_vendor_directory',
118
+ 'message':'DPV2 未启用公共工艺复用,也没有该账号的既有交付;请提供原始 PDK 目录进行适配。'}
119
+ delivery=found['delivery'];tree=delivery.get('tree_sha256','')
120
+ revision=request.get('use_client_revision','')
121
+ if tree and revision==tree:
122
+ return {'ok':True,'status':'REUSED','job_status':'REUSED','pdk_id':alias,'mode':mode,
123
+ 'adaptation_started':False,'run_id':found['job_id'],'workstation_id':found['workstation_id'],
124
+ 'origin':'dpv2-history','version':tree,'match_method':'client_revision','completed_mode':'full'}
125
+ if revision:
126
+ return {'ok':False,'status':'ADAPTATION_REQUIRED','pdk_id':alias,'mode':mode,'adaptation_started':False,
127
+ 'previous_run_id':found['job_id'],
128
+ 'message':'确认的安装摘要与既有 DPV2 交付不一致;请核实当前安装的交付摘要,或以原始 PDK 目录重新适配。'}
129
+ return {'ok':False,'status':'CLIENT_CONFIRMATION_REQUIRED','pdk_id':alias,'mode':mode,'adaptation_started':False,
130
+ 'run_id':found['job_id'],'workstation_id':found['workstation_id'],'delivery_tree_sha256':tree,
131
+ 'next_action':'confirm_revision_or_start_adaptation',
132
+ 'message':'已有 DPV2 交付(run_id=%s)。请用 --use-client-revision 提交当前安装的交付摘要以确认复用,'
133
+ '或提供 --vendor-dir 重新适配。'%found['job_id']}
134
+
102
135
  def worker(self):
103
136
  if self.candidate:
104
137
  release=self.config.get('candidate_worker')
@@ -152,8 +185,26 @@ class Application:
152
185
  return 200,{'plugin':'pdkadapt','protocol_version':1,'worker_ready':worker is not None,
153
186
  'workstation_proxy':self.config.get('transport',{}).get('public_proxy_url'),
154
187
  'deployment_stage':'local-candidate' if self.candidate else 'release',
155
- 'actions':['start','status','resume','cancel'] if worker else ['status'],
188
+ 'actions':['check','start','status','resume','cancel'] if worker else ['status'],
156
189
  'default_start':'async','plugin_version':worker['version'] if worker else None}
190
+ if method=='POST' and route==PREFIX+'/checks':
191
+ if not isinstance(body,dict) or not isinstance(body.get('action'),str):
192
+ raise ContractError('check request required')
193
+ from .request_contract import validate_request
194
+ request=validate_request(body)
195
+ if request['action']!='check':raise ContractError('checks only accept action=check')
196
+ return 200,self.check(subject,request)
197
+ source=re.fullmatch(re.escape(PREFIX)+r'/sources/(previews|confirmations|installations|publications)',route)
198
+ if source and method=='POST':
199
+ if not isinstance(body,dict):raise ContractError('source request required')
200
+ # The shared source-reuse channel is a DPV1 reuse surface; DPV2
201
+ # keeps server-side reuse closed. The old action face stays mapped
202
+ # so callers get the defined structured status instead of a silent
203
+ # ignore or a fabricated success. Nothing is published or shared.
204
+ return 200,{'ok':False,'event':'tpdk_source','job_status':'FAILED','adaptation_started':False,
205
+ 'error':{'code':'SOURCE_REUSE_UNAVAILABLE',
206
+ 'message':'DPV2 未提供公共工艺源复用通道(服务器端工艺复用保持关闭);'
207
+ '请直接以 --action start --vendor-dir 发起新适配。'}}
157
208
  if method=='POST' and route==PREFIX+'/jobs':
158
209
  if not isinstance(body,dict) or set(body)!={'workstation_id','request'}:raise ContractError('workstation_id and request required')
159
210
  self.workstation(subject,body['workstation_id']);worker=self.worker()