homeostat 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/README.md +30 -2
- package/bin/homeostat.js +16 -0
- package/dist/src/agents.d.ts +7 -0
- package/dist/src/agents.js +34 -0
- package/dist/src/cli.d.ts +25 -0
- package/dist/src/cli.js +296 -0
- package/dist/src/codeowners.d.ts +5 -0
- package/dist/src/codeowners.js +31 -0
- package/dist/src/curate.d.ts +10 -0
- package/dist/src/curate.js +251 -0
- package/dist/src/deep-dive.d.ts +9 -0
- package/dist/src/deep-dive.js +94 -0
- package/dist/src/digest.d.ts +8 -0
- package/dist/src/digest.js +49 -0
- package/dist/src/docs.d.ts +13 -0
- package/dist/src/docs.js +50 -0
- package/dist/src/doctor.d.ts +17 -0
- package/dist/src/doctor.js +201 -0
- package/dist/src/events-command.d.ts +9 -0
- package/dist/src/events-command.js +18 -0
- package/dist/src/export.d.ts +11 -0
- package/dist/src/export.js +121 -0
- package/dist/src/flag.d.ts +10 -0
- package/dist/src/flag.js +66 -0
- package/dist/src/format.d.ts +10 -0
- package/dist/src/format.js +22 -0
- package/dist/src/git.d.ts +10 -0
- package/dist/src/git.js +73 -0
- package/dist/src/hook.d.ts +18 -0
- package/dist/src/hook.js +181 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/init.d.ts +14 -0
- package/dist/src/init.js +339 -0
- package/dist/src/learn.d.ts +35 -0
- package/dist/src/learn.js +230 -0
- package/dist/src/mcp.d.ts +10 -0
- package/dist/src/mcp.js +71 -0
- package/dist/src/provider.d.ts +11 -0
- package/dist/src/provider.js +19 -0
- package/dist/src/publish.d.ts +31 -0
- package/dist/src/publish.js +39 -0
- package/dist/src/query.d.ts +20 -0
- package/dist/src/query.js +104 -0
- package/dist/src/seed.d.ts +14 -0
- package/dist/src/seed.js +127 -0
- package/dist/src/touched.d.ts +5 -0
- package/dist/src/touched.js +32 -0
- package/dist/src/up.d.ts +24 -0
- package/dist/src/up.js +101 -0
- package/dist/src/validate.d.ts +7 -0
- package/dist/src/validate.js +45 -0
- package/package.json +47 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# homeostat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Your team's code-review lessons, as rules every coding agent follows.**
|
|
4
|
+
|
|
5
|
+
Homeostat turns review feedback that led to a code change into short, scored rules and living team documents. It keeps them in a git repo where every change is a reviewed pull request, and gives every agent the ones that matter for the files it is touching: Claude Code (plugin and hooks), any MCP client, Cursor, Copilot and AGENTS.md.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# In a repo for your team's knowledge base:
|
|
9
|
+
npx --yes homeostat@0.1.0 init
|
|
10
|
+
|
|
11
|
+
# In Claude Code:
|
|
12
|
+
claude plugin marketplace add ysugarmen/homeostat
|
|
13
|
+
claude plugin install homeostat@homeostat
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Common commands:
|
|
17
|
+
- `homeostat learn`: capture a rule
|
|
18
|
+
- `homeostat validate`: check the knowledge base
|
|
19
|
+
- `homeostat curate`: the daily curator, run in CI
|
|
20
|
+
- `homeostat export`: write rules files for other tools
|
|
21
|
+
- `homeostat mcp`: serve the MCP server
|
|
22
|
+
- `homeostat dashboard`: open the local dashboard
|
|
23
|
+
- `homeostat doctor --security`: check a setup
|
|
24
|
+
|
|
25
|
+
`homeostat --help` lists the rest.
|
|
26
|
+
|
|
27
|
+
- [Quickstart](https://github.com/ysugarmen/homeostat/blob/main/docs/guide/quickstart.md)
|
|
28
|
+
- [Guide](https://github.com/ysugarmen/homeostat/blob/main/docs/index.md)
|
|
29
|
+
- [Data handling](https://github.com/ysugarmen/homeostat/blob/main/docs/data-handling.md)
|
|
30
|
+
|
|
31
|
+
Every release is published from GitHub Actions with npm provenance. Apache-2.0.
|
package/bin/homeostat.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Node strips types from .ts files in a checkout but not inside node_modules, so an installed
|
|
3
|
+
// package runs the compiled dist/ and the repo runs the source directly.
|
|
4
|
+
const { runCli } = import.meta.url.includes("/node_modules/")
|
|
5
|
+
? await import("../dist/src/cli.js")
|
|
6
|
+
: await import("../src/cli.ts");
|
|
7
|
+
|
|
8
|
+
// A closed pipe (`homeostat validate | head`) means the reader has what it wanted, not a crash.
|
|
9
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
10
|
+
stream.on("error", (error) => {
|
|
11
|
+
if (error.code === "EPIPE") process.exit(process.exitCode ?? 0);
|
|
12
|
+
throw error;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
process.exitCode = await runCli(process.argv);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Asker, type Config } from "@homeostat/core";
|
|
2
|
+
import type { Io } from "./cli.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The Claude runtime configured for `agent` in homeostat.yaml. Each call is logged as a
|
|
5
|
+
* `model-call` event with its size, runtime and model, never its content (security plan T5).
|
|
6
|
+
*/
|
|
7
|
+
export declare function askerFor(config: Config, agent: "curator" | "deepDive", io: Io, kbRoot: string): Asker;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { apiAsker, bedrockAsker, claudeCodeAsker, logEvent, vertexAsker, } from "@homeostat/core";
|
|
2
|
+
/**
|
|
3
|
+
* The Claude runtime configured for `agent` in homeostat.yaml. Each call is logged as a
|
|
4
|
+
* `model-call` event with its size, runtime and model, never its content (security plan T5).
|
|
5
|
+
*/
|
|
6
|
+
export function askerFor(config, agent, io, kbRoot) {
|
|
7
|
+
const { model, effort } = config.agents[agent];
|
|
8
|
+
const runtime = config.agents.runtime;
|
|
9
|
+
const ask = {
|
|
10
|
+
api: () => apiAsker({ model, effort, env: { ...io.env } }),
|
|
11
|
+
"claude-code": () => claudeCodeAsker({ model, effort, env: { ...io.env } }),
|
|
12
|
+
bedrock: () => bedrockAsker({ model, effort, ...config.agents.bedrock }),
|
|
13
|
+
vertex: () => vertexAsker({ model, effort, ...config.agents.vertex }),
|
|
14
|
+
}[runtime]();
|
|
15
|
+
return async (system, user, schema) => {
|
|
16
|
+
const record = (ok) => logEvent(kbRoot, {
|
|
17
|
+
type: "model-call",
|
|
18
|
+
agent,
|
|
19
|
+
runtime,
|
|
20
|
+
model,
|
|
21
|
+
chars: system.length + user.length,
|
|
22
|
+
ok,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
const out = await ask(system, user, schema);
|
|
26
|
+
record(true);
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
record(false);
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConflictJudge, DocPatcher, Drafter, Merger, Provider, Seeder } from "@homeostat/core";
|
|
2
|
+
/** Everything the commands touch outside the file system, so tests can supply their own. */
|
|
3
|
+
export interface Io {
|
|
4
|
+
stdout: (text: string) => void;
|
|
5
|
+
stderr: (text: string) => void;
|
|
6
|
+
color: boolean;
|
|
7
|
+
/** Prompts for one line; absent when there is no terminal to ask. */
|
|
8
|
+
ask?: (question: string) => Promise<string>;
|
|
9
|
+
/** Environment variables, for tokens. Defaults to none, so tests never see real tokens. */
|
|
10
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
now?: () => Date;
|
|
13
|
+
/** Reads all of stdin; hooks receive their event JSON this way. */
|
|
14
|
+
stdin?: () => Promise<string>;
|
|
15
|
+
/** Test seams for the agents: a git-host provider and a drafter instead of the real ones. */
|
|
16
|
+
provider?: Provider;
|
|
17
|
+
drafter?: Drafter;
|
|
18
|
+
patcher?: DocPatcher;
|
|
19
|
+
seeder?: Seeder;
|
|
20
|
+
merger?: Merger;
|
|
21
|
+
judge?: ConflictJudge;
|
|
22
|
+
}
|
|
23
|
+
export declare const processIo: Io;
|
|
24
|
+
/** Runs the CLI with `argv` (as in `process.argv`) and returns the exit code. */
|
|
25
|
+
export declare function runCli(argv: readonly string[], io?: Io): Promise<number>;
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { VERSION } from "@homeostat/core";
|
|
3
|
+
import { Command, CommanderError } from "commander";
|
|
4
|
+
import { runCodeowners } from "./codeowners.js";
|
|
5
|
+
import { runCurate } from "./curate.js";
|
|
6
|
+
import { runDeepDive } from "./deep-dive.js";
|
|
7
|
+
import { runDigest } from "./digest.js";
|
|
8
|
+
import { runConvertDocs } from "./docs.js";
|
|
9
|
+
import { runDoctor } from "./doctor.js";
|
|
10
|
+
import { runEvents } from "./events-command.js";
|
|
11
|
+
import { runExport } from "./export.js";
|
|
12
|
+
import { runFlag } from "./flag.js";
|
|
13
|
+
import { HOOK_EVENTS, runHook } from "./hook.js";
|
|
14
|
+
import { HOSTS, runInit } from "./init.js";
|
|
15
|
+
import { runLearn } from "./learn.js";
|
|
16
|
+
import { runMcp } from "./mcp.js";
|
|
17
|
+
import { runExplain, runList, runSearch, runStatus } from "./query.js";
|
|
18
|
+
import { runSeed } from "./seed.js";
|
|
19
|
+
import { runDashboard, runUp } from "./up.js";
|
|
20
|
+
import { runValidate } from "./validate.js";
|
|
21
|
+
async function readStdin() {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
for await (const chunk of process.stdin)
|
|
24
|
+
chunks.push(chunk);
|
|
25
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
26
|
+
}
|
|
27
|
+
async function askTerminal(question) {
|
|
28
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
29
|
+
try {
|
|
30
|
+
return await rl.question(`${question}: `);
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
rl.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const processIo = {
|
|
37
|
+
stdout: (t) => process.stdout.write(t),
|
|
38
|
+
stderr: (t) => process.stderr.write(t),
|
|
39
|
+
color: process.stdout.isTTY === true && !process.env.NO_COLOR,
|
|
40
|
+
...(process.stdin.isTTY ? { ask: askTerminal } : {}),
|
|
41
|
+
env: process.env,
|
|
42
|
+
stdin: readStdin,
|
|
43
|
+
};
|
|
44
|
+
/** Runs the CLI with `argv` (as in `process.argv`) and returns the exit code. */
|
|
45
|
+
export async function runCli(argv, io = processIo) {
|
|
46
|
+
let exitCode = 0;
|
|
47
|
+
const program = new Command("homeostat")
|
|
48
|
+
.description("Team knowledge base for coding agents.")
|
|
49
|
+
.version(VERSION, "-v, --version")
|
|
50
|
+
.exitOverride()
|
|
51
|
+
.configureOutput({ writeOut: io.stdout, writeErr: io.stderr });
|
|
52
|
+
program
|
|
53
|
+
.command("validate")
|
|
54
|
+
.aliases(["check", "lint"])
|
|
55
|
+
.description("Check homeostat.yaml and every entry under knowledge/.")
|
|
56
|
+
.argument("[dir]", "knowledge base root", ".")
|
|
57
|
+
.option("--fix", "rewrite stale score and tokens values")
|
|
58
|
+
.option("--json", "print the result as JSON")
|
|
59
|
+
.action((dir, opts) => {
|
|
60
|
+
exitCode = runValidate(dir, opts, io);
|
|
61
|
+
});
|
|
62
|
+
program
|
|
63
|
+
.command("codeowners")
|
|
64
|
+
.description("Generate CODEOWNERS from homeostat.yaml and entry owners.")
|
|
65
|
+
.argument("[dir]", "knowledge base root", ".")
|
|
66
|
+
.option("--check", "exit 1 if CODEOWNERS is stale, without writing it")
|
|
67
|
+
.action((dir, opts) => {
|
|
68
|
+
exitCode = runCodeowners(dir, opts, io);
|
|
69
|
+
});
|
|
70
|
+
program
|
|
71
|
+
.command("init")
|
|
72
|
+
.description("Scaffold homeostat.yaml, knowledge/ and a validate CI file in a KB repo.")
|
|
73
|
+
.argument("[dir]", "knowledge base root", ".")
|
|
74
|
+
.option("--host <host>", `git host for the CI file: ${HOSTS.join(" or ")} (default: detect)`)
|
|
75
|
+
.option("--member <id>", "id of the first (senior) member (default: from git user.name)")
|
|
76
|
+
.option("--handle <handle>", "CODEOWNERS handle of the first member, e.g. @you")
|
|
77
|
+
.option("--force", "overwrite an existing homeostat.yaml")
|
|
78
|
+
.action((dir, opts) => {
|
|
79
|
+
exitCode = runInit(dir, opts, io);
|
|
80
|
+
});
|
|
81
|
+
const collect = (value, previous = []) => [...previous, value];
|
|
82
|
+
program
|
|
83
|
+
.command("learn")
|
|
84
|
+
.aliases(["add", "remember"])
|
|
85
|
+
.description("Write a candidate entry from flags, prompts, or a PR review comment URL.")
|
|
86
|
+
.argument("[url]", "Bitbucket or GitHub PR review comment link")
|
|
87
|
+
.option("--dir <dir>", "knowledge base root", ".")
|
|
88
|
+
.option("--title <text>", "imperative one-line title")
|
|
89
|
+
.option("--rule <text>", "the rule, one paragraph of at most 60 words")
|
|
90
|
+
.option("--why <text>", "why the rule exists, at most 100 words")
|
|
91
|
+
.option("--area <area>", "area from homeostat.yaml (default: core)")
|
|
92
|
+
.option("--scope <glob>", "path glob the rule applies to; repeatable", collect)
|
|
93
|
+
.option("--author <id>", "member who originated it (default: comment author or git user)")
|
|
94
|
+
.option("--owner <id>", "member who answers for it (default: author)")
|
|
95
|
+
.option("--id <id>", "entry id (default: from the title)")
|
|
96
|
+
.option("--tag <tag>", "search tag; repeatable", collect)
|
|
97
|
+
.option("--kind <kind>", "convention, anti-pattern, review-lesson, migration, legacy, tech-debt, practice or decision")
|
|
98
|
+
.option("--not-adopted", "with --kind decision: a proposal the team rejected (rule = the proposal, why = why not)")
|
|
99
|
+
.option("--example-file <path>", "markdown to use as the Example section")
|
|
100
|
+
.option("--doc <area/topic>", "patch one section of knowledge/<area>/docs/<topic>.md instead")
|
|
101
|
+
.option("--section <id>", "with --doc: the section to replace or append to (or a new id)")
|
|
102
|
+
.option("--text <text>", "with --doc: the section text")
|
|
103
|
+
.option("--append", "with --doc: add to the section instead of replacing it")
|
|
104
|
+
.option("--heading <text>", "with --doc: add a new section with this heading")
|
|
105
|
+
.option("--source <type>", "manual (default) or agent-handoff")
|
|
106
|
+
.option("--branch <name>", "commit to this KB branch instead of the working tree")
|
|
107
|
+
.option("--push", "push --branch to origin after committing")
|
|
108
|
+
.action(async (url, opts) => {
|
|
109
|
+
exitCode = await runLearn(url, opts, io);
|
|
110
|
+
});
|
|
111
|
+
program
|
|
112
|
+
.command("search")
|
|
113
|
+
.aliases(["find"])
|
|
114
|
+
.description("Search accepted entries by topic or keyword.")
|
|
115
|
+
.argument("<query...>", "words to search for")
|
|
116
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
117
|
+
.option("--area <area>", "only this area")
|
|
118
|
+
.option("--path <path>", "only entries whose scope covers this file")
|
|
119
|
+
.option("--limit <n>", "how many to show", "10")
|
|
120
|
+
.option("--all", "include candidates, disputed and retired entries")
|
|
121
|
+
.option("--json", "print JSON")
|
|
122
|
+
.action((query, opts) => {
|
|
123
|
+
exitCode = runSearch(query, opts, io);
|
|
124
|
+
});
|
|
125
|
+
program
|
|
126
|
+
.command("explain")
|
|
127
|
+
.aliases(["show", "why"])
|
|
128
|
+
.description("Why an entry exists: source, score breakdown, owner, conflicts, text.")
|
|
129
|
+
.argument("<id>", "entry id")
|
|
130
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
131
|
+
.option("--json", "print JSON")
|
|
132
|
+
.action((id, opts) => {
|
|
133
|
+
exitCode = runExplain(id, opts, io);
|
|
134
|
+
});
|
|
135
|
+
program
|
|
136
|
+
.command("list")
|
|
137
|
+
.aliases(["ls"])
|
|
138
|
+
.description("List entries with their status and score.")
|
|
139
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
140
|
+
.option("--area <area>", "only this area")
|
|
141
|
+
.option("--status <status>", "only this status")
|
|
142
|
+
.option("--json", "print JSON")
|
|
143
|
+
.action((opts) => {
|
|
144
|
+
exitCode = runList(opts, io);
|
|
145
|
+
});
|
|
146
|
+
const docs = program
|
|
147
|
+
.command("docs")
|
|
148
|
+
.description("Knowledge documents: the team's living reference under knowledge/<area>/docs/.");
|
|
149
|
+
docs
|
|
150
|
+
.command("convert")
|
|
151
|
+
.description("Bring existing markdown documents into the KB, with section ids and provenance.")
|
|
152
|
+
.argument("<files...>", "markdown files to convert")
|
|
153
|
+
.requiredOption("--area <area>", "area the documents describe (core for org-wide)")
|
|
154
|
+
.requiredOption("--owner <member>", "member who owns them")
|
|
155
|
+
.option("--scope <glob>", "paths they describe; repeatable (default: the area's globs)", collect)
|
|
156
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
157
|
+
.option("--force", "overwrite documents that already exist")
|
|
158
|
+
.action((files, opts) => {
|
|
159
|
+
exitCode = runConvertDocs(files, opts, io);
|
|
160
|
+
});
|
|
161
|
+
program
|
|
162
|
+
.command("seed")
|
|
163
|
+
.description("Draft a new team's first documents from a local repo checkout. Manual only: sends code to the model.")
|
|
164
|
+
.argument("<repo>", "path to a local checkout of the code repo")
|
|
165
|
+
.requiredOption("--area <area>", "area the documents describe (core for org-wide)")
|
|
166
|
+
.requiredOption("--owner <member>", "member who will own them")
|
|
167
|
+
.option("--topic <topic>", "architecture, conventions or cross-repo; repeatable", collect)
|
|
168
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
169
|
+
.option("--dry-run", "print exactly what would be sent; send nothing, write nothing")
|
|
170
|
+
.option("--force", "replace documents that already exist")
|
|
171
|
+
.action(async (repo, opts) => {
|
|
172
|
+
exitCode = await runSeed(repo, opts, io);
|
|
173
|
+
});
|
|
174
|
+
program
|
|
175
|
+
.command("digest")
|
|
176
|
+
.description("Post the weekly digest to the Slack webhook in notifications.slackWebhookEnv (run in CI).")
|
|
177
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
178
|
+
.option("--days <n>", "window in days", "7")
|
|
179
|
+
.option("--dry-run", "print the digest instead of posting it")
|
|
180
|
+
.action(async (opts) => {
|
|
181
|
+
exitCode = await runDigest(opts, io);
|
|
182
|
+
});
|
|
183
|
+
program
|
|
184
|
+
.command("doctor")
|
|
185
|
+
.description("Security review: what is read, what leaves, who can change the rules, and the blast radius.")
|
|
186
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
187
|
+
.option("--security", "run the security checks (the default, and today the only ones)")
|
|
188
|
+
.action(async (opts) => {
|
|
189
|
+
exitCode = await runDoctor(opts, io);
|
|
190
|
+
});
|
|
191
|
+
program
|
|
192
|
+
.command("status")
|
|
193
|
+
.aliases(["report", "health"])
|
|
194
|
+
.description("Knowledge base health: entries by status, new, flagged, stale, duplicates, injections.")
|
|
195
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
196
|
+
.option("--days <n>", "window in days", "7")
|
|
197
|
+
.action((opts) => {
|
|
198
|
+
exitCode = runStatus(opts, io);
|
|
199
|
+
});
|
|
200
|
+
program
|
|
201
|
+
.command("events")
|
|
202
|
+
.aliases(["log"])
|
|
203
|
+
.description("The KB's local event log: injections, MCP calls, captures, agent runs.")
|
|
204
|
+
.option("--dir <dir>", "knowledge base root (default: $HOMEOSTAT_DIR or the current dir)")
|
|
205
|
+
.option("--since <date>", "ISO date or time (default: the last 24 hours)")
|
|
206
|
+
.option("--type <type>", "only this event type; repeatable", collect)
|
|
207
|
+
.option("--json", "print JSON")
|
|
208
|
+
.action((opts) => {
|
|
209
|
+
exitCode = runEvents(opts, io);
|
|
210
|
+
});
|
|
211
|
+
program
|
|
212
|
+
.command("flag")
|
|
213
|
+
.description("Report that an entry is wrong: it loses score and goes back to review.")
|
|
214
|
+
.argument("<id>", "entry id")
|
|
215
|
+
.option("--reason <text>", "what is wrong")
|
|
216
|
+
.option("--dir <dir>", "knowledge base root", ".")
|
|
217
|
+
.option("--by <id>", "member reporting it (default: git user)")
|
|
218
|
+
.option("--branch <name>", "commit to this KB branch instead of the working tree")
|
|
219
|
+
.option("--push", "push --branch to origin after committing")
|
|
220
|
+
.action((id, opts) => {
|
|
221
|
+
exitCode = runFlag(id, opts, io);
|
|
222
|
+
});
|
|
223
|
+
program
|
|
224
|
+
.command("mcp")
|
|
225
|
+
.description("Serve the knowledge base to any agent over MCP (stdio).")
|
|
226
|
+
.action(async () => {
|
|
227
|
+
exitCode = await runMcp(io);
|
|
228
|
+
});
|
|
229
|
+
program
|
|
230
|
+
.command("export")
|
|
231
|
+
.description("Write accepted entries into a code repo as Claude, Cursor, Copilot and AGENTS.md rules.")
|
|
232
|
+
.option("--kb <dir>", "knowledge base checkout (default: $HOMEOSTAT_DIR, else the current dir)")
|
|
233
|
+
.option("--out <dir>", "code repo to write into", ".")
|
|
234
|
+
.option("--target <target>", "claude, cursor, agents-md or copilot; repeatable (default: homeostat.yaml)", collect)
|
|
235
|
+
.option("--check", "exit 1 if the exported files are out of date, without writing")
|
|
236
|
+
.option("--allow-public", "export even when the code repo is public")
|
|
237
|
+
.action(async (opts) => {
|
|
238
|
+
exitCode = await runExport(opts, io);
|
|
239
|
+
});
|
|
240
|
+
program
|
|
241
|
+
.command("curate")
|
|
242
|
+
.description("Draft entries from merged review feedback and open a PR on the KB repo (run in CI).")
|
|
243
|
+
.option("--dir <dir>", "knowledge base checkout", ".")
|
|
244
|
+
.option("--since <date>", "look at PRs merged since this date (default: agents.curator.lookbackHours ago)")
|
|
245
|
+
.option("--dry-run", "draft and report, but commit and open nothing")
|
|
246
|
+
.option("--show-prompts", "print every prompt that would be sent to the model; send none, commit nothing")
|
|
247
|
+
.action(async (opts) => {
|
|
248
|
+
exitCode = await runCurate(opts, io);
|
|
249
|
+
});
|
|
250
|
+
program
|
|
251
|
+
.command("deep-dive")
|
|
252
|
+
.description("Merge near-duplicates, mark contradictions, retire stale entries; opens a PR (run in CI).")
|
|
253
|
+
.option("--dir <dir>", "knowledge base checkout", ".")
|
|
254
|
+
.option("--dry-run", "report the changes, but commit and open nothing")
|
|
255
|
+
.option("--no-llm", "skip Claude: no merged text and no conflict check")
|
|
256
|
+
.action(async (opts) => {
|
|
257
|
+
exitCode = await runDeepDive(opts, io);
|
|
258
|
+
});
|
|
259
|
+
program
|
|
260
|
+
.command("up")
|
|
261
|
+
.description("Serve the dashboard and run the curator and deep dive on their schedules (a shared box).")
|
|
262
|
+
.option("--dir <dir>", "knowledge base checkout", ".")
|
|
263
|
+
.option("--once", "check the schedule once and exit")
|
|
264
|
+
.option("--run-now", "run every enabled agent now and exit")
|
|
265
|
+
.option("--no-dashboard", "schedule the agents without serving the dashboard")
|
|
266
|
+
.option("--port <port>", "dashboard port", "4747")
|
|
267
|
+
.option("--host <host>", "dashboard interface (default 127.0.0.1; 0.0.0.0 in a container)")
|
|
268
|
+
.action(async (opts) => {
|
|
269
|
+
exitCode = await runUp(opts, io);
|
|
270
|
+
});
|
|
271
|
+
program
|
|
272
|
+
.command("dashboard")
|
|
273
|
+
.description("Serve the setup and metrics dashboard on localhost.")
|
|
274
|
+
.option("--dir <dir>", "knowledge base root", ".")
|
|
275
|
+
.option("--port <port>", "port", "4747")
|
|
276
|
+
.option("--host <host>", "interface (default 127.0.0.1; 0.0.0.0 in a container)")
|
|
277
|
+
.action(async (opts) => {
|
|
278
|
+
exitCode = await runDashboard(opts, io);
|
|
279
|
+
});
|
|
280
|
+
program
|
|
281
|
+
.command("hook", { hidden: true })
|
|
282
|
+
.description(`Handle a Claude Code hook event (${HOOK_EVENTS.join(", ")}); used by the plugin.`)
|
|
283
|
+
.argument("<event>")
|
|
284
|
+
.action(async (event) => {
|
|
285
|
+
exitCode = await runHook(event, io);
|
|
286
|
+
});
|
|
287
|
+
try {
|
|
288
|
+
await program.parseAsync([...argv]);
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
if (e instanceof CommanderError)
|
|
292
|
+
return e.exitCode;
|
|
293
|
+
throw e;
|
|
294
|
+
}
|
|
295
|
+
return exitCode;
|
|
296
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { CODEOWNERS_FILE, generateCodeowners, readKbFiles, validate, writeKbFile, } from "@homeostat/core";
|
|
4
|
+
import { formatIssues } from "./format.js";
|
|
5
|
+
/** `homeostat codeowners [dir]`: writes CODEOWNERS, or with `--check` only reports whether it is stale. */
|
|
6
|
+
export function runCodeowners(dir, opts, io) {
|
|
7
|
+
const root = resolve(dir);
|
|
8
|
+
const result = validate(readKbFiles(root));
|
|
9
|
+
if (!result.ok || !result.config) {
|
|
10
|
+
const errors = result.issues.filter((i) => i.severity === "error");
|
|
11
|
+
io.stdout(`${formatIssues(errors, io).text}fix the errors above before generating CODEOWNERS\n`);
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
const { text, issues } = generateCodeowners(result.config, result.entries.map((e) => e.entry.frontmatter));
|
|
15
|
+
if (issues.length > 0) {
|
|
16
|
+
io.stdout(formatIssues(issues, io).text);
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
const path = join(root, CODEOWNERS_FILE);
|
|
20
|
+
const current = existsSync(path) ? readFileSync(path, "utf8") : undefined;
|
|
21
|
+
if (opts.check) {
|
|
22
|
+
const fresh = current === text;
|
|
23
|
+
io.stdout(fresh
|
|
24
|
+
? `${CODEOWNERS_FILE} is up to date\n`
|
|
25
|
+
: `${CODEOWNERS_FILE} is out of date; run homeostat codeowners\n`);
|
|
26
|
+
return fresh ? 0 : 1;
|
|
27
|
+
}
|
|
28
|
+
writeKbFile(root, CODEOWNERS_FILE, text);
|
|
29
|
+
io.stdout(`wrote ${CODEOWNERS_FILE}\n`);
|
|
30
|
+
return 0;
|
|
31
|
+
}
|