@runeditrun/rer 0.2.21 → 0.2.23

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 (72) hide show
  1. package/cli/README.md +26 -0
  2. package/cli/bounded.mjs +5 -1
  3. package/cli/delivery-declarations.mjs +2 -2
  4. package/cli/demo-host.mjs +5 -5
  5. package/cli/deploy-command.mjs +2 -2
  6. package/cli/deploy-inputs.mjs +4 -1
  7. package/cli/deploy.mjs +7 -3
  8. package/cli/deployment-record.mjs +52 -0
  9. package/cli/export.mjs +1 -1
  10. package/cli/local.mjs +11 -3
  11. package/cli/managed-server.mjs +7 -3
  12. package/cli/output.mjs +1 -1
  13. package/cli/production-auth.mjs +7 -13
  14. package/cli/production-mail.mjs +72 -0
  15. package/cli/signin.mjs +11 -6
  16. package/global/CHANGELOG.md +9 -0
  17. package/modules/container/README.md +18 -3
  18. package/modules/container/build.mjs +8 -12
  19. package/modules/container/host.mjs +9 -4
  20. package/modules/container/ingress.mjs +15 -4
  21. package/modules/container/migration-inventory.mjs +33 -0
  22. package/modules/container/migrations.mjs +16 -2
  23. package/modules/container/websockets.mjs +54 -0
  24. package/modules/container/worker-engine.mjs +2 -2
  25. package/modules/delivery-producer/migrations.mjs +61 -0
  26. package/modules/demo/README.md +4 -0
  27. package/modules/demo/effects.mjs +4 -0
  28. package/modules/demo/label.mjs +7 -4
  29. package/modules/demo/responses.mjs +1 -1
  30. package/modules/demo-host/README.md +32 -19
  31. package/modules/demo-host/capacity.mjs +3 -3
  32. package/modules/demo-host/container.mjs +65 -37
  33. package/modules/demo-host/pages.mjs +1 -1
  34. package/modules/demo-host/plan.mjs +19 -6
  35. package/modules/demo-host/remove.mjs +9 -7
  36. package/modules/demo-host/start-script.mjs +10 -1
  37. package/modules/demo-host/startup.mjs +4 -2
  38. package/modules/demo-host/worker.mjs +28 -7
  39. package/modules/dependencies/approval.mjs +3 -2
  40. package/modules/dependencies/index.mjs +2 -2
  41. package/modules/deploy-kit/README.md +4 -2
  42. package/modules/deploy-kit/diagnostics.mjs +9 -0
  43. package/modules/deploy-kit/owner-signin.mjs +1 -1
  44. package/modules/deploy-kit/provider-transport.mjs +56 -0
  45. package/modules/deploy-kit/provider.mjs +22 -20
  46. package/modules/mail/README.md +14 -5
  47. package/modules/mail/src/adapters/rer/contract.mjs +33 -5
  48. package/modules/mail/src/adapters/rer/index.mjs +4 -1
  49. package/modules/mail/src/core/transport.mjs +9 -3
  50. package/modules/operator-auth/README.md +9 -0
  51. package/modules/operator-auth/accounts/credentials.mjs +2 -2
  52. package/modules/operator-auth/accounts/email-change.mjs +2 -2
  53. package/modules/operator-auth/accounts/provider-control.mjs +3 -3
  54. package/modules/operator-auth/accounts/store.mjs +9 -8
  55. package/modules/operator-auth/dev/cli-session.mjs +5 -4
  56. package/modules/operator-auth/dev/index.mjs +5 -5
  57. package/modules/operator-auth/dev-gate.mjs +4 -2
  58. package/modules/operator-auth/identity/email-link/index.mjs +7 -1
  59. package/modules/operator-auth/signin/index.mjs +10 -2
  60. package/onboarding/adapter.mjs +11 -3
  61. package/onboarding/local/operation.mjs +4 -2
  62. package/onboarding/local/owner.mjs +9 -3
  63. package/onboarding/local/state-files.mjs +17 -0
  64. package/onboarding/operator-installer.mjs +2 -2
  65. package/onboarding/operator-migrations.mjs +48 -0
  66. package/onboarding/process-diagnostics.mjs +25 -5
  67. package/onboarding/process-table.mjs +45 -19
  68. package/package.json +1 -1
  69. package/scripts/publish-check/README.md +5 -2
  70. package/scripts/publish-check/content_identities.py +1 -1
  71. package/scripts/publish-check/json_identity.py +10 -1
  72. package/scripts/publish-check/public_hygiene.py +30 -4
@@ -0,0 +1,48 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { readFile, readdir, unlink } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { DatabaseSync } from 'node:sqlite';
5
+ import { privateDirectory, writePrivateFile } from './private-files.mjs';
6
+ import { selectLocalState } from './local/state.mjs';
7
+ import { labels } from './adapter-labels.mjs';
8
+
9
+ async function appliedNames(state, table) {
10
+ const directory = join(state, 'v3/d1/miniflare-D1DatabaseObject'), names = new Set();
11
+ let files;
12
+ try { files = await readdir(directory); } catch (error) { if (error.code === 'ENOENT') return names; throw error; }
13
+ for (const file of files.filter(name => name.endsWith('.sqlite'))) {
14
+ const db = new DatabaseSync(join(directory, file), { readOnly: true });
15
+ try {
16
+ if (db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table)) {
17
+ for (const row of db.prepare(`SELECT name FROM "${table.replaceAll('"', '""')}"`).all()) names.add(row.name);
18
+ }
19
+ } finally { db.close(); }
20
+ }
21
+ return names;
22
+ }
23
+
24
+ // Vite's last build copied only the migrations that existed then. Keep its D1
25
+ // identity, but give Wrangler the complete current source inventory, including
26
+ // files just acquired by git pull. The temporary config contains no app vars.
27
+ export async function migrateOperator(context, database) {
28
+ const { root, demo, store } = context;
29
+ const config = JSON.parse(await readFile(join(root, 'dist/server/wrangler.json'), 'utf8'));
30
+ const binding = config.d1_databases?.find(item => item.database_name === database || item.binding === database);
31
+ if (!binding) throw new Error(`Local migration database ${database} is missing from the built configuration. Run rer setup.`);
32
+ const state = resolve(root, demo?.state ?? await selectLocalState(root));
33
+ const inventory = resolve(root, 'migrations/core');
34
+ const names = (await readdir(inventory)).filter(name => name.endsWith('.sql')).sort();
35
+ const table = binding.migrations_table ?? 'd1_migrations';
36
+ const before = await appliedNames(state, table);
37
+ const directory = await privateDirectory(root, ['.rer', 'local']);
38
+ const path = join(directory, `migrations-${randomUUID()}.json`);
39
+ await writePrivateFile(path, JSON.stringify({ name: config.name, compatibility_date: config.compatibility_date,
40
+ d1_databases: [{ ...binding, migrations_dir: inventory, migrations_pattern: `${inventory}/*.sql` }] }));
41
+ try {
42
+ await context.run(labels.migrate, 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database,
43
+ '--local', '--persist-to', state, '--config', path], { step: 'setup' });
44
+ const after = await appliedNames(state, table);
45
+ const applied = names.filter(name => !before.has(name) && after.has(name));
46
+ if (applied.length) store.report(`Applied local migrations: ${applied.join(', ')}`);
47
+ } finally { await unlink(path); }
48
+ }
@@ -6,14 +6,15 @@ import {homedir} from 'node:os';
6
6
  import {isIP} from 'node:net';
7
7
  import {setTimeout as delay} from 'node:timers/promises';
8
8
  import {commandFailure,approvedFailure} from './failures.mjs';
9
+ import {stateFiles} from './local/state-files.mjs';
9
10
  const exec=promisify(execFile);
10
11
  // macOS supplies lsof in /usr/sbin, which a command PATH may omit.
11
12
  // Diagnose sockets with the system utility even when that PATH is constrained.
12
13
  const lsof=process.platform==='darwin'?'/usr/sbin/lsof':'lsof';
13
14
  // One monotonic budget covers every command in an ownership decision.
14
- export const inspectionContext=(details={})=>({deadline:performance.now()+15000,...details});
15
+ export const inspectionContext=({budgetMs=15000,...details}={})=>({deadline:performance.now()+budgetMs,budgetMs,...details});
15
16
  export const uncheckedInspection=error=>approvedFailure(error)?.ownershipUnchecked===true;
16
- const run=async(command,args,context=inspectionContext(),{maxBuffer=1024*1024,noMatch=false}={})=>{
17
+ const run=async(command,args,context=inspectionContext(),{maxBuffer=1024*1024,noMatch=false,positiveResult}={})=>{
17
18
  const invocation=[command,...args].join(' ').replaceAll(homedir(),'~');
18
19
  let failure;
19
20
  for(let attempt=0;attempt<2;attempt++){
@@ -22,6 +23,9 @@ const run=async(command,args,context=inspectionContext(),{maxBuffer=1024*1024,no
22
23
  const timeout=attempt===0?Math.min(3000,remaining):remaining;
23
24
  try{return (await exec(command,args,{timeout,maxBuffer})).stdout;}
24
25
  catch(error){
26
+ // A selected state file positively observed before a timeout still has a
27
+ // holder. Partial output can never establish the absence of a holder.
28
+ if(typeof error.stdout==='string'&&positiveResult?.(error.stdout))return error.stdout;
25
29
  // A quiet lsof exit 1 means no match, including a selected PID exiting
26
30
  // while other selected PIDs still return records. Diagnostic output instead
27
31
  // means inspection failed, even if lsof also returned partial records.
@@ -31,7 +35,7 @@ const run=async(command,args,context=inspectionContext(),{maxBuffer=1024*1024,no
31
35
  }
32
36
  const subject=context.port?`who uses port ${context.port}`:'local process ownership';
33
37
  const cause=failure?.startsWith('timed out')||performance.now()>=context.deadline?'in time (system busy)':'because the system process check failed';
34
- throw commandFailure(`Could not check ${subject} ${cause}. Run rer ${context.verb??'dev'} again. No other owner was identified.\nOwnership check: ${invocation} ${failure??'total inspection deadline exhausted'} (at most 2 attempts; shared total bound 15000 ms).`,{ownershipUnchecked:true});
38
+ throw commandFailure(`Could not check ${subject} ${cause}. Run rer ${context.verb??'dev'} again. No other owner was identified.\nOwnership check: ${invocation} ${failure??'total inspection deadline exhausted'} (at most 2 attempts; shared total bound ${context.budgetMs??15000} ms).`,{ownershipUnchecked:true});
35
39
  };
36
40
 
37
41
  export async function processName(pid,context=inspectionContext()){
@@ -46,6 +50,7 @@ function records(text,socketTypes=false){
46
50
  let record,family;const rows=[];
47
51
  for(const line of text.split('\n')){
48
52
  if(line[0]==='p'){record={pid:Number(line.slice(1)),names:[],...(socketTypes?{sockets:[]}: {})};family=undefined;rows.push(record);}
53
+ else if(line[0]==='c'&&record)record.command=basename(line.slice(1)).replace(/[^a-zA-Z0-9._-]/g,'').slice(0,80);
49
54
  else if(line[0]==='f')family=undefined;
50
55
  else if(line[0]==='t')family=['IPv4','IPv6'].includes(line.slice(1))?line.slice(1):undefined;
51
56
  else if(line[0]==='n'&&record){const name=line.slice(1);record.names.push(name);if(socketTypes)record.sockets.push({name,family});}
@@ -192,8 +197,23 @@ export async function localProcessConflict(root,savedOrigin,context=inspectionCo
192
197
  let held;
193
198
  if(hasState){
194
199
  if(process.platform==='linux'){for(const pid of await linuxPids())if(!lineage.has(pid)&&(await descriptors(pid)).some(path=>path.startsWith(state+'/'))){held={pid};break;}}
195
- else held=records(await run(lsof,['-nP','-b','-w','-Fpn'],context,{maxBuffer:16*1024*1024})).find(row=>!lineage.has(row.pid)&&row.names.some(path=>path.startsWith(state+'/')));
196
- if(held)return {pid:held.pid,command:await processName(held.pid,context),reason:'the canonical local state'};
200
+ else {
201
+ const files=await stateFiles(state);
202
+ // Path selection needs stat, so -b (which skips stat) is inappropriate here.
203
+ // No system-wide open-file output, and no query at all for empty state.
204
+ if(files.length){
205
+ const budgetMs=context.verb==='dev'?3000:context.budgetMs??15000;
206
+ const stateContext=inspectionContext({verb:context.verb,budgetMs,deadline:Math.min(context.deadline,performance.now()+budgetMs)});
207
+ const holder=text=>records(text).find(row=>!lineage.has(row.pid)&&row.names.some(path=>path.startsWith(state+'/')));
208
+ held=holder(await run(lsof,['-nP','-w','-Fpcn','--',...files],stateContext,{positiveResult:holder}));
209
+ }
210
+ }
211
+ if(held){
212
+ // A slow optional label cannot discard a positively observed holder.
213
+ let command=held.command;
214
+ if(!command)try{command=await processName(held.pid,context);}catch(error){if(!uncheckedInspection(error))throw error;}
215
+ return {pid:held.pid,command:command||'process',reason:'the canonical local state'};
216
+ }
197
217
  }
198
218
  let all;
199
219
  try{all=await listeners(undefined,context);}
@@ -7,6 +7,21 @@ const execute = promisify(execFile)
7
7
  // One bounded wait for any process inspection; a loaded machine can take over a
8
8
  // second to list processes, which must not abort an otherwise healthy cleanup.
9
9
  export const inspectionMs = 5000
10
+ // A snapshot taken while processes start or exit can hold a row ps has not yet
11
+ // finished, or ps itself can fail for an instant. Such a read says nothing
12
+ // about ownership; it is repeated within the same bound rather than ending a
13
+ // launch whose own processes are accounted for.
14
+ const transient = (message) => Object.assign(new Error(message), { transient: true })
15
+ const retryMs = 10
16
+ async function withinBound(timeout, attempt) {
17
+ const deadline = Date.now() + timeout
18
+ for (;;) {
19
+ try { return await attempt(Math.max(1, deadline - Date.now())) } catch (error) {
20
+ if (!error.transient || Date.now() + retryMs >= deadline) throw error
21
+ await delay(retryMs)
22
+ }
23
+ }
24
+ }
10
25
  export const validPid = (pid) => Number.isSafeInteger(pid) && pid > 0 && pid <= 0x7fffffff
11
26
 
12
27
  // Inspect numeric identity and the executable name, never private argv.
@@ -60,20 +75,23 @@ async function processGroup(pgid, signal) {
60
75
  }
61
76
  return group
62
77
  }
63
- const { stdout } = await execute('/bin/ps', [
64
- '-ax', '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=',
65
- ], { env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, signal, killSignal: 'SIGKILL', maxBuffer: 8 * 1024 * 1024 })
78
+ let stdout
79
+ try {
80
+ ({ stdout } = await execute('/bin/ps', [
81
+ '-ax', '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=',
82
+ ], { env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, signal, killSignal: 'SIGKILL', maxBuffer: 8 * 1024 * 1024 }))
83
+ } catch (error) { if (signal.aborted) throw error; throw transient('Could not read process identities.') }
66
84
  const group = []
67
85
  for (const line of stdout.split('\n').filter((line) => line.trim())) {
68
86
  const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.{24})\s*$/)
69
- if (!match) throw new Error('Could not read process identities.')
87
+ if (!match) throw transient('Could not read process identities.')
70
88
  const [, id, parent, groupId, uid, state, birth] = match
71
89
  const pid = Number(id)
72
90
  const ppid = Number(parent)
73
91
  if (pgid === undefined && (pid === 0 || Number(groupId) === 0)) continue
74
92
  if (pgid !== undefined && Number(groupId) !== pgid) continue
75
93
  if (!validPid(pid) || !validPid(Number(groupId)) || !Number.isSafeInteger(ppid) || ppid < 0 || !Number.isFinite(Date.parse(birth))) {
76
- throw new Error('Invalid process identity.')
94
+ throw transient('Invalid process identity.')
77
95
  }
78
96
  group.push({ pid, ppid, pgid: Number(groupId), uid: Number(uid), state, birth })
79
97
  }
@@ -86,30 +104,38 @@ async function processGroup(pgid, signal) {
86
104
  export async function readProcessIdentity(pid, timeout = inspectionMs) {
87
105
  if (!validPid(pid) || !(timeout > 0)) throw new Error('Invalid process identity deadline.')
88
106
  if (process.platform === 'linux') return linuxProcess(pid, undefined, AbortSignal.timeout(timeout))
107
+ return withinBound(timeout, (remaining) => psIdentity(pid, remaining))
108
+ }
109
+
110
+ async function psIdentity(pid, timeout) {
89
111
  let stdout
90
112
  try {
91
113
  ({ stdout } = await execute('/bin/ps', ['-p', String(pid), '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=', '-o', 'comm='],
92
114
  { env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, timeout, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024 }))
93
- } catch (error) { if (error.code === 1 && !error.stdout?.trim()) return; throw new Error('Could not inspect process identity.') }
115
+ } catch (error) { if (error.code === 1 && !error.stdout?.trim()) return; throw transient('Could not inspect process identity.') }
94
116
  const match = stdout.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.{24})\s+(.+?)\s*$/)
95
- if (!match) throw new Error('Invalid process identity.')
117
+ if (!match) throw transient('Invalid process identity.')
96
118
  const [, id, parent, groupId, uid, state, birth, command] = match
97
- if (Number(id) !== pid || !validPid(Number(groupId)) || !Number.isFinite(Date.parse(birth + ' UTC'))) throw new Error('Invalid process identity.')
119
+ if (Number(id) !== pid || !validPid(Number(groupId)) || !Number.isFinite(Date.parse(birth + ' UTC'))) throw transient('Invalid process identity.')
98
120
  return { pid, ppid: Number(parent), pgid: Number(groupId), uid: Number(uid), state, birth, command }
99
121
  }
100
122
 
101
- export async function readProcessTable(timeout = inspectionMs, pgid) {
123
+ // `read` is the process edge: it returns the table or throws; tests supply a
124
+ // failing one.
125
+ export async function readProcessTable(timeout = inspectionMs, pgid, read = processGroup) {
102
126
  if (!(timeout > 0)) throw new Error('Process inspection deadline expired.')
103
- const controller = new AbortController()
104
- let timer
105
- try {
106
- return await Promise.race([processGroup(pgid, controller.signal), new Promise((_, reject) => {
107
- timer = setTimeout(() => {
108
- controller.abort()
109
- reject(new Error('Process inspection deadline expired.'))
110
- }, timeout)
111
- })])
112
- } finally { clearTimeout(timer) }
127
+ return withinBound(timeout, async (remaining) => {
128
+ const controller = new AbortController()
129
+ let timer
130
+ try {
131
+ return await Promise.race([read(pgid, controller.signal), new Promise((_, reject) => {
132
+ timer = setTimeout(() => {
133
+ controller.abort()
134
+ reject(new Error('Process inspection deadline expired.'))
135
+ }, remaining)
136
+ })])
137
+ } finally { clearTimeout(timer) }
138
+ })
113
139
  }
114
140
 
115
141
  export const sameBirth = (left, right) => validPid(left?.pid) && left.pid === right?.pid && left.birth === right?.birth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -63,8 +63,11 @@ public report. Authoring's integrity checks remain unchanged.
63
63
  against every declared file's bytes and regular-file mode in the same scanned
64
64
  tree. Historical matches use only that commit's blobs; present files cannot
65
65
  rescue a historical mismatch. Working-tree preimages reject linked paths.
66
- Only the exact native match at a proved inventory field is classified. There
67
- is no filename, hash-value or comma-delimited credential exemption.
66
+ Copy records use the same proof at custom JSON paths.
67
+ The captured secret must occur unambiguously inside the exact proved JSON value;
68
+ a native fragment ending partway through a digest qualifies too. The same value
69
+ in another field remains a finding. There is no filename, hash-value or
70
+ comma-delimited credential exemption.
68
71
 
69
72
  `checksum_maps.py` classifies a file-name to digest map (`'0005_operator_auth.sql':
70
73
  '<sha256>'`, in JSON, JavaScript, YAML or similar) in any file outside the
@@ -24,7 +24,7 @@ class ContentIdentities:
24
24
  pointers = set(module_pins(path, document.value))
25
25
  pointers.update(source_pointers(path, document.value))
26
26
  pointers.update(controller_pointers(document.value))
27
- if path in ('base-copies.json', 'base/PROVENANCE.json') and read_regular is not None:
27
+ if read_regular is not None:
28
28
  pointers.update(copy_pointers(document.value, read_regular))
29
29
  self.allowed[path] = pointers
30
30
 
@@ -67,13 +67,22 @@ class Document:
67
67
  def matches(self, hit, pointers):
68
68
  if hit.get('RuleID') not in ('generic-api-key', 'hex-api-key'):
69
69
  return False
70
+ secret = hit.get('Secret', '').encode('utf-8')
71
+ if not secret:
72
+ return False
70
73
  located = set()
71
74
  for left, right in match_spans(self.data, hit):
75
+ start = self.data.find(secret, left, right)
76
+ if start < 0 or self.data.find(secret, start + 1, right) >= 0:
77
+ continue
72
78
  for pointer in pointers:
73
79
  span = self.spans.get(pointer)
74
80
  if span:
75
81
  a, b, value = span
76
- if (left <= a + 1 and b - 1 <= right and hit.get('Secret') == value
82
+ # Native fragments can truncate a digest capture. Bind the
83
+ # captured secret's bytes, including a partial capture, to
84
+ # this exact unescaped JSON value.
85
+ if (a + 1 <= start and start + len(secret) <= b - 1
77
86
  and self.data[a + 1:b - 1] == value.encode('ascii')):
78
87
  located.add((a, b))
79
88
  return len(located) == 1
@@ -12,11 +12,12 @@ from png_text import text_chunks
12
12
  from media import sample_spans
13
13
  from c2pa import certificate_spans
14
14
  URI_AUTHORITY = re.compile(r'''//(?P<authority>[^/?#\s<>"']+)''')
15
+ ACTION_REFERENCE = re.compile(r'''uses:\s*["']?[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+@[^\s"']+''')
15
16
  SCHEME_CHARACTERS = frozenset('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-')
16
17
  # Match raw, complete commit trailer lines; decoded or embedded prose cannot
17
18
  # acquire trailer privileges. Only the address span is omitted from email checks.
18
19
  COAUTHOR = re.compile(
19
- rb'^Co-Authored-By:[ \t]+[^<>\r\n]*[^<>\s][ \t]+<(?P<address>'
20
+ rb'^Co-Authored-By:[ \t]+(?=[^ \t])[^<>\r\n]*[^<>\s][ \t]+<(?P<address>'
20
21
  rb'noreply@(?:anthropic|github)\.com|'
21
22
  rb'[0-9]+\+[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}@users\.noreply\.github\.com'
22
23
  rb')>[ \t]*\r?$', re.I | re.M)
@@ -27,7 +28,7 @@ def without_public_coauthor_addresses(data):
27
28
  # A quoted attribution followed by ordinary prose stays ordinary body text.
28
29
  tail = data.rstrip(b' \t\r\n')
29
30
  block = re.split(rb'\r?\n[ \t]*\r?\n', tail)[-1]
30
- if not all(re.fullmatch(rb'[A-Za-z0-9-]+:[ \t]+[^\r\n]+\r?', line)
31
+ if not all(re.fullmatch(rb'[A-Za-z0-9-]+:[ \t][^\r\n]+\r?', line)
31
32
  for line in block.split(b'\n')):
32
33
  return data
33
34
  offset = len(tail) - len(block)
@@ -74,11 +75,36 @@ def private_emails(text, config):
74
75
  email_text = re.sub(r'(?i)\b(?a:git@github\.com:)(?=[A-Za-z0-9]|\$\{[A-Za-z_$][A-Za-z0-9_.$]*\})', '', email_text)
75
76
  # A package manager's patch filename joins the name and version with an at sign.
76
77
  version = r'(?:v?[0-9]+(?:\.[0-9]+)*(?:-[A-Za-z0-9-]+)?|[a-f0-9]{40})(?:\.patch)?(?![A-Za-z0-9_.-])'
77
- email_text = re.sub(r'(?m)^\s*-?\s*uses:\s*[\"\']?[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+@[^\s\"\']+', '', email_text)
78
- email_text = re.sub(r'(?<![A-Za-z0-9])(?:@[A-Za-z0-9_.-]+/)?[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)?@' + version, '', email_text)
78
+ email_text = without_action_references(email_text)
79
+ # Only the first character of a package token can change the outcome.
80
+ # Keep the outer boundary for scopes preceded by punctuation (x.@scope/pkg).
81
+ email_text = re.sub(r'(?<![A-Za-z0-9])(?:@[A-Za-z0-9_.-]+/)?(?<![A-Za-z0-9_.-])[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)?@' + version, '', email_text)
79
82
  return [match.group() for match in EMAIL.finditer(email_text) if not public_email(match.group(), config)]
80
83
 
81
84
 
85
+ def without_action_references(text):
86
+ pieces, offset = [], 0
87
+ for match in ACTION_REFERENCE.finditer(text):
88
+ # Locate the literal first, then walk each whitespace gap once. A
89
+ # multiline ^\s*-?\s* retries and repartitions long blank-line runs.
90
+ start = match.start()
91
+ while start > offset and text[start - 1].isspace():
92
+ start -= 1
93
+ if start > offset and text[start - 1] == '-':
94
+ start -= 1
95
+ while start > offset and text[start - 1].isspace():
96
+ start -= 1
97
+ if start > 0 and text[start - 1] != '\n':
98
+ newline = text.find('\n', start, match.start())
99
+ if newline < 0:
100
+ continue
101
+ start = newline + 1
102
+ pieces.append(text[offset:start])
103
+ offset = match.end()
104
+ pieces.append(text[offset:])
105
+ return ''.join(pieces)
106
+
107
+
82
108
  # A stored host name is lower case, upper case or capitalised, label by label.
83
109
  # Bytes that merely decode to text, such as compressed pixels, rarely are.
84
110
  HOST_LABEL = re.compile(r'(?:[a-z0-9-]+|[A-Z0-9-]+|[A-Z][a-z0-9-]*)')