kinfold 0.0.1-bootstrap.0 → 0.2.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.
Files changed (3) hide show
  1. package/bin/kinfold.js +135 -0
  2. package/package.json +20 -4
  3. package/README.md +0 -3
package/bin/kinfold.js ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env node
2
+ // The npm entry point for Kinfold. One native program per platform is too large
3
+ // for a single package, so npm installs @kinfold/cli-<platform>-<arch> beside
4
+ // this file, and this launcher starts the program in it. Only node: builtins are
5
+ // used, and the file is CommonJS, so Node 18 and Bun both run it with no
6
+ // dependencies.
7
+
8
+ 'use strict'
9
+
10
+ const { spawnSync } = require('node:child_process')
11
+ const { accessSync, chmodSync, constants, existsSync } = require('node:fs')
12
+ const { dirname, join } = require('node:path')
13
+
14
+ /** npm's platform and architecture names, beside the package that carries each program. */
15
+ const PACKAGES = {
16
+ 'darwin-arm64': '@kinfold/cli-darwin-arm64',
17
+ 'darwin-x64': '@kinfold/cli-darwin-x64',
18
+ 'linux-x64': '@kinfold/cli-linux-x64',
19
+ 'linux-arm64': '@kinfold/cli-linux-arm64',
20
+ 'win32-x64': '@kinfold/cli-windows-x64',
21
+ }
22
+
23
+ const SUPPORTED = 'macOS (arm64, x64), Linux glibc (x64, arm64), Windows x64'
24
+
25
+ function packageName(platform, arch) {
26
+ return PACKAGES[`${platform}-${arch}`] ?? null
27
+ }
28
+
29
+ /** The musl loaders, which exist on Alpine-style systems and not on glibc ones. */
30
+ const MUSL_LOADERS = ['/lib/ld-musl-x86_64.so.1', '/lib/ld-musl-aarch64.so.1']
31
+
32
+ /**
33
+ * True on a Linux whose C library is musl. Node reports the glibc version it
34
+ * runs on and leaves the field out on musl, so a report settles it. Bun's
35
+ * report never names glibc, so under Bun there is no report and the musl loader
36
+ * files decide.
37
+ */
38
+ function isMusl(platform, report, probe) {
39
+ if (platform !== 'linux') return false
40
+ if (report !== null && report !== undefined && report.header !== undefined) {
41
+ return report.header.glibcVersionRuntime === undefined
42
+ }
43
+ return MUSL_LOADERS.some((path) => probe(path))
44
+ }
45
+
46
+ /**
47
+ * The diagnostic report, read only on Linux, the one platform whose answer
48
+ * depends on it, and never under Bun, whose report says nothing about the C
49
+ * library. Generating it costs time on every launch, and the network interface
50
+ * listing it would otherwise include is not needed.
51
+ */
52
+ function currentReport(platform) {
53
+ if (platform !== 'linux' || process.versions.bun !== undefined) return null
54
+ try {
55
+ if (process.report === undefined || typeof process.report.getReport !== 'function') return null
56
+ process.report.excludeNetwork = true
57
+ return process.report.getReport()
58
+ } catch {
59
+ return null
60
+ }
61
+ }
62
+
63
+ function programName(platform) {
64
+ return platform === 'win32' ? 'kinfold.exe' : 'kinfold'
65
+ }
66
+
67
+ function unsupportedMessage(platform, arch) {
68
+ return `kinfold: no build for ${platform}-${arch}. Supported: ${SUPPORTED}.`
69
+ }
70
+
71
+ /** The program in the platform package, or null when that package is not installed. */
72
+ function resolveProgram(pkg, platform) {
73
+ try {
74
+ const manifest = require.resolve(`${pkg}/package.json`)
75
+ return join(dirname(manifest), programName(platform))
76
+ } catch {
77
+ return null
78
+ }
79
+ }
80
+
81
+ /** npm may not keep the executable bit on a package file, and the spawn needs it. */
82
+ function ensureExecutable(program, platform) {
83
+ if (platform === 'win32') return
84
+ try {
85
+ accessSync(program, constants.X_OK)
86
+ } catch {
87
+ try {
88
+ chmodSync(program, 0o755)
89
+ } catch {
90
+ // The spawn below reports the real failure.
91
+ }
92
+ }
93
+ }
94
+
95
+ function main() {
96
+ const platform = process.platform
97
+ const arch = process.arch
98
+ const musl = isMusl(platform, currentReport(platform), existsSync)
99
+ const pkg = musl ? null : packageName(platform, arch)
100
+ const program = pkg === null ? null : resolveProgram(pkg, platform)
101
+ if (program === null) {
102
+ process.stderr.write(`${unsupportedMessage(musl ? 'linux-musl' : platform, arch)}\n`)
103
+ process.exit(1)
104
+ }
105
+
106
+ ensureExecutable(program, platform)
107
+ const argv = process.argv.slice(2)
108
+ // `npx kinfold` with no subcommand opens the installer.
109
+ const args = argv.length === 0 ? ['install'] : argv
110
+ // The program records how it was installed. bunx follows the `node` shebang
111
+ // when Node is installed, so Bun's version alone misses it; the user agent
112
+ // bunx gives its child says `bun/`.
113
+ const agent = process.env.npm_config_user_agent
114
+ const underBun = process.versions.bun !== undefined || (typeof agent === 'string' && agent.startsWith('bun/'))
115
+ const channel = underBun ? 'bunx' : 'npx'
116
+ const result = spawnSync(program, args, { stdio: 'inherit', env: { ...process.env, KINFOLD_INSTALL_CHANNEL: channel } })
117
+ if (result.error !== undefined) {
118
+ process.stderr.write(`kinfold: could not run ${program}: ${result.error.message}\n`)
119
+ process.exit(1)
120
+ }
121
+ if (result.signal !== null) {
122
+ // Die by the signal the program saw, so a caller sees the same status.
123
+ try {
124
+ process.kill(process.pid, result.signal)
125
+ } catch {
126
+ process.exit(1)
127
+ }
128
+ return
129
+ }
130
+ process.exit(result.status === null ? 1 : result.status)
131
+ }
132
+
133
+ module.exports = { main, isMusl, currentReport, packageName, programName, unsupportedMessage }
134
+
135
+ if (require.main === module) main()
package/package.json CHANGED
@@ -1,14 +1,30 @@
1
1
  {
2
2
  "name": "kinfold",
3
- "version": "0.0.1-bootstrap.0",
4
- "description": "Placeholder that reserves this name for Kinfold's release workflow. Install kinfold 0.1.0 or later.",
3
+ "version": "0.2.0",
4
+ "description": "A local memory your coding agents share: Claude Code, OpenCode, Codex and Cursor.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/yahyafakhroji/kinfold",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/yahyafakhroji/kinfold.git"
10
10
  },
11
+ "bugs": {
12
+ "url": "https://github.com/yahyafakhroji/kinfold/issues"
13
+ },
14
+ "bin": {
15
+ "kinfold": "bin/kinfold.js"
16
+ },
11
17
  "files": [
12
- "README.md"
13
- ]
18
+ "bin/kinfold.js"
19
+ ],
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "optionalDependencies": {
24
+ "@kinfold/cli-darwin-arm64": "0.2.0",
25
+ "@kinfold/cli-darwin-x64": "0.2.0",
26
+ "@kinfold/cli-linux-x64": "0.2.0",
27
+ "@kinfold/cli-linux-arm64": "0.2.0",
28
+ "@kinfold/cli-windows-x64": "0.2.0"
29
+ }
14
30
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # kinfold
2
-
3
- This version is a placeholder that reserves the name for Kinfold's release workflow. Install `kinfold` 0.1.0 or later: https://github.com/yahyafakhroji/kinfold