@foggy-projects/deepseek-harness-plugin 0.4.2-rc.3 → 0.4.4-rc.1

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 (52) hide show
  1. package/README.md +222 -173
  2. package/THIRD-PARTY-RUNTIME-NOTICES.md +16 -16
  3. package/cordis.patch.yml +6 -6
  4. package/docs/COMMUNITY-MARKETPLACES.md +64 -64
  5. package/docs/PUBLIC-BETA-READINESS.md +109 -109
  6. package/docs/RELEASE-CANDIDATE-0.4.0-RC.2.md +38 -38
  7. package/docs/RELEASE-CANDIDATE-0.4.0-RC.3.md +18 -18
  8. package/docs/RELEASE-CANDIDATE-0.4.1-DSH-0.1.5-RC.1.md +60 -60
  9. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.1.md +62 -62
  10. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.2.md +50 -50
  11. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.3.md +34 -34
  12. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.4.md +32 -0
  13. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.5.md +27 -0
  14. package/docs/RELEASE-CANDIDATE-0.4.3-DSH-0.2.0-RC.1.md +96 -0
  15. package/docs/RELEASE-CANDIDATE-0.4.4-DSH-0.2.1-RC.1.md +135 -0
  16. package/docs/WINDOWS-BETA-ACCEPTANCE.md +113 -113
  17. package/experience/linux/README.md +53 -53
  18. package/experience/linux/prepare.sh +2 -2
  19. package/lib/atomic-json.js +41 -41
  20. package/lib/client.js +1222 -906
  21. package/lib/component-manager.js +164 -0
  22. package/lib/component-releases.js +363 -0
  23. package/lib/diagnostics.js +86 -86
  24. package/lib/index.js +764 -698
  25. package/lib/operation-lock.js +139 -0
  26. package/lib/python-runtime.js +339 -339
  27. package/lib/query-tool.js +134 -104
  28. package/lib/remote-descriptor.js +74 -59
  29. package/lib/remote.js +8 -8
  30. package/lib/runtime-settings.js +89 -89
  31. package/lib/skill-provider.js +116 -116
  32. package/lib/typert.js +9 -9
  33. package/lib/version.js +20 -20
  34. package/lib/viewer-preview.js +44 -27
  35. package/package.json +25 -15
  36. package/skills/foggy-deepseek-onboarding/SKILL.md +149 -143
  37. package/skills/foggy-deepseek-onboarding/assets/connection.schema.json +48 -48
  38. package/skills/foggy-deepseek-onboarding/assets/datasource.example.json +14 -14
  39. package/skills/foggy-deepseek-onboarding/assets/env.example +14 -14
  40. package/skills/foggy-deepseek-onboarding/assets/onboarding-state.schema.json +71 -71
  41. package/skills/foggy-deepseek-onboarding/assets/semantic-plan.example.json +8 -8
  42. package/skills/foggy-deepseek-onboarding/assets/semantic-plan.schema.json +21 -21
  43. package/skills/foggy-deepseek-onboarding/assets/versions.json +23 -23
  44. package/skills/foggy-deepseek-onboarding/references/onboarding-workflow.md +168 -168
  45. package/skills/foggy-deepseek-onboarding/scripts/doctor.ps1 +4 -4
  46. package/skills/foggy-deepseek-onboarding/scripts/install.ps1 +4 -4
  47. package/skills/foggy-deepseek-onboarding/scripts/invoke-onboarding.ps1 +32 -32
  48. package/skills/foggy-deepseek-onboarding/scripts/onboard.ps1 +4 -4
  49. package/skills/foggy-deepseek-onboarding/scripts/onboarding.py +3721 -3681
  50. package/skills/foggy-deepseek-onboarding/scripts/runtime-start.ps1 +4 -4
  51. package/skills/foggy-deepseek-onboarding/scripts/runtime-stop.ps1 +4 -4
  52. package/skills/foggy-deepseek-onboarding/scripts/uninstall.ps1 +4 -4
@@ -0,0 +1,139 @@
1
+ import { randomUUID } from 'node:crypto'
2
+ import { lstat, mkdir, readFile, readdir, unlink } from 'node:fs/promises'
3
+ import { join } from 'node:path'
4
+ import { writeJsonAtomic } from './atomic-json.js'
5
+
6
+ const SCHEMA = 'foggy-managed-operation-lock/v1'
7
+ const UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
8
+
9
+ export class ManagedOperationBusyError extends Error {
10
+ constructor(owner = null, initializing = false) {
11
+ const detail = owner?.operationKind ? ` (${owner.operationKind})` : ''
12
+ super(initializing
13
+ ? 'Another Foggy operation is initializing, or its operation-lock metadata is incomplete. Wait for it to finish before trying again.'
14
+ : `Another Foggy operation${detail} is running in a different Harness process. Wait for it to finish before trying again.`)
15
+ this.name = 'ManagedOperationBusyError'
16
+ this.code = 'FOGGY_OPERATION_RUNNING'
17
+ this.ownerPID = owner?.ownerPID ?? null
18
+ this.operationKind = owner?.operationKind ?? null
19
+ }
20
+ }
21
+
22
+ export function managedOperationLockDirectory(dataRoot) {
23
+ return join(dataRoot, 'operation-locks')
24
+ }
25
+
26
+ function processAlive(pid) {
27
+ try {
28
+ process.kill(pid, 0)
29
+ return true
30
+ } catch (error) {
31
+ // Lack of permission is not evidence that a process has stopped.
32
+ return error?.code !== 'ESRCH'
33
+ }
34
+ }
35
+
36
+ function entryName(owner) {
37
+ return `owner-${owner.ownerPID}-${owner.token}.json`
38
+ }
39
+
40
+ function validOwner(owner, name) {
41
+ return owner?.schemaVersion === SCHEMA
42
+ && Number.isInteger(owner.ownerPID) && owner.ownerPID > 0 && owner.ownerPID <= 2147483647
43
+ && typeof owner.token === 'string' && UUID.test(owner.token)
44
+ && entryName(owner) === name
45
+ && typeof owner.createdAt === 'string' && Number.isFinite(Date.parse(owner.createdAt))
46
+ && typeof owner.operationKind === 'string' && owner.operationKind.length <= 100
47
+ && (owner.phase === 'choosing' || (owner.phase === 'waiting' && typeof owner.ticket === 'string' && /^[1-9]\d{0,39}$/.test(owner.ticket)))
48
+ }
49
+
50
+ async function readOwner(directory, name) {
51
+ try {
52
+ const path = join(directory, name)
53
+ const info = await lstat(path)
54
+ if (!info.isFile() || info.isSymbolicLink() || info.size > 8192) throw new ManagedOperationBusyError(null, true)
55
+ const owner = JSON.parse(await readFile(path, 'utf8'))
56
+ if (!validOwner(owner, name)) throw new ManagedOperationBusyError(null, true)
57
+ return owner
58
+ } catch (error) {
59
+ if (error?.code === 'ENOENT') return null
60
+ if (error instanceof ManagedOperationBusyError) throw error
61
+ throw new ManagedOperationBusyError(null, true)
62
+ }
63
+ }
64
+
65
+ async function owners(directory, self, isProcessAlive) {
66
+ const result = []
67
+ for (const name of await readdir(directory)) {
68
+ // Atomic JSON staging files are never published lock owners.
69
+ if (!name.endsWith('.json')) continue
70
+ if (name === entryName(self)) continue
71
+ const owner = await readOwner(directory, name)
72
+ if (!owner) continue
73
+ if (!isProcessAlive(owner.ownerPID)) {
74
+ // Each contender owns a unique UUID path. Removing a dead contender cannot
75
+ // remove a new owner's file, even if several processes recover it at once.
76
+ try { await unlink(join(directory, name)) } catch (error) { if (error?.code !== 'ENOENT') throw error }
77
+ continue
78
+ }
79
+ result.push(owner)
80
+ }
81
+ return result
82
+ }
83
+
84
+ function precedes(left, right) {
85
+ const leftTicket = BigInt(left.ticket)
86
+ const rightTicket = BigInt(right.ticket)
87
+ return leftTicket < rightTicket || (leftTicket === rightTicket && left.token < right.token)
88
+ }
89
+
90
+ async function release(directory, owner) {
91
+ const name = entryName(owner)
92
+ const saved = await readOwner(directory, name)
93
+ if (saved?.token !== owner.token || saved?.ownerPID !== owner.ownerPID) return
94
+ try { await unlink(join(directory, name)) } catch (error) { if (error?.code !== 'ENOENT') throw error }
95
+ }
96
+
97
+ /**
98
+ * Nonblocking cross-process lock for the user's managed component roots.
99
+ *
100
+ * A file-based bakery ticket avoids deleting/replacing a shared owner file or
101
+ * an empty directory during initialization. Every owner is fully written and
102
+ * atomically published before it chooses a ticket. Dead processes leave only
103
+ * their unique UUID file, which subsequent contenders can safely remove.
104
+ */
105
+ export async function withManagedOperationLock(dataRoot, action, {
106
+ kind = 'managed-operation',
107
+ isProcessAlive = processAlive,
108
+ now = Date.now,
109
+ } = {}) {
110
+ if (typeof dataRoot !== 'string' || !dataRoot) throw new TypeError('dataRoot is required')
111
+ if (typeof action !== 'function') throw new TypeError('action must be a function')
112
+ const directory = managedOperationLockDirectory(dataRoot)
113
+ const owner = {
114
+ schemaVersion: SCHEMA,
115
+ ownerPID: process.pid,
116
+ token: randomUUID(),
117
+ createdAt: new Date(now()).toISOString(),
118
+ operationKind: String(kind).slice(0, 100),
119
+ phase: 'choosing',
120
+ }
121
+ await mkdir(directory, { recursive: true })
122
+ const path = join(directory, entryName(owner))
123
+ try {
124
+ await writeJsonAtomic(path, owner)
125
+ const contenders = await owners(directory, owner, isProcessAlive)
126
+ const largest = contenders.reduce((ticket, other) => other.phase === 'waiting' && BigInt(other.ticket) > ticket ? BigInt(other.ticket) : ticket, 0n)
127
+ owner.ticket = (largest + 1n).toString()
128
+ owner.phase = 'waiting'
129
+ await writeJsonAtomic(path, owner)
130
+ for (const other of await owners(directory, owner, isProcessAlive)) {
131
+ if (other.phase === 'choosing' || precedes(other, owner)) {
132
+ throw new ManagedOperationBusyError(other, other.phase === 'choosing')
133
+ }
134
+ }
135
+ return await action()
136
+ } finally {
137
+ await release(directory, owner)
138
+ }
139
+ }