okforest 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/NOTICE +4 -0
- package/README.md +23 -2
- package/dist/cli.mjs +360 -0
- package/package.json +49 -3
- package/templates/company/.github/workflows/okforest-validate.yml +22 -0
- package/templates/company/.okforest/tree.yaml +13 -0
- package/templates/company/README.md +14 -0
- package/templates/company/company/index.md +3 -0
- package/templates/company/company/overview.md +25 -0
- package/templates/company/customers/ideal-customer-profile.md +26 -0
- package/templates/company/customers/index.md +3 -0
- package/templates/company/index.md +8 -0
- package/templates/company/log.md +4 -0
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/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# okforest
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The OKForest CLI: validate, inventory, and scaffold
|
|
4
|
+
[Open Knowledge Format (OKF)](https://github.com/GoogleCloudPlatform/open-knowledge-format)
|
|
5
|
+
v0.2 trees.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx okforest validate . # exit 1 on errors; warnings never fail
|
|
9
|
+
npx okforest validate . --format json # for CI and tools
|
|
10
|
+
npx okforest inventory . # types, tags, keys, near-duplicates
|
|
11
|
+
npx okforest init sales-okf --template company --owner jane@acme.example
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
To also check D2 and Mermaid diagram syntax, install the optional packages
|
|
15
|
+
alongside it:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npx -p okforest -p @d2lang/d2 -p mermaid okforest validate .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Rules, options, and what counts as a concept: see the
|
|
22
|
+
[OKForest CLI README](https://github.com/okforest/cli#readme).
|
|
23
|
+
|
|
24
|
+
Apache-2.0 · © Preneur LLC · [okforest.ai](https://okforest.ai)
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
5
|
+
import { basename, join, resolve } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { parseArgs, styleText } from "node:util";
|
|
8
|
+
import { buildInventory } from "@okforest/okf";
|
|
9
|
+
import { readTree } from "@okforest/okf/node";
|
|
10
|
+
import { validate } from "@okforest/validate";
|
|
11
|
+
//#region src/io.ts
|
|
12
|
+
/** Exit codes: 0 success, 1 validation errors, 2 usage or read problems. */
|
|
13
|
+
const EXIT = {
|
|
14
|
+
ok: 0,
|
|
15
|
+
failed: 1,
|
|
16
|
+
usage: 2
|
|
17
|
+
};
|
|
18
|
+
/** Thrown for bad arguments or unreadable input; becomes exit code 2. */
|
|
19
|
+
var UsageError = class extends Error {};
|
|
20
|
+
function paint(io, style, text) {
|
|
21
|
+
return io.color ? styleText(style, text, { validateStream: false }) : text;
|
|
22
|
+
}
|
|
23
|
+
const packageRoot = new URL("../", import.meta.url);
|
|
24
|
+
const VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
25
|
+
const TEMPLATES_DIR = new URL("templates/", packageRoot);
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/args.ts
|
|
28
|
+
/** Parse a command's arguments: options plus at most one positional path. */
|
|
29
|
+
function parseCommand(args, options) {
|
|
30
|
+
const { values, positionals } = parseArgs({
|
|
31
|
+
args: [...args],
|
|
32
|
+
options: {
|
|
33
|
+
...options,
|
|
34
|
+
help: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
short: "h"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
allowPositionals: true,
|
|
40
|
+
strict: true
|
|
41
|
+
});
|
|
42
|
+
if (positionals.length > 1) throw new UsageError(`Expected one path, got ${positionals.length}: ${positionals.join(" ")}`);
|
|
43
|
+
return {
|
|
44
|
+
values,
|
|
45
|
+
path: positionals[0] ?? "."
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function formatOption(value) {
|
|
49
|
+
if (value === void 0 || value === "text") return "text";
|
|
50
|
+
if (value === "json") return "json";
|
|
51
|
+
throw new UsageError(`--format must be \`text\` or \`json\` (got \`${String(value)}\`).`);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/commands/init.ts
|
|
55
|
+
const HELP$3 = `Usage: okforest init [path] --template <name> [--owner <email>] [--tree <name>] [--title <title>]
|
|
56
|
+
|
|
57
|
+
Create a new OKF v0.2 tree at path (default: the current directory, which must
|
|
58
|
+
be empty apart from .git) from a starter template. Starter concepts are drafts
|
|
59
|
+
for you to fill in.
|
|
60
|
+
|
|
61
|
+
Options
|
|
62
|
+
--template <name> Starter template (available: company).
|
|
63
|
+
--owner <email> The tree's Owner, one person (default: git config user.email).
|
|
64
|
+
--tree <name> The tree's short name (default: the folder name without -okf).
|
|
65
|
+
--title <title> Display title (default: "<Tree> knowledge").
|
|
66
|
+
`;
|
|
67
|
+
async function initCommand(args, io) {
|
|
68
|
+
const { values, path } = parseCommand(args, {
|
|
69
|
+
template: { type: "string" },
|
|
70
|
+
owner: { type: "string" },
|
|
71
|
+
tree: { type: "string" },
|
|
72
|
+
title: { type: "string" }
|
|
73
|
+
});
|
|
74
|
+
if (values.help) {
|
|
75
|
+
io.stdout(HELP$3);
|
|
76
|
+
return EXIT.ok;
|
|
77
|
+
}
|
|
78
|
+
const templates = await listTemplates();
|
|
79
|
+
const template = values.template;
|
|
80
|
+
if (typeof template !== "string" || !templates.includes(template)) throw new UsageError(`${template === void 0 ? "Choose" : `Unknown template \`${template}\`; choose`} a template with --template (${templates.join(", ")}).`);
|
|
81
|
+
const target = resolve(io.cwd, path);
|
|
82
|
+
const blocking = (await readdir(target).catch(() => [])).filter((name) => name !== ".git" && name !== ".DS_Store");
|
|
83
|
+
if (blocking.length > 0) throw new UsageError(`${path} is not empty (${blocking.slice(0, 3).join(", ")}${blocking.length > 3 ? ", ..." : ""}).`);
|
|
84
|
+
const owner = (typeof values.owner === "string" ? values.owner : gitEmail(target, io.cwd))?.replace(/^user:/, "").trim();
|
|
85
|
+
if (!owner || /\s/.test(owner)) throw new UsageError(owner ? `--owner must be one identifier with no spaces (got \`${owner}\`).` : "Name the tree's Owner with --owner <email> (no git user.email is configured).");
|
|
86
|
+
const tree = slug(typeof values.tree === "string" ? values.tree : basename(target).replace(/-okf$/, "")) || "company";
|
|
87
|
+
const title = typeof values.title === "string" && values.title.trim() !== "" ? values.title.trim() : `${capitalize(tree)} knowledge`;
|
|
88
|
+
const now = /* @__PURE__ */ new Date();
|
|
89
|
+
const tokens = {
|
|
90
|
+
owner,
|
|
91
|
+
tree,
|
|
92
|
+
title,
|
|
93
|
+
title_yaml: JSON.stringify(title),
|
|
94
|
+
version: VERSION,
|
|
95
|
+
date: now.toISOString().slice(0, 10),
|
|
96
|
+
now: `${now.toISOString().slice(0, 19)}Z`
|
|
97
|
+
};
|
|
98
|
+
const written = await copyTemplate(fileURLToPath(new URL(`${template}/`, TEMPLATES_DIR)), target, tokens);
|
|
99
|
+
const where = path;
|
|
100
|
+
const drafts = written.filter((f) => f.endsWith(".md") && !/(^|\/)(index|log|README)\.md$/.test(f));
|
|
101
|
+
io.stdout(`Created a ${template} tree in ${where} (${written.length} files).\n\nNext steps
|
|
102
|
+
1. Review .okforest/tree.yaml (Owner: user:${owner}).\n 2. Fill in the draft concepts: ${drafts.join(", ")}.\n 3. Validate: npx okforest validate ${where}\n 4. Commit and push; the included workflow validates every pull request.
|
|
103
|
+
`);
|
|
104
|
+
return EXIT.ok;
|
|
105
|
+
}
|
|
106
|
+
async function listTemplates() {
|
|
107
|
+
return (await readdir(TEMPLATES_DIR, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
108
|
+
}
|
|
109
|
+
/** Copy a template directory, replacing `{{token}}` for known tokens only
|
|
110
|
+
* (GitHub Actions' `${{ ... }}` expressions are left alone). */
|
|
111
|
+
async function copyTemplate(from, to, tokens) {
|
|
112
|
+
const written = [];
|
|
113
|
+
const walk = async (dir) => {
|
|
114
|
+
const entries = await readdir(join(from, dir), { withFileTypes: true });
|
|
115
|
+
for (const entry of entries.sort((a, b) => a.name < b.name ? -1 : 1)) {
|
|
116
|
+
const rel = dir ? `${dir}/${entry.name}` : entry.name;
|
|
117
|
+
if (entry.isDirectory()) {
|
|
118
|
+
await walk(rel);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const text = (await readFile(join(from, rel), "utf8")).replace(/\{\{(\w+)\}\}/g, (match, key) => Object.hasOwn(tokens, key) ? tokens[key] : match);
|
|
122
|
+
await mkdir(join(to, dir), { recursive: true });
|
|
123
|
+
await writeFile(join(to, rel), text, { flag: "wx" });
|
|
124
|
+
written.push(rel);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
await walk("");
|
|
128
|
+
return written;
|
|
129
|
+
}
|
|
130
|
+
function gitEmail(target, cwd) {
|
|
131
|
+
for (const dir of [target, cwd]) {
|
|
132
|
+
const result = spawnSync("git", ["config", "user.email"], {
|
|
133
|
+
cwd: dir,
|
|
134
|
+
encoding: "utf8"
|
|
135
|
+
});
|
|
136
|
+
if (result.status === 0 && result.stdout.trim()) return result.stdout.trim();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function slug(value) {
|
|
140
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
141
|
+
}
|
|
142
|
+
function capitalize(value) {
|
|
143
|
+
return value.charAt(0).toUpperCase() + value.slice(1).replaceAll("-", " ");
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/tree.ts
|
|
147
|
+
/** Read the tree at a user-supplied path, or explain why not. */
|
|
148
|
+
async function loadTree(path, io) {
|
|
149
|
+
const dir = resolve(io.cwd, path);
|
|
150
|
+
const info = await stat(dir).catch(() => void 0);
|
|
151
|
+
if (!info) throw new UsageError(`No such directory: ${path}`);
|
|
152
|
+
if (!info.isDirectory()) throw new UsageError(`Not a directory: ${path} (give the tree's root folder).`);
|
|
153
|
+
try {
|
|
154
|
+
return await readTree(dir);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new UsageError(`Could not read ${path}: ${error.message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/commands/inventory.ts
|
|
161
|
+
const HELP$2 = `Usage: okforest inventory [path] [--format text|json]
|
|
162
|
+
|
|
163
|
+
List every type, tag, and frontmatter key in use in the tree at path (default:
|
|
164
|
+
the current directory), with counts, lifecycle and trust totals, and likely
|
|
165
|
+
near-duplicates (case, punctuation, plurals, and small spelling differences).
|
|
166
|
+
|
|
167
|
+
Options
|
|
168
|
+
--format text|json Output format (default: text).
|
|
169
|
+
`;
|
|
170
|
+
async function inventoryCommand(args, io) {
|
|
171
|
+
const { values, path } = parseCommand(args, { format: { type: "string" } });
|
|
172
|
+
if (values.help) {
|
|
173
|
+
io.stdout(HELP$2);
|
|
174
|
+
return EXIT.ok;
|
|
175
|
+
}
|
|
176
|
+
const format = formatOption(values.format);
|
|
177
|
+
const inventory = buildInventory(await loadTree(path, io));
|
|
178
|
+
io.stdout(format === "json" ? `${JSON.stringify({
|
|
179
|
+
schemaVersion: 1,
|
|
180
|
+
tool: {
|
|
181
|
+
name: "okforest",
|
|
182
|
+
version: VERSION
|
|
183
|
+
},
|
|
184
|
+
path,
|
|
185
|
+
...inventory
|
|
186
|
+
}, null, 2)}\n` : inventoryText(inventory, io));
|
|
187
|
+
return EXIT.ok;
|
|
188
|
+
}
|
|
189
|
+
const REASONS = {
|
|
190
|
+
"case-or-punctuation": "case or punctuation",
|
|
191
|
+
plural: "singular and plural",
|
|
192
|
+
spelling: "spelling"
|
|
193
|
+
};
|
|
194
|
+
function inventoryText(inventory, io) {
|
|
195
|
+
const out = [];
|
|
196
|
+
const { statuses: s, trustTiers: t } = inventory;
|
|
197
|
+
out.push(`${inventory.concepts} concepts · ${inventory.types.length} types · ${inventory.tags.length} tags · ${inventory.keys.length} frontmatter keys`, `Status: ${s.stable} stable, ${s.draft} draft, ${s.deprecated} deprecated · Trust: ${t["human-reviewed"]} human-reviewed, ${t["machine-confirmed"]} machine-confirmed, ${t.unverified} unverified · ${inventory.stale} stale`);
|
|
198
|
+
if (inventory.untyped > 0) out.push(paint(io, "yellow", `${inventory.untyped} concepts have no usable type`));
|
|
199
|
+
const section = (title, counts) => {
|
|
200
|
+
out.push("", paint(io, "bold", title));
|
|
201
|
+
if (counts.length === 0) out.push(paint(io, "dim", " (none)"));
|
|
202
|
+
const width = Math.max(0, ...counts.map((c) => String(c.count).length));
|
|
203
|
+
for (const c of counts) out.push(` ${String(c.count).padStart(width)} ${c.value}`);
|
|
204
|
+
};
|
|
205
|
+
section("Types", inventory.types);
|
|
206
|
+
section("Tags", inventory.tags);
|
|
207
|
+
section("Frontmatter keys", inventory.keys);
|
|
208
|
+
out.push("", paint(io, "bold", "Near-duplicates"));
|
|
209
|
+
if (inventory.nearDuplicates.length === 0) out.push(paint(io, "dim", " (none found)"));
|
|
210
|
+
for (const group of inventory.nearDuplicates) {
|
|
211
|
+
const values = group.values.map((v) => `${v.value} (${v.count})`).join(", ");
|
|
212
|
+
const why = group.reasons.map((r) => REASONS[r]).join(", ");
|
|
213
|
+
out.push(` ${group.field}: ${values} ${paint(io, "dim", `- ${why}`)}`);
|
|
214
|
+
}
|
|
215
|
+
return `${out.join("\n")}\n`;
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/commands/validate.ts
|
|
219
|
+
const HELP$1 = `Usage: okforest validate [path] [--format text|json]
|
|
220
|
+
|
|
221
|
+
Check the OKF v0.2 tree at path (default: the current directory) against the
|
|
222
|
+
OKF specification and OKForest conventions. Exits 1 when there are errors;
|
|
223
|
+
warnings and info are reported but never fail.
|
|
224
|
+
|
|
225
|
+
Options
|
|
226
|
+
--format text|json Output format (default: text). JSON is for CI and tools.
|
|
227
|
+
`;
|
|
228
|
+
async function validateCommand(args, io) {
|
|
229
|
+
const { values, path } = parseCommand(args, { format: { type: "string" } });
|
|
230
|
+
if (values.help) {
|
|
231
|
+
io.stdout(HELP$1);
|
|
232
|
+
return EXIT.ok;
|
|
233
|
+
}
|
|
234
|
+
const format = formatOption(values.format);
|
|
235
|
+
const result = await validate(await loadTree(path, io));
|
|
236
|
+
io.stdout(format === "json" ? toJson(path, result) : toText(result, io));
|
|
237
|
+
return result.ok ? EXIT.ok : EXIT.failed;
|
|
238
|
+
}
|
|
239
|
+
function toJson(path, result) {
|
|
240
|
+
const { findings, errors, warnings, infos, concepts, files, ok } = result;
|
|
241
|
+
return `${JSON.stringify({
|
|
242
|
+
schemaVersion: 1,
|
|
243
|
+
tool: {
|
|
244
|
+
name: "okforest",
|
|
245
|
+
version: VERSION
|
|
246
|
+
},
|
|
247
|
+
path,
|
|
248
|
+
summary: {
|
|
249
|
+
ok,
|
|
250
|
+
errors,
|
|
251
|
+
warnings,
|
|
252
|
+
infos,
|
|
253
|
+
concepts,
|
|
254
|
+
files
|
|
255
|
+
},
|
|
256
|
+
findings
|
|
257
|
+
}, null, 2)}\n`;
|
|
258
|
+
}
|
|
259
|
+
const LABEL = {
|
|
260
|
+
error: "error",
|
|
261
|
+
warning: "warning",
|
|
262
|
+
info: "info"
|
|
263
|
+
};
|
|
264
|
+
const COLOR = {
|
|
265
|
+
error: "red",
|
|
266
|
+
warning: "yellow",
|
|
267
|
+
info: "cyan"
|
|
268
|
+
};
|
|
269
|
+
function toText(result, io) {
|
|
270
|
+
const out = [];
|
|
271
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
272
|
+
for (const finding of result.findings) byFile.set(finding.file, [...byFile.get(finding.file) ?? [], finding]);
|
|
273
|
+
for (const [file, findings] of byFile) {
|
|
274
|
+
out.push(paint(io, "underline", file));
|
|
275
|
+
const positions = findings.map((f) => f.line === void 0 ? "" : `${f.line}:${f.column ?? 1}`);
|
|
276
|
+
const width = Math.max(...positions.map((p) => p.length));
|
|
277
|
+
findings.forEach((f, i) => {
|
|
278
|
+
out.push(` ${paint(io, "dim", positions[i].padEnd(width))} ${paint(io, COLOR[f.severity], LABEL[f.severity].padEnd(7))} ${f.message} ${paint(io, "dim", f.ruleId)}`);
|
|
279
|
+
});
|
|
280
|
+
out.push("");
|
|
281
|
+
}
|
|
282
|
+
out.push(summary(result, io));
|
|
283
|
+
return `${out.join("\n")}\n`;
|
|
284
|
+
}
|
|
285
|
+
function summary(result, io) {
|
|
286
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
287
|
+
const scope = `${plural(result.concepts, "concept")} in ${plural(result.files, "file")}`;
|
|
288
|
+
if (result.findings.length === 0) return `${paint(io, "green", "✔")} No problems · ${scope}`;
|
|
289
|
+
const counts = `${plural(result.errors, "error")}, ${plural(result.warnings, "warning")}, ${result.infos} info`;
|
|
290
|
+
return result.ok ? `${paint(io, "green", "✔")} ${counts} · ${scope}` : `${paint(io, "red", "✖")} ${counts} · ${scope}`;
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/main.ts
|
|
294
|
+
const HELP = `okforest ${VERSION}: validate, inventory, and scaffold Open Knowledge Format (OKF) v0.2 trees
|
|
295
|
+
|
|
296
|
+
Usage
|
|
297
|
+
okforest validate [path] [--format text|json]
|
|
298
|
+
okforest inventory [path] [--format text|json]
|
|
299
|
+
okforest init [path] --template company [--owner <email>] [--tree <name>] [--title <title>]
|
|
300
|
+
|
|
301
|
+
Commands
|
|
302
|
+
validate Check a tree against OKF v0.2 and OKForest conventions.
|
|
303
|
+
Exits 1 when there are errors; warnings and info never fail.
|
|
304
|
+
inventory List every type, tag, and frontmatter key in use, with counts
|
|
305
|
+
and likely near-duplicates.
|
|
306
|
+
init Create a new tree from a starter template (templates: company).
|
|
307
|
+
|
|
308
|
+
Options
|
|
309
|
+
-h, --help Show help (also: okforest <command> --help)
|
|
310
|
+
-v, --version Show the version
|
|
311
|
+
|
|
312
|
+
Diagram syntax checks need the optional packages \`@d2lang/d2\` and \`mermaid\`
|
|
313
|
+
installed alongside okforest, e.g.:
|
|
314
|
+
npx -p okforest -p @d2lang/d2 -p mermaid okforest validate .
|
|
315
|
+
|
|
316
|
+
Docs: https://okforest.ai/docs · Source: https://github.com/okforest/cli
|
|
317
|
+
`;
|
|
318
|
+
const COMMANDS = {
|
|
319
|
+
validate: validateCommand,
|
|
320
|
+
inventory: inventoryCommand,
|
|
321
|
+
init: initCommand
|
|
322
|
+
};
|
|
323
|
+
/** Run the CLI and return its exit code. */
|
|
324
|
+
async function main(argv, io) {
|
|
325
|
+
const [command, ...rest] = argv;
|
|
326
|
+
try {
|
|
327
|
+
if (command === void 0 || command === "-h" || command === "--help" || command === "help") {
|
|
328
|
+
io.stdout(HELP);
|
|
329
|
+
return command === void 0 ? EXIT.usage : EXIT.ok;
|
|
330
|
+
}
|
|
331
|
+
if (command === "-v" || command === "--version") {
|
|
332
|
+
io.stdout(`${VERSION}\n`);
|
|
333
|
+
return EXIT.ok;
|
|
334
|
+
}
|
|
335
|
+
if (!Object.hasOwn(COMMANDS, command)) throw new UsageError(`Unknown command \`${command}\`. Run \`okforest --help\` for usage.`);
|
|
336
|
+
return await COMMANDS[command](rest, io);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error instanceof UsageError || isArgsError(error)) {
|
|
339
|
+
io.stderr(`okforest: ${error.message}\n`);
|
|
340
|
+
return EXIT.usage;
|
|
341
|
+
}
|
|
342
|
+
throw error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function isArgsError(error) {
|
|
346
|
+
const code = error?.code;
|
|
347
|
+
return typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/cli.ts
|
|
351
|
+
const env = process.env;
|
|
352
|
+
const color = env.FORCE_COLOR !== void 0 ? env.FORCE_COLOR !== "0" : Boolean(process.stdout.isTTY) && env.NO_COLOR === void 0 && env.TERM !== "dumb";
|
|
353
|
+
process.exitCode = await main(process.argv.slice(2), {
|
|
354
|
+
stdout: (text) => process.stdout.write(text),
|
|
355
|
+
stderr: (text) => process.stderr.write(text),
|
|
356
|
+
color,
|
|
357
|
+
cwd: process.cwd()
|
|
358
|
+
});
|
|
359
|
+
//#endregion
|
|
360
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "okforest",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The OKForest CLI: validate Open Knowledge Format (OKF) v0.2 trees, inventory their metadata, and scaffold new trees from templates.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"okf",
|
|
7
|
+
"open-knowledge-format",
|
|
8
|
+
"cli",
|
|
9
|
+
"validator",
|
|
10
|
+
"knowledge-management",
|
|
11
|
+
"okforest"
|
|
12
|
+
],
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"author": "Preneur LLC",
|
|
15
|
+
"homepage": "https://okforest.ai",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/okforest/cli.git",
|
|
19
|
+
"directory": "packages/okforest"
|
|
20
|
+
},
|
|
21
|
+
"bugs": "https://github.com/okforest/cli/issues",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"bin": {
|
|
24
|
+
"okforest": "./dist/cli.mjs"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"templates",
|
|
29
|
+
"NOTICE"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@okforest/okf": "0.1.0",
|
|
36
|
+
"@okforest/validate": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^26.6.5",
|
|
40
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
41
|
+
"tsdown": "^0.23.0",
|
|
42
|
+
"typescript": "^7.0.2",
|
|
43
|
+
"vitest": "^5.0.3"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:coverage": "vitest run --coverage",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"start": "node dist/cli.mjs"
|
|
51
|
+
}
|
|
6
52
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: OKForest Validate
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
validate:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7
|
|
16
|
+
- uses: actions/setup-node@v7
|
|
17
|
+
with:
|
|
18
|
+
node-version: 22
|
|
19
|
+
# Fails on OKF errors; warnings are reported without failing. To also
|
|
20
|
+
# check D2 and Mermaid diagram syntax, add the optional packages:
|
|
21
|
+
# npx --yes -p okforest@^{{version}} -p @d2lang/d2 -p mermaid okforest validate .
|
|
22
|
+
- run: npx --yes okforest@^{{version}} validate .
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# OKForest settings for this tree (an OKForest convention, not part of OKF).
|
|
2
|
+
tree: {{tree}}
|
|
3
|
+
title: {{title_yaml}}
|
|
4
|
+
owner: user:{{owner}} # exactly one person, accountable for the tree
|
|
5
|
+
# backup_owner: user:... # optional; acts for the Owner during absences
|
|
6
|
+
stewards: # review and approve changes; groups are recommended
|
|
7
|
+
- user: {{owner}}
|
|
8
|
+
sensitivity_default: internal
|
|
9
|
+
# Files that are not concepts, in addition to README.md, LICENSE.md,
|
|
10
|
+
# CONTRIBUTING.md, CHANGELOG.md, SECURITY.md, and CODE_OF_CONDUCT.md at the
|
|
11
|
+
# root. Globs are relative to the tree root.
|
|
12
|
+
# ignore:
|
|
13
|
+
# - FOLLOWUPS.md
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# {{title}}
|
|
2
|
+
|
|
3
|
+
An [Open Knowledge Format (OKF)](https://github.com/GoogleCloudPlatform/open-knowledge-format)
|
|
4
|
+
v0.2 tree: one markdown file per concept, with YAML frontmatter.
|
|
5
|
+
|
|
6
|
+
- Start at [`index.md`](index.md). `index.md` and `log.md` files are reserved;
|
|
7
|
+
every other `.md` file is a concept.
|
|
8
|
+
- The starter concepts are drafts (`status: draft`): fill them in, then remove
|
|
9
|
+
the guidance comments.
|
|
10
|
+
- Owner and Stewards are in [`.okforest/tree.yaml`](.okforest/tree.yaml).
|
|
11
|
+
- Validate with `npx okforest validate .`; the workflow in
|
|
12
|
+
`.github/workflows/okforest-validate.yml` runs it on every pull request.
|
|
13
|
+
|
|
14
|
+
Created with the [OKForest CLI](https://github.com/okforest/cli) `company` template.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: Organization
|
|
3
|
+
title: Company overview
|
|
4
|
+
description: What the company does, why it exists, and who it serves.
|
|
5
|
+
tags: [company]
|
|
6
|
+
status: draft
|
|
7
|
+
generated: { by: okforest/{{version}}, at: {{now}} }
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# What we do
|
|
11
|
+
|
|
12
|
+
<!-- One or two sentences: what the company does, and for whom. -->
|
|
13
|
+
|
|
14
|
+
# Why we exist
|
|
15
|
+
|
|
16
|
+
<!-- The mission: the problem the company solves and why it matters. -->
|
|
17
|
+
|
|
18
|
+
# Products and services
|
|
19
|
+
|
|
20
|
+
<!-- What the company sells. As the tree grows, give each product its own
|
|
21
|
+
concept (for example under products/) and link to it from here. -->
|
|
22
|
+
|
|
23
|
+
# Customers
|
|
24
|
+
|
|
25
|
+
Who we serve is described in the [ideal customer profile](/customers/ideal-customer-profile.md).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: Customer Profile
|
|
3
|
+
title: Ideal customer profile
|
|
4
|
+
description: The customers the company serves best, and how to recognize them.
|
|
5
|
+
tags: [customers, sales]
|
|
6
|
+
status: draft
|
|
7
|
+
generated: { by: okforest/{{version}}, at: {{now}} }
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Who they are
|
|
11
|
+
|
|
12
|
+
<!-- Industry, size, region, and the role of the person who buys. -->
|
|
13
|
+
|
|
14
|
+
# Problems we solve for them
|
|
15
|
+
|
|
16
|
+
<!-- The pains that bring them to us, in their words. -->
|
|
17
|
+
|
|
18
|
+
# Signs of a good fit
|
|
19
|
+
|
|
20
|
+
<!-- What a promising prospect looks like. -->
|
|
21
|
+
|
|
22
|
+
# Signs of a poor fit
|
|
23
|
+
|
|
24
|
+
<!-- When to walk away, and why. -->
|
|
25
|
+
|
|
26
|
+
See the [company overview](/company/overview.md) for what we offer.
|