@troylar/flightdeck 1.10.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/CHANGELOG.md +171 -0
- package/LICENSE +24 -0
- package/README.md +384 -0
- package/bin/flightdeck.js +145 -0
- package/dist/FONT-LICENSE.txt +93 -0
- package/dist/flightdeck.html +5608 -0
- package/package.json +45 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* The flightdeck command: puts the one-file app where a team uses it. No dependencies, nothing runs on install, and it
|
|
3
|
+
never touches the network. Every command works on plain files: copy the app into a team folder, add or update the
|
|
4
|
+
skills for AI assistants (in the team folder or any other folder), or open the app. */
|
|
5
|
+
'use strict';
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { spawn } = require('child_process');
|
|
9
|
+
|
|
10
|
+
const APP = path.join(__dirname, '..', 'dist', 'flightdeck.html');
|
|
11
|
+
const NAME = 'flightdeck.html', OLD = 'preflight.html', SKILLS = '.flightdeck/skills';
|
|
12
|
+
|
|
13
|
+
function fail(msg) { process.stderr.write('flightdeck: ' + msg + '\n'); process.exit(1); }
|
|
14
|
+
function versionOf(html) {
|
|
15
|
+
const m = /<meta name="(?:flightdeck|preflight)-version" content="(\d+\.\d+\.\d+|dev)">/.exec(html.slice(0, 8192));
|
|
16
|
+
return m ? m[1] : null;
|
|
17
|
+
}
|
|
18
|
+
function cmp(a, b) {
|
|
19
|
+
const x = a.split('.').map(BigInt), y = b.split('.').map(BigInt);
|
|
20
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i] ? 1 : -1;
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
function app() {
|
|
24
|
+
if (!fs.existsSync(APP)) fail('the app file is missing from this install (' + APP + '). Reinstall the package.');
|
|
25
|
+
return fs.readFileSync(APP, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
function expand(arg) { return path.resolve(arg.replace(/^~(?=$|[\\/])/, require('os').homedir())); }
|
|
28
|
+
function folderArg(arg) {
|
|
29
|
+
if (!arg) fail('say which team folder, for example: flightdeck install "~/OneDrive/Team/Flightdeck"');
|
|
30
|
+
const dir = expand(arg);
|
|
31
|
+
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) fail('"' + dir + '" isn\'t a folder.');
|
|
32
|
+
return fs.realpathSync(dir);
|
|
33
|
+
}
|
|
34
|
+
/* Write a file inside the team folder, and only there: no part of the path below the folder may be a link (a symlink or a
|
|
35
|
+
Windows junction could point anywhere), and the file is written whole to a temporary sibling first, then moved into
|
|
36
|
+
place, so an interrupted write never leaves half a file behind. */
|
|
37
|
+
function safeWrite(dir, parts, text) {
|
|
38
|
+
let cur = dir;
|
|
39
|
+
for (let i = 0; i < parts.length; i++) {
|
|
40
|
+
cur = path.join(cur, parts[i]);
|
|
41
|
+
if (!cur.startsWith(dir + path.sep)) fail('refusing to write outside the team folder: ' + parts.join('/'));
|
|
42
|
+
let st = null;
|
|
43
|
+
try { st = fs.lstatSync(cur); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
44
|
+
if (st && st.isSymbolicLink()) fail('refusing to write through a link: ' + cur);
|
|
45
|
+
if (i < parts.length - 1) { if (!st) fs.mkdirSync(cur); else if (!st.isDirectory()) fail(cur + ' isn\'t a folder.'); }
|
|
46
|
+
}
|
|
47
|
+
const tmp = path.join(path.dirname(cur), '.' + path.basename(cur) + '.' + process.pid + '.' + Date.now() + '.tmp');
|
|
48
|
+
try { fs.writeFileSync(tmp, text, { flag: 'wx' }); fs.renameSync(tmp, cur); }
|
|
49
|
+
catch (e) { try { fs.unlinkSync(tmp); } catch (e2) { /* nothing to clean up */ } fail('couldn\'t write ' + cur + ': ' + e.message); }
|
|
50
|
+
}
|
|
51
|
+
/* Whether the app may replace the file at dest: a newer version, or a file that isn't a Flightdeck app, needs --force. */
|
|
52
|
+
function mayReplace(dest, mine, force) {
|
|
53
|
+
let st = null;
|
|
54
|
+
try { st = fs.lstatSync(dest); } catch (e) { return true; }
|
|
55
|
+
if (st.isSymbolicLink()) fail('refusing to write through a link: ' + dest);
|
|
56
|
+
if (force) return true;
|
|
57
|
+
const theirs = versionOf(fs.readFileSync(dest, 'utf8'));
|
|
58
|
+
if (!theirs) fail(dest + ' isn\'t a Flightdeck app this version recognizes. Use --force to replace it anyway.');
|
|
59
|
+
if (theirs !== 'dev' && mine !== 'dev' && cmp(theirs, mine) > 0) fail(dest + ' is a newer version (' + theirs + ') than this one (' + mine + '). Update the package, or use --force to replace it anyway.');
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/* The example folder is built into the app; the skills are taken from there, so they always match this version. */
|
|
63
|
+
function skillFiles(html) {
|
|
64
|
+
const m = /var EXAMPLES = (\{[\s\S]*?\});\n/.exec(html);
|
|
65
|
+
if (!m) fail('couldn\'t find the built-in skills in the app file.');
|
|
66
|
+
const all = JSON.parse(m[1].replace(/<\\\//g, '</'));
|
|
67
|
+
return Object.keys(all).filter((p) => p.startsWith(SKILLS + '/')).map((p) => ({ path: p.slice(SKILLS.length + 1), text: all[p] }));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const HELP = `flightdeck: team process checklists, in one HTML file
|
|
71
|
+
|
|
72
|
+
flightdeck open open the app (it starts on built-in examples)
|
|
73
|
+
flightdeck install <team folder> copy the app into the team folder as ${NAME}
|
|
74
|
+
flightdeck skills <team folder> add or update the AI assistant skills in <team folder>/.flightdeck/skills
|
|
75
|
+
flightdeck skills --to <folder> add or update them in any other folder (an assistant's skills folder, a repo)
|
|
76
|
+
flightdeck path print where the app file is
|
|
77
|
+
flightdeck version print this version
|
|
78
|
+
|
|
79
|
+
--force replace a newer app, or skill files someone changed`;
|
|
80
|
+
|
|
81
|
+
function main(argv) {
|
|
82
|
+
const ti = argv.indexOf('--to'), to = ti >= 0 ? argv[ti + 1] : null;
|
|
83
|
+
if (ti >= 0 && (!to || to.startsWith('--'))) fail('say which folder after --to, for example: flightdeck skills --to ~/skills');
|
|
84
|
+
const args = argv.filter((a, i) => !a.startsWith('--') && !(ti >= 0 && i === ti + 1)), force = argv.includes('--force');
|
|
85
|
+
const cmd = args[0];
|
|
86
|
+
if (!cmd || cmd === 'help' || argv.includes('--help')) { process.stdout.write(HELP + '\n'); return; }
|
|
87
|
+
if (cmd === 'version' || argv.includes('--version')) { process.stdout.write((versionOf(app()) || 'unknown') + '\n'); return; }
|
|
88
|
+
if (cmd === 'path') { app(); process.stdout.write(APP + '\n'); return; }
|
|
89
|
+
if (cmd === 'install') {
|
|
90
|
+
const dir = folderArg(args[1]), html = app(), mine = versionOf(html), dest = path.join(dir, NAME), old = path.join(dir, OLD);
|
|
91
|
+
mayReplace(dest, mine, force);
|
|
92
|
+
/* Before 1.9.0 the app was preflight.html. If the folder still has it, update it too: people who open that file keep
|
|
93
|
+
their browser-saved state (it's tied to the file's address), and older copies looking for it see the update. */
|
|
94
|
+
const keepOld = fs.existsSync(old);
|
|
95
|
+
if (keepOld) mayReplace(old, mine, force);
|
|
96
|
+
safeWrite(dir, [NAME], html);
|
|
97
|
+
if (keepOld) safeWrite(dir, [OLD], html);
|
|
98
|
+
process.stdout.write('Installed Flightdeck ' + mine + ' at ' + dest + (keepOld ? '\nAlso updated ' + old + ' (the same app under its old name)' : '') + '\nOpen it in Edge or Chrome, choose Open team folder, and pick ' + dir + '\n');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (cmd === 'skills') {
|
|
102
|
+
/* Without --to the skills go in <team folder>/.flightdeck/skills. With --to they go straight into that folder, which
|
|
103
|
+
is created if it's missing. Either way nothing is written through a link below it. */
|
|
104
|
+
let dir, base;
|
|
105
|
+
if (to) {
|
|
106
|
+
const t = expand(to);
|
|
107
|
+
try { fs.mkdirSync(t, { recursive: true }); } catch (e) { fail('couldn\'t create "' + t + '": ' + e.message); }
|
|
108
|
+
dir = folderArg(t); base = [];
|
|
109
|
+
} else {
|
|
110
|
+
dir = folderArg(args[1]); base = SKILLS.split('/');
|
|
111
|
+
}
|
|
112
|
+
const files = skillFiles(app()), kept = [];
|
|
113
|
+
let written = 0;
|
|
114
|
+
for (const f of files) {
|
|
115
|
+
const parts = base.concat(f.path.split('/'));
|
|
116
|
+
if (parts.some((x) => !x || x === '.' || x === '..')) fail('refusing an unexpected skill path: ' + f.path);
|
|
117
|
+
const dest = path.join(dir, ...parts);
|
|
118
|
+
let st = null;
|
|
119
|
+
try { st = fs.lstatSync(dest); } catch (e) { /* not there yet */ }
|
|
120
|
+
if (st && st.isSymbolicLink()) fail('refusing to write through a link: ' + dest);
|
|
121
|
+
if (st) {
|
|
122
|
+
if (fs.readFileSync(dest, 'utf8') === f.text) continue;
|
|
123
|
+
if (!force) { kept.push(f.path); continue; }
|
|
124
|
+
}
|
|
125
|
+
safeWrite(dir, parts, f.text);
|
|
126
|
+
written++;
|
|
127
|
+
}
|
|
128
|
+
process.stdout.write(written + ' skill file' + (written === 1 ? '' : 's') + ' written to ' + path.join(dir, ...base) + '\n');
|
|
129
|
+
if (kept.length) process.stdout.write('Left as they are (changed in the folder; use --force to replace):\n' + kept.map((p) => ' ' + p).join('\n') + '\n');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (cmd === 'open') {
|
|
133
|
+
app();
|
|
134
|
+
/* The path is passed as data to a launcher, never through a shell (cmd would expand %VARIABLES% in it). */
|
|
135
|
+
const [bin, ...rest] = process.platform === 'darwin' ? ['open', APP] : process.platform === 'win32' ? ['explorer.exe', APP] : ['xdg-open', APP];
|
|
136
|
+
const child = spawn(bin, rest, { stdio: 'ignore', detached: true });
|
|
137
|
+
child.on('error', () => fail('couldn\'t open a browser. Open this file in Edge or Chrome: ' + APP));
|
|
138
|
+
child.unref();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
fail('unknown command "' + cmd + '". Try: flightdeck help');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (require.main === module) main(process.argv.slice(2));
|
|
145
|
+
module.exports = { main, versionOf, cmp, skillFiles };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2017 The Barlow Project Authors (https://github.com/jpt/barlow)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|