@agentshouse/kit 0.2.1-cf110d15f69c8 → 0.2.1-cf2c570b41f24

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 (147) hide show
  1. package/README.md +38 -44
  2. package/dist/acp.js +96 -22
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +221 -65
  5. package/dist/api.js +21 -3
  6. package/dist/app-git.js +10 -26
  7. package/dist/binaries.js +60 -0
  8. package/dist/bridge.js +101 -49
  9. package/dist/building.js +50 -0
  10. package/dist/calls.js +88 -0
  11. package/dist/chunks.js +54 -0
  12. package/dist/clis.js +80 -52
  13. package/dist/connect.js +121 -0
  14. package/dist/connection.js +120 -0
  15. package/dist/content.js +106 -0
  16. package/dist/conversations.js +711 -267
  17. package/dist/copies.js +1293 -595
  18. package/dist/earlier.js +273 -0
  19. package/dist/end.js +15 -3
  20. package/dist/events.js +553 -281
  21. package/dist/files.js +206 -32
  22. package/dist/git.js +2 -70
  23. package/dist/grok.js +39 -0
  24. package/dist/home.js +123 -15
  25. package/dist/house-cli.js +282 -0
  26. package/dist/house-main.js +7 -206
  27. package/dist/instructions.js +7 -13
  28. package/dist/keys.js +238 -0
  29. package/dist/kit-cli.js +78 -0
  30. package/dist/kit-main.js +8 -22
  31. package/dist/login.js +71 -39
  32. package/dist/logout.js +2 -4
  33. package/dist/manifest.js +75 -0
  34. package/dist/mcp.js +47 -7
  35. package/dist/owner.js +46 -0
  36. package/dist/placement.js +25 -0
  37. package/dist/refusals.js +50 -23
  38. package/dist/relay.js +22 -1
  39. package/dist/resident.js +153 -53
  40. package/dist/scope.js +15 -4
  41. package/dist/scripts.js +319 -0
  42. package/dist/secret-input.js +1 -1
  43. package/dist/settings.js +247 -0
  44. package/dist/sign-in.js +66 -38
  45. package/dist/silence.js +28 -0
  46. package/dist/skills.js +49 -35
  47. package/dist/supervisor.js +163 -0
  48. package/dist/transcription.js +90 -47
  49. package/dist/update.js +119 -102
  50. package/dist/wire.js +32 -0
  51. package/dist/work.js +30 -7
  52. package/dist/workspace.js +113 -0
  53. package/package.json +25 -21
  54. package/dist/authority-main.js +0 -22
  55. package/dist/bootstrap.json +0 -24
  56. package/dist/clis-main.js +0 -23
  57. package/dist/configure-main.js +0 -6
  58. package/dist/enrol-main.js +0 -10
  59. package/dist/git-main.js +0 -153
  60. package/dist/parts.js +0 -82
  61. package/dist/service-main.js +0 -9
  62. package/dist/service.js +0 -33
  63. package/dist/stream.js +0 -74
  64. package/dist/translate.js +0 -51
  65. package/how-we-work.md +0 -23
  66. package/skills/ask-matt/LICENSE +0 -21
  67. package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
  68. package/skills/ask-matt/SKILL.md +0 -91
  69. package/skills/ask-matt/agents/openai.yaml +0 -4
  70. package/skills/code-review/LICENSE +0 -21
  71. package/skills/code-review/SKILL.md +0 -89
  72. package/skills/code-review/agents/openai.yaml +0 -3
  73. package/skills/codebase-design/DEEPENING.md +0 -37
  74. package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
  75. package/skills/codebase-design/LICENSE +0 -21
  76. package/skills/codebase-design/SKILL.md +0 -116
  77. package/skills/codebase-design/agents/openai.yaml +0 -3
  78. package/skills/diagnosing-bugs/LICENSE +0 -21
  79. package/skills/diagnosing-bugs/SKILL.md +0 -140
  80. package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
  81. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
  82. package/skills/domain-modeling/ADR-FORMAT.md +0 -47
  83. package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
  84. package/skills/domain-modeling/LICENSE +0 -21
  85. package/skills/domain-modeling/SKILL.md +0 -76
  86. package/skills/domain-modeling/agents/openai.yaml +0 -3
  87. package/skills/grill-me/LICENSE +0 -21
  88. package/skills/grill-me/SKILL.md +0 -8
  89. package/skills/grill-me/agents/openai.yaml +0 -4
  90. package/skills/grill-with-docs/LICENSE +0 -21
  91. package/skills/grill-with-docs/SKILL.md +0 -8
  92. package/skills/grill-with-docs/agents/openai.yaml +0 -4
  93. package/skills/grilling/LICENSE +0 -21
  94. package/skills/grilling/SKILL.md +0 -30
  95. package/skills/grilling/agents/openai.yaml +0 -3
  96. package/skills/handoff/LICENSE +0 -21
  97. package/skills/handoff/SKILL.md +0 -17
  98. package/skills/handoff/agents/openai.yaml +0 -4
  99. package/skills/implement/LICENSE +0 -21
  100. package/skills/implement/SKILL.md +0 -16
  101. package/skills/implement/agents/openai.yaml +0 -4
  102. package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
  103. package/skills/improve-codebase-architecture/LICENSE +0 -21
  104. package/skills/improve-codebase-architecture/SKILL.md +0 -72
  105. package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
  106. package/skills/prototype/LICENSE +0 -21
  107. package/skills/prototype/LOGIC.md +0 -67
  108. package/skills/prototype/SKILL.md +0 -28
  109. package/skills/prototype/UI.md +0 -112
  110. package/skills/prototype/agents/openai.yaml +0 -3
  111. package/skills/research/LICENSE +0 -21
  112. package/skills/research/SKILL.md +0 -14
  113. package/skills/research/agents/openai.yaml +0 -3
  114. package/skills/resolving-merge-conflicts/LICENSE +0 -21
  115. package/skills/resolving-merge-conflicts/SKILL.md +0 -16
  116. package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
  117. package/skills/tdd/LICENSE +0 -21
  118. package/skills/tdd/SKILL.md +0 -40
  119. package/skills/tdd/agents/openai.yaml +0 -3
  120. package/skills/tdd/mocking.md +0 -59
  121. package/skills/tdd/tests.md +0 -77
  122. package/skills/teach/GLOSSARY-FORMAT.md +0 -35
  123. package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
  124. package/skills/teach/LICENSE +0 -21
  125. package/skills/teach/MISSION-FORMAT.md +0 -31
  126. package/skills/teach/RESOURCES-FORMAT.md +0 -32
  127. package/skills/teach/SKILL.md +0 -141
  128. package/skills/teach/agents/openai.yaml +0 -4
  129. package/skills/to-questionnaire/LICENSE +0 -21
  130. package/skills/to-questionnaire/SKILL.md +0 -55
  131. package/skills/to-questionnaire/agents/openai.yaml +0 -4
  132. package/skills/to-spec/LICENSE +0 -21
  133. package/skills/to-spec/SKILL.md +0 -76
  134. package/skills/to-spec/agents/openai.yaml +0 -4
  135. package/skills/to-tickets/LICENSE +0 -21
  136. package/skills/to-tickets/SKILL.md +0 -106
  137. package/skills/to-tickets/agents/openai.yaml +0 -4
  138. package/skills/wait-what/LICENSE +0 -21
  139. package/skills/wait-what/SKILL.md +0 -8
  140. package/skills/wait-what/agents/openai.yaml +0 -4
  141. package/skills/wayfinder/LICENSE +0 -21
  142. package/skills/wayfinder/SKILL.md +0 -129
  143. package/skills/wayfinder/agents/openai.yaml +0 -4
  144. package/skills/writing-for-agents/LICENSE +0 -21
  145. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  146. package/skills/writing-for-agents/SKILL.md +0 -83
  147. package/skills/writing-for-agents/agents/openai.yaml +0 -3
@@ -0,0 +1,113 @@
1
+ import { cp, lstat, mkdir, readdir, readFile, rename, rm, rmdir, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ export async function present(path) {
4
+ try {
5
+ return await lstat(path);
6
+ }
7
+ catch (error) {
8
+ if (error.code === 'ENOENT')
9
+ return null;
10
+ throw error;
11
+ }
12
+ }
13
+ async function listed(path) {
14
+ const entries = await readdir(path, { recursive: true, withFileTypes: true });
15
+ const shown = await Promise.all(entries.map(async (entry) => {
16
+ const at = join(entry.parentPath, entry.name);
17
+ return `${at.slice(path.length)} ${entry.isFile() ? (await lstat(at)).size : entry.isDirectory() ? 'folder' : 'link'}`;
18
+ }));
19
+ return shown.sort();
20
+ }
21
+ export async function moved(source, target) {
22
+ try {
23
+ await rename(source, target);
24
+ return;
25
+ }
26
+ catch (error) {
27
+ if (error.code !== 'EXDEV')
28
+ throw error;
29
+ }
30
+ const copy = `${target}.moving`;
31
+ await rm(copy, { recursive: true, force: true });
32
+ try {
33
+ await cp(source, copy, { recursive: true, preserveTimestamps: true, verbatimSymlinks: true });
34
+ const folder = (await lstat(source)).isDirectory();
35
+ if (folder && JSON.stringify(await listed(source)) !== JSON.stringify(await listed(copy))) {
36
+ throw new Error(`${source} could not be copied to ${target} whole`);
37
+ }
38
+ }
39
+ catch (error) {
40
+ await rm(copy, { recursive: true, force: true });
41
+ throw error;
42
+ }
43
+ await rename(copy, target);
44
+ await rm(source, { recursive: true, force: true });
45
+ }
46
+ export async function keptName(path) {
47
+ for (let count = 1;; count++) {
48
+ const name = `${path} (kept)${count === 1 ? '' : ` ${count}`}`;
49
+ if ((await present(name)) === null)
50
+ return name;
51
+ }
52
+ }
53
+ export async function merged(from, to, placed = () => 'moves') {
54
+ const found = await present(from);
55
+ if (found === null || !found.isDirectory())
56
+ return;
57
+ await mkdir(to, { recursive: true, mode: 0o700 });
58
+ for (const entry of await readdir(from, { withFileTypes: true })) {
59
+ const source = join(from, entry.name);
60
+ const placement = placed(source, entry);
61
+ if (placement === 'stays')
62
+ continue;
63
+ const target = join(to, entry.name);
64
+ const held = await present(target);
65
+ if (held === null && placement === 'moves')
66
+ await moved(source, target);
67
+ else if (entry.isDirectory() && (held === null || held.isDirectory()))
68
+ await merged(source, target, placed);
69
+ else
70
+ await rm(source, { recursive: true, force: true });
71
+ }
72
+ await removeFolder(from);
73
+ }
74
+ export async function removeFolder(path) {
75
+ await rmdir(path).catch((error) => {
76
+ if (error.code !== 'ENOTEMPTY' && error.code !== 'ENOENT')
77
+ throw error;
78
+ });
79
+ }
80
+ export function within(path, folder) {
81
+ return path === folder || path.startsWith(`${folder}/`);
82
+ }
83
+ function rewritten(value, from, to, kept) {
84
+ if (typeof value === 'string') {
85
+ if (kept.some((folder) => within(value, folder)) || (within(to, from) && within(value, to)) || !within(value, from))
86
+ return value;
87
+ return `${to}${value.slice(from.length)}`;
88
+ }
89
+ if (Array.isArray(value))
90
+ return value.map((item) => rewritten(item, from, to, kept));
91
+ if (typeof value === 'object' && value !== null) {
92
+ return Object.fromEntries(Object.entries(value).map(([name, held]) => [name, rewritten(held, from, to, kept)]));
93
+ }
94
+ return value;
95
+ }
96
+ export function rerooted(value, from, to) {
97
+ return rewritten(value, from, to, []);
98
+ }
99
+ export async function followRoot(records, from, to, kept = []) {
100
+ if (from === to)
101
+ return;
102
+ for (const name of await readdir(records).catch(() => [])) {
103
+ if (!name.endsWith('.json'))
104
+ continue;
105
+ const path = join(records, name);
106
+ const text = await readFile(path, 'utf8');
107
+ const next = `${JSON.stringify(rewritten(JSON.parse(text), from, to, kept))}\n`;
108
+ if (next.trim() === text.trim())
109
+ continue;
110
+ await writeFile(`${path}.new`, next, { mode: 0o600 });
111
+ await rename(`${path}.new`, path);
112
+ }
113
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-cf110d15f69c8",
4
- "description": "House Kit connects an Environment to agents.house.",
3
+ "version": "0.2.1-cf2c570b41f24",
4
+ "description": "Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -12,27 +12,30 @@
12
12
  "kit": "dist/kit-main.js",
13
13
  "house": "dist/house-main.js"
14
14
  },
15
- "exports": {
16
- "./bootstrap": "./dist/bootstrap.json"
17
- },
18
15
  "files": [
19
- "dist",
20
- "how-we-work.md",
21
- "skills"
16
+ "dist"
22
17
  ],
23
18
  "scripts": {
24
- "build": "tsc -p tsconfig.build.json && node scripts/bootstrap-manifest.mjs",
19
+ "bootstrap-manifest": "node scripts/bootstrap-manifest.mjs",
20
+ "build": "tsc -p tsconfig.build.json",
25
21
  "engine": "mkdir -p tmp/engine && docker run --rm -v \"$PWD:/kit\" -w /kit alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6 sh scripts/engine.sh tmp/engine",
22
+ "follow-skills-and-kit-wire": "node scripts/follow-skills-and-kit-wire.mjs",
23
+ "release-files": "node scripts/release-files.mjs",
26
24
  "test": "tsc -p tsconfig.json && vitest run"
27
25
  },
28
26
  "dependencies": {
29
- "@agentclientprotocol/sdk": "1.7.0",
30
- "@agentshouse/mdmodel": "0.1.0-c68e2039f1ca8",
27
+ "@agentclientprotocol/sdk": "2.4.0",
28
+ "@agentshouse/kit-wire": "0.1.0-ce269f317b0cb",
29
+ "@agentshouse/session-content": "0.1.0-c560e48c9bea3",
30
+ "@agentshouse/skills": "0.1.0-cc915e7509460",
31
+ "@lydell/node-pty": "1.2.0-beta.15",
32
+ "micromark": "4.0.2",
33
+ "smol-toml": "1.9.1",
31
34
  "yaml": "2.9.1"
32
35
  },
33
36
  "peerDependencies": {
34
- "@agentclientprotocol/claude-agent-acp": "0.85.1",
35
- "@agentclientprotocol/codex-acp": "2.1.1"
37
+ "@agentclientprotocol/claude-agent-acp": "0.100.0",
38
+ "@agentclientprotocol/codex-acp": "2.5.0"
36
39
  },
37
40
  "peerDependenciesMeta": {
38
41
  "@agentclientprotocol/claude-agent-acp": {
@@ -43,26 +46,27 @@
43
46
  }
44
47
  },
45
48
  "devDependencies": {
46
- "@types/node": "24.13.6",
49
+ "@types/node": "24.19.2",
47
50
  "@types/ws": "8.18.2",
48
51
  "typescript": "7.0.2",
49
- "vitest": "5.0.1",
50
- "ws": "8.22.0"
52
+ "vitest": "5.0.5",
53
+ "ws": "8.22.0",
54
+ "zod": "4.6.7"
51
55
  },
52
- "packageManager": "npm@11.19.0",
56
+ "packageManager": "npm@11.19.1",
53
57
  "engines": {
54
- "node": "24.21.0",
55
- "npm": "11.19.0"
58
+ "node": "24.22.1",
59
+ "npm": "11.19.1"
56
60
  },
57
61
  "devEngines": {
58
62
  "runtime": {
59
63
  "name": "node",
60
- "version": "24.21.0",
64
+ "version": "24.22.1",
61
65
  "onFail": "error"
62
66
  },
63
67
  "packageManager": {
64
68
  "name": "npm",
65
- "version": "11.19.0",
69
+ "version": "11.19.1",
66
70
  "onFail": "error"
67
71
  }
68
72
  }
@@ -1,22 +0,0 @@
1
- import { setGlobalProxyFromEnv } from 'node:http';
2
- import { HouseRefusal, post } from './api.js';
3
- import { readEnrolment } from './home.js';
4
- function unanswered(error) {
5
- return error instanceof HouseRefusal ? error.status >= 500 : error instanceof TypeError && error.message === 'fetch failed';
6
- }
7
- setGlobalProxyFromEnv();
8
- try {
9
- const { house, credential } = (await readEnrolment());
10
- try {
11
- await post(house, '/kit/agents/desired', {}, credential);
12
- }
13
- catch (error) {
14
- if (!unanswered(error))
15
- throw error;
16
- process.stderr.write(`kit: House did not answer, so the stored credential stands: ${error.message}\n`);
17
- }
18
- }
19
- catch (error) {
20
- process.stderr.write(`kit: ${error.message}\n`);
21
- process.exitCode = 1;
22
- }
@@ -1,24 +0,0 @@
1
- {
2
- "schemaVersion": 2,
3
- "version": "0.2.1-cf110d15f69c8",
4
- "hosts": {
5
- "macos": {
6
- "asset": {
7
- "name": "connect-linux.sh",
8
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-cf110d15f69c8/connect-linux.sh"
9
- }
10
- },
11
- "linux": {
12
- "asset": {
13
- "name": "connect-linux.sh",
14
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-cf110d15f69c8/connect-linux.sh"
15
- }
16
- },
17
- "windows": {
18
- "asset": {
19
- "name": "connect-windows.ps1",
20
- "url": "https://github.com/agentshouse/kit/releases/download/v0.2.1-cf110d15f69c8/connect-windows.ps1"
21
- }
22
- }
23
- }
24
- }
package/dist/clis-main.js DELETED
@@ -1,23 +0,0 @@
1
- import { setGlobalProxyFromEnv } from 'node:http';
2
- import { post } from './api.js';
3
- import { CLIS, below, locate, versionOf } from './clis.js';
4
- import { readEnrolment } from './home.js';
5
- setGlobalProxyFromEnv();
6
- try {
7
- const { house, credential } = (await readEnrolment());
8
- const { agents } = await post(house, '/kit/agents/desired', {}, credential);
9
- for (const kind of agents) {
10
- const cli = await locate(kind);
11
- if (cli === null)
12
- continue;
13
- const release = await versionOf(cli);
14
- if (release === null)
15
- continue;
16
- const { bin, minimum } = CLIS[kind];
17
- process.stdout.write(`${[bin, cli, release, minimum, below(release, minimum) ? 'old' : 'current'].join('\t')}\n`);
18
- }
19
- }
20
- catch (error) {
21
- process.stderr.write(`kit: ${error.message}\n`);
22
- process.exitCode = 1;
23
- }
@@ -1,6 +0,0 @@
1
- import { readConfiguration, writeConfiguration } from './home.js';
2
- const skills = !process.argv.slice(2).includes('--no-skills');
3
- const stored = await readConfiguration();
4
- await writeConfiguration({ skills });
5
- if (stored.skills !== skills)
6
- process.stdout.write('changed\n');
@@ -1,10 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { writeEnrolment } from './home.js';
3
- const [house, environment] = process.argv.slice(2);
4
- const relay = process.env.HOUSE_KIT_RELAY || undefined;
5
- await writeEnrolment({
6
- house: house,
7
- ...(relay === undefined ? {} : { relay }),
8
- environment: environment,
9
- credential: readFileSync(0, 'utf8').trim(),
10
- });
package/dist/git-main.js DELETED
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env node
2
- import { spawn, spawnSync } from 'node:child_process';
3
- import { accessSync, constants, realpathSync, statSync } from 'node:fs';
4
- import { request } from 'node:http';
5
- import { constants as system } from 'node:os';
6
- import { delimiter, dirname, join } from 'node:path';
7
- import { localCopies } from './git.js';
8
- import { kitHome } from './home.js';
9
- const VALUED = new Set(['-C', '-c', '--git-dir', '--work-tree', '--namespace', '--config-env', '--attr-source', '--super-prefix']);
10
- const READS = new Set([
11
- 'blame',
12
- 'branch',
13
- 'cat-file',
14
- 'check-ignore',
15
- 'config',
16
- 'describe',
17
- 'diff',
18
- 'fetch',
19
- 'for-each-ref',
20
- 'grep',
21
- 'help',
22
- 'log',
23
- 'ls-files',
24
- 'ls-tree',
25
- 'reflog',
26
- 'remote',
27
- 'rev-list',
28
- 'rev-parse',
29
- 'shortlog',
30
- 'show',
31
- 'show-ref',
32
- 'status',
33
- 'tag',
34
- 'version',
35
- ]);
36
- const RELAYED = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT'];
37
- function nativeGit() {
38
- const shim = join(kitHome(), 'shim');
39
- for (const directory of (process.env.PATH ?? '').split(delimiter)) {
40
- if (directory === '')
41
- continue;
42
- try {
43
- if (realpathSync(directory) === realpathSync(shim))
44
- continue;
45
- const candidate = join(directory, 'git');
46
- if (!statSync(candidate).isFile())
47
- continue;
48
- accessSync(candidate, constants.X_OK);
49
- return candidate;
50
- }
51
- catch { }
52
- }
53
- return null;
54
- }
55
- function captured(git, args) {
56
- const ran = spawnSync(git, args, {
57
- stdio: ['ignore', 'pipe', 'ignore'],
58
- maxBuffer: Infinity,
59
- env: { ...process.env, LC_ALL: 'C' },
60
- });
61
- return ran.status === 0 ? ran.stdout.toString('utf8') : null;
62
- }
63
- function delegated(git, args) {
64
- return new Promise((resolve) => {
65
- const child = spawn(git, args, { stdio: 'inherit' });
66
- const relay = (signal) => child.kill(signal);
67
- for (const signal of RELAYED)
68
- process.on(signal, relay);
69
- const settle = (outcome) => {
70
- for (const signal of RELAYED)
71
- process.off(signal, relay);
72
- resolve(outcome);
73
- };
74
- child.once('error', (error) => {
75
- process.stderr.write(`git: ${error.message}\n`);
76
- settle({ status: 127, signal: null });
77
- });
78
- child.once('close', (status, signal) => settle({ status, signal }));
79
- });
80
- }
81
- function staged(listing) {
82
- const entries = new Map();
83
- for (const record of (listing ?? '').split('\0')) {
84
- const tab = record.indexOf('\t');
85
- if (tab >= 0)
86
- entries.set(record.slice(tab + 1), record.slice(0, tab).split(' ')[1]);
87
- }
88
- return entries;
89
- }
90
- function moved(planned, before, after) {
91
- const moves = [];
92
- for (const line of planned.split('\n')) {
93
- if (!line.startsWith('Renaming '))
94
- continue;
95
- const renaming = line.slice('Renaming '.length);
96
- for (let at = renaming.indexOf(' to '); at >= 0; at = renaming.indexOf(' to ', at + 1)) {
97
- const from = renaming.slice(0, at);
98
- const to = renaming.slice(at + 4);
99
- if (before.has(from) && !after.has(from) && after.get(to) === before.get(from)) {
100
- moves.push({ from, to });
101
- break;
102
- }
103
- }
104
- }
105
- return moves;
106
- }
107
- function reported(socketPath, body) {
108
- return new Promise((resolve) => {
109
- const sent = request({ socketPath, path: '/git/observed', method: 'POST' }, (answer) => {
110
- answer.resume();
111
- answer.on('end', resolve);
112
- });
113
- sent.on('error', () => resolve());
114
- sent.end(JSON.stringify(body));
115
- });
116
- }
117
- async function observed(git, args) {
118
- let index = 0;
119
- while (index < args.length && args[index].startsWith('-'))
120
- index += VALUED.has(args[index]) ? 2 : 1;
121
- const globals = args.slice(0, index);
122
- const name = args[index];
123
- const bridge = process.env.HOUSE_BRIDGE;
124
- if (bridge === undefined || name === undefined || READS.has(name))
125
- return delegated(git, args);
126
- const located = captured(git, [...globals, 'rev-parse', '--path-format=absolute', '--git-common-dir', '--show-toplevel']);
127
- const [common, worktree] = located?.split('\n') ?? [];
128
- if (common === undefined || worktree === undefined || !dirname(common).startsWith(`${localCopies()}/`)) {
129
- return delegated(git, args);
130
- }
131
- const listing = [...globals, '-C', worktree, 'ls-files', '--stage', '-z'];
132
- const before = name === 'mv' ? staged(captured(git, listing)) : null;
133
- const planned = name === 'mv' ? (captured(git, [...globals, 'mv', '--dry-run', ...args.slice(index + 1)]) ?? '') : '';
134
- const outcome = await delegated(git, args);
135
- const moves = before !== null && outcome.status === 0 ? moved(planned, before, staged(captured(git, listing))) : [];
136
- await reported(bridge, { common, worktree, moves });
137
- return outcome;
138
- }
139
- const git = nativeGit();
140
- if (git === null) {
141
- process.stderr.write('git: no installed Git found on PATH\n');
142
- process.exitCode = 127;
143
- }
144
- else {
145
- observed(git, process.argv.slice(2)).then(({ status, signal }) => {
146
- if (signal === null) {
147
- process.exitCode = status ?? 1;
148
- return;
149
- }
150
- process.exitCode = 128 + system.signals[signal];
151
- process.kill(process.pid, signal);
152
- });
153
- }
package/dist/parts.js DELETED
@@ -1,82 +0,0 @@
1
- export class Parts {
2
- parts = [];
3
- context = null;
4
- emit;
5
- made = [];
6
- events = 0;
7
- writing = null;
8
- counting = null;
9
- planned = null;
10
- constructor(emit) {
11
- this.emit = emit;
12
- }
13
- write(type, id, text) {
14
- if (text === '')
15
- return;
16
- if (this.writing?.type === type && this.writing.id === id) {
17
- this.parts[this.writing.index].text += text;
18
- this.emit({ op: 'append', index: this.writing.index, text });
19
- return;
20
- }
21
- this.writing = { type, id, index: this.start({ type, text }) };
22
- }
23
- command() {
24
- if (this.counting === null) {
25
- this.counting = this.start({ type: 'commands', count: 1 });
26
- return;
27
- }
28
- const part = this.parts[this.counting];
29
- part.count++;
30
- this.emit({ op: 'count', index: this.counting, count: part.count });
31
- }
32
- start(part) {
33
- this.writing = null;
34
- this.counting = null;
35
- return this.add(part, ++this.events);
36
- }
37
- reserve() {
38
- this.writing = null;
39
- this.counting = null;
40
- return ++this.events;
41
- }
42
- arrive(part, reserved) {
43
- this.add(part, reserved);
44
- }
45
- done(index, result) {
46
- const part = this.parts[index];
47
- part.status = 'done';
48
- part.result = result;
49
- this.emit({ op: 'status', index, status: 'done', result });
50
- }
51
- plan(entries) {
52
- if (this.planned === null) {
53
- this.planned = this.start({ type: 'plan', entries });
54
- return;
55
- }
56
- this.parts[this.planned].entries = entries;
57
- this.emit({ op: 'plan', index: this.planned, entries });
58
- }
59
- measure(context) {
60
- this.context = context;
61
- this.emit({ op: 'context', ...context });
62
- }
63
- saved() {
64
- return this.parts
65
- .map((part, index) => ({ part, made: this.made[index] }))
66
- .sort((a, b) => a.made - b.made)
67
- .map(({ part }) => part);
68
- }
69
- operations() {
70
- return [
71
- ...this.parts.map((part, index) => ({ op: 'start', index, part })),
72
- ...(this.context === null ? [] : [{ op: 'context', ...this.context }]),
73
- ];
74
- }
75
- add(part, made) {
76
- this.parts.push(part);
77
- this.made.push(made);
78
- const index = this.parts.length - 1;
79
- this.emit({ op: 'start', index, part });
80
- return index;
81
- }
82
- }
@@ -1,9 +0,0 @@
1
- import { startService } from './service.js';
2
- try {
3
- if (startService())
4
- process.stdout.write('started\n');
5
- }
6
- catch (error) {
7
- process.stderr.write(`kit: ${error.message}\n`);
8
- process.exitCode = 1;
9
- }
package/dist/service.js DELETED
@@ -1,33 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- const UNIT = 'house-kit.service';
3
- // launchctl and systemctl answer at once, so ten seconds only bounds a stuck service manager.
4
- const MANAGER_MS = 10_000;
5
- function manage(command, args) {
6
- return spawnSync(command, args, { encoding: 'utf8', timeout: MANAGER_MS });
7
- }
8
- function start(command, args) {
9
- const started = manage(command, args);
10
- if (started.status === 0)
11
- return;
12
- const cause = started.error?.message ?? (started.stderr.trim() || `${command} exited with ${started.status ?? 'a signal'}`);
13
- throw new Error(`the House Kit service could not be started: ${cause}`);
14
- }
15
- export function startService() {
16
- if (process.platform === 'darwin') {
17
- const service = `gui/${process.getuid()}/house-kit`;
18
- const printed = manage('launchctl', ['print', service]);
19
- if (printed.status !== 0 || /^\tstate = running$/m.test(printed.stdout))
20
- return false;
21
- start('launchctl', ['kickstart', service]);
22
- return true;
23
- }
24
- for (const scope of [['--user'], []]) {
25
- if (manage('systemctl', [...scope, 'is-enabled', '--quiet', UNIT]).status !== 0)
26
- continue;
27
- if (manage('systemctl', [...scope, 'is-active', '--quiet', UNIT]).status === 0)
28
- return false;
29
- start('systemctl', [...scope, 'start', UNIT]);
30
- return true;
31
- }
32
- return false;
33
- }
package/dist/stream.js DELETED
@@ -1,74 +0,0 @@
1
- import { subscribe } from 'node:diagnostics_channel';
2
- import { finalRefusal, HouseRefusal, retryDelay } from './api.js';
3
- import { end, REPLACED, signInAgain } from './end.js';
4
- import { readEnrolment } from './home.js';
5
- import { relayed } from './relay.js';
6
- const PATH = '/kit/stream';
7
- const SUBPROTOCOL = 'house.kit.stream.1';
8
- const REFUSAL_HEADER = 'x-house-refusal';
9
- function streamUrl(house) {
10
- const url = new URL(PATH, house);
11
- url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
12
- return url;
13
- }
14
- function header(headers, name) {
15
- for (let index = 0; index < headers.length; index += 2) {
16
- if (headers[index].toString('latin1').toLowerCase() === name)
17
- return headers[index + 1].toString('latin1');
18
- }
19
- return '';
20
- }
21
- let refused = null;
22
- subscribe('undici:request:headers', (message) => {
23
- const { request, response } = message;
24
- if (!request.path.endsWith(PATH))
25
- return;
26
- refused = new HouseRefusal(PATH, response.statusCode, header(response.headers, REFUSAL_HEADER) || response.statusText);
27
- });
28
- export function holdStream(handlers) {
29
- let socket = null;
30
- let failures = 0;
31
- const connect = async () => {
32
- const { house, credential } = (await readEnrolment());
33
- refused = null;
34
- const opening = new WebSocket(relayed(streamUrl(house)), {
35
- protocols: [SUBPROTOCOL],
36
- headers: { authorization: `Bearer ${credential}` },
37
- });
38
- let opened = false;
39
- opening.onopen = () => {
40
- opened = true;
41
- failures = 0;
42
- socket = opening;
43
- handlers.opened();
44
- };
45
- opening.onmessage = (event) => {
46
- handlers.frame(JSON.parse(String(event.data)));
47
- };
48
- opening.onerror = () => undefined;
49
- opening.onclose = (event) => {
50
- if (socket === opening)
51
- socket = null;
52
- process.stderr.write(`kit: control stream closed ${event.code} ${event.reason}\n`);
53
- if (event.reason === 'replaced')
54
- end(REPLACED);
55
- if (event.reason === 'credential_rejected' || refused?.status === 401) {
56
- void signInAgain(credential);
57
- return;
58
- }
59
- if (finalRefusal(refused))
60
- end(refused.message);
61
- // A closed socket reopens in one to three seconds, spread so Kits one restart closed return apart; an opening House refused as retryable or left unanswered backs off on the jittered curve.
62
- setTimeout(() => void connect(), opened ? 1000 + Math.random() * 2000 : retryDelay(failures++));
63
- };
64
- };
65
- void connect();
66
- return {
67
- send(frame) {
68
- if (socket === null || socket.readyState !== WebSocket.OPEN)
69
- return false;
70
- socket.send(JSON.stringify(frame));
71
- return true;
72
- },
73
- };
74
- }